chore: Keep prettier config local to the project (#531)

This commit is contained in:
Tim Griesser 2020-10-03 16:26:50 -04:00 committed by GitHub
parent 2bceeb915f
commit 8f3189c069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 146 additions and 151 deletions

7
.prettierrc Normal file
View File

@ -0,0 +1,7 @@
{
"printWidth": 110,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}

View File

@ -1,46 +1,46 @@
import { RESTDataSource } from "apollo-datasource-rest";
import { DataSource } from "apollo-datasource";
import { RESTDataSource } from 'apollo-datasource-rest'
import { DataSource } from 'apollo-datasource'
export interface Mission {
name: string;
missionPatchSmall: string;
missionPatchLarge: string;
name: string
missionPatchSmall: string
missionPatchLarge: string
}
export interface Rocket {
id: number;
name: string;
type: string;
id: number
name: string
type: string
}
export interface Launch {
id: number;
cursor: string;
site: string;
mission: Mission;
rocket: Rocket;
id: number
cursor: string
site: string
mission: Mission
rocket: Rocket
}
export interface DBUser {
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
token: string;
id: string
createdAt: Date
updatedAt: Date
email: string
token: string
}
export interface DBTrip {
id: number;
createdAt: Date;
updatedAt: Date;
launchId: number;
userId: number;
id: number
createdAt: Date
updatedAt: Date
launchId: number
userId: number
}
export interface LaunchApi extends RESTDataSource {
getAllLaunches(): Promise<Launch[]>;
getLaunchById(opts: { launchId: string }): Promise<Launch>;
getLaunchesByIds(opts: { launchIds: string[] }): Promise<Launch[]>;
getAllLaunches(): Promise<Launch[]>
getLaunchById(opts: { launchId: string }): Promise<Launch>
getLaunchesByIds(opts: { launchIds: string[] }): Promise<Launch[]>
}
export interface UserApi extends DataSource {
@ -49,27 +49,27 @@ export interface UserApi extends DataSource {
* have to be. If the user is already on the context, it will use that user
* instead
*/
findOrCreateUser(obj?: { email?: string | null }): Promise<DBUser | null>;
bookTrips(obj: { launchIds: string[] }): Promise<DBTrip[]>;
bookTrip(obj: { launchId: string }): Promise<DBTrip | false>;
cancelTrip(obj: { launchId: string }): Promise<void>;
getLaunchIdsByUser(): Promise<string[]>;
isBookedOnLaunch(obj: { launchId: string }): boolean;
findOrCreateUser(obj?: { email?: string | null }): Promise<DBUser | null>
bookTrips(obj: { launchIds: string[] }): Promise<DBTrip[]>
bookTrip(obj: { launchId: string }): Promise<DBTrip | false>
cancelTrip(obj: { launchId: string }): Promise<void>
getLaunchIdsByUser(): Promise<string[]>
isBookedOnLaunch(obj: { launchId: string }): boolean
}
export interface Utils {
paginateResults<T>(opts: {
after?: string | null;
pageSize?: number | null;
results: T[];
getCursor?: Function;
}): T[];
createStore(): {};
after?: string | null
pageSize?: number | null
results: T[]
getCursor?: Function
}): T[]
createStore(): {}
}
export interface Context {
dataSources: {
userAPI: UserApi;
launchAPI: LaunchApi;
};
userAPI: UserApi
launchAPI: LaunchApi
}
}

View File

@ -1,12 +1,12 @@
import ghost from "ghost";
import db from "ghost/core/server/data/db";
import { ApolloServer } from "apollo-server-express";
import express from "express";
import { schema } from "./ghost-schema";
import { Context } from "./data-sources/Context";
import { knex } from "./utils/knexInstance";
import ghost from 'ghost'
import db from 'ghost/core/server/data/db'
import { ApolloServer } from 'apollo-server-express'
import express from 'express'
import { schema } from './ghost-schema'
import { Context } from './data-sources/Context'
import { knex } from './utils/knexInstance'
const demoApp = express();
const demoApp = express()
// Note: This isn't (yet) protected by any sort of
// authentication/authorization, so don't try running queries in
@ -15,15 +15,15 @@ ghost().then((ghostServer) => {
const apolloServer = new ApolloServer({
schema,
context: () => new Context(),
});
apolloServer.applyMiddleware({ app: demoApp });
demoApp.use("/", ghostServer.rootApp);
ghostServer.start(demoApp);
console.log("Ghost server Ready!");
});
})
apolloServer.applyMiddleware({ app: demoApp })
demoApp.use('/', ghostServer.rootApp)
ghostServer.start(demoApp)
console.log('Ghost server Ready!')
})
function closeKnex() {
db.knex.destroy();
knex.destroy();
db.knex.destroy()
knex.destroy()
}
process.on("SIGTERM", closeKnex);
process.on("SIGINT", closeKnex);
process.on('SIGTERM', closeKnex)
process.on('SIGINT', closeKnex)

View File

@ -1,19 +1,17 @@
import { plugin } from "@nexus/schema";
import { plugin } from '@nexus/schema'
export const logMutationTimePlugin = plugin({
name: "LogMutationTime",
name: 'LogMutationTime',
onCreateFieldResolver(config) {
if (config.parentTypeConfig.name !== "Mutation") {
return;
if (config.parentTypeConfig.name !== 'Mutation') {
return
}
return async (root, args, ctx, info, next) => {
const startTimeMs = new Date().valueOf();
const value = await next(root, args, ctx, info);
const endTimeMs = new Date().valueOf();
console.log(
`Mutation ${info.operation.name} took ${endTimeMs - startTimeMs} ms`
);
return value;
};
const startTimeMs = new Date().valueOf()
const value = await next(root, args, ctx, info)
const endTimeMs = new Date().valueOf()
console.log(`Mutation ${info.operation.name} took ${endTimeMs - startTimeMs} ms`)
return value
}
},
});
})

View File

@ -1,4 +1,4 @@
import { Character, Human, Droid } from "./types/backingTypes";
import { Character, Human, Droid } from './types/backingTypes'
/**
* Copied from GraphQL JS:
@ -18,85 +18,85 @@ import { Character, Human, Droid } from "./types/backingTypes";
*/
const luke = {
type: "Human",
id: "1000",
name: "Luke Skywalker",
friends: ["1002", "1003", "2000", "2001"],
type: 'Human',
id: '1000',
name: 'Luke Skywalker',
friends: ['1002', '1003', '2000', '2001'],
appears_in: [4, 5, 6],
home_planet: "Tatooine",
};
home_planet: 'Tatooine',
}
const vader = {
type: "Human",
id: "1001",
name: "Darth Vader",
friends: ["1004"],
type: 'Human',
id: '1001',
name: 'Darth Vader',
friends: ['1004'],
appears_in: [4, 5, 6],
home_planet: "Tatooine",
};
home_planet: 'Tatooine',
}
const han = {
type: "Human",
id: "1002",
name: "Han Solo",
friends: ["1000", "1003", "2001"],
type: 'Human',
id: '1002',
name: 'Han Solo',
friends: ['1000', '1003', '2001'],
appears_in: [4, 5, 6],
};
}
const leia = {
type: "Human",
id: "1003",
name: "Leia Organa",
friends: ["1000", "1002", "2000", "2001"],
type: 'Human',
id: '1003',
name: 'Leia Organa',
friends: ['1000', '1002', '2000', '2001'],
appears_in: [4, 5, 6],
home_planet: "Alderaan",
};
home_planet: 'Alderaan',
}
const tarkin = {
type: "Human",
id: "1004",
name: "Wilhuff Tarkin",
friends: ["1001"],
type: 'Human',
id: '1004',
name: 'Wilhuff Tarkin',
friends: ['1001'],
appears_in: [4],
};
}
const humanData = {
"1000": luke,
"1001": vader,
"1002": han,
"1003": leia,
"1004": tarkin,
} as { [key in string]: Human };
'1000': luke,
'1001': vader,
'1002': han,
'1003': leia,
'1004': tarkin,
} as { [key in string]: Human }
const threepio = {
type: "Droid",
id: "2000",
name: "C-3PO",
friends: ["1000", "1002", "1003", "2001"],
type: 'Droid',
id: '2000',
name: 'C-3PO',
friends: ['1000', '1002', '1003', '2001'],
appears_in: [4, 5, 6],
primary_function: "Protocol",
};
primary_function: 'Protocol',
}
const artoo = {
type: "Droid",
id: "2001",
name: "R2-D2",
friends: ["1000", "1002", "1003"],
type: 'Droid',
id: '2001',
name: 'R2-D2',
friends: ['1000', '1002', '1003'],
appears_in: [4, 5, 6],
primary_function: "Astromech",
};
primary_function: 'Astromech',
}
const droidData = {
"2000": threepio,
"2001": artoo,
} as { [key in string]: Droid };
'2000': threepio,
'2001': artoo,
} as { [key in string]: Droid }
/**
* Helper function to get a character by ID.
*/
function getCharacter(id: string) {
// Returning a promise just to illustrate GraphQL.js's support.
return Promise.resolve(humanData[id] || droidData[id]);
return Promise.resolve(humanData[id] || droidData[id])
}
/**
@ -104,7 +104,7 @@ function getCharacter(id: string) {
*/
export function getFriends(character: Character) {
// Notice that GraphQL accepts Arrays of Promises.
return character.friends.map((id) => getCharacter(id));
return character.friends.map((id) => getCharacter(id))
}
/**
@ -113,26 +113,26 @@ export function getFriends(character: Character) {
export function getHero(episode?: number | null): Character {
if (episode === 5) {
// Luke is the hero of Episode V.
return luke as Human;
return luke as Human
}
// Artoo is the hero otherwise.
return artoo as Droid;
return artoo as Droid
}
export const allHumans = Object.keys(humanData).map((key) => humanData[key]);
export const allHumans = Object.keys(humanData).map((key) => humanData[key])
/**
* Allows us to query for the human with the given id.
*/
export function getHuman(id: string): Human {
return humanData[id];
return humanData[id]
}
export const allDroids = Object.keys(droidData).map((key) => droidData[key]);
export const allDroids = Object.keys(droidData).map((key) => droidData[key])
/**
* Allows us to query for the droid with the given id.
*/
export function getDroid(id: string): Droid {
return droidData[id];
return droidData[id]
}

View File

@ -1,15 +1,11 @@
import { ApolloServer } from "apollo-server";
import { ApolloServer } from 'apollo-server'
import { schema } from "./schema";
import { schema } from './schema'
const server = new ApolloServer({
schema,
});
})
const port = process.env.PORT || 4000;
const port = process.env.PORT || 4000
server.listen({ port }, () =>
console.log(
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
)
);
server.listen({ port }, () => console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`))

View File

@ -1,14 +1,10 @@
import { ApolloServer } from "apollo-server";
import { schema } from "./schema";
import { ApolloServer } from 'apollo-server'
import { schema } from './schema'
const server = new ApolloServer({
schema,
});
})
const port = process.env.PORT || 4000;
const port = process.env.PORT || 4000
server.listen({ port }, () =>
console.log(
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
)
);
server.listen({ port }, () => console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`))

View File

@ -37,7 +37,7 @@
"dev:examples": "yarn -s link-examples && tsc -w",
"dev:test": "jest --watch",
"examples": "yarn link-examples && yarn gulp run-examples",
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts'",
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'examples/*/src/**.ts'",
"link-examples": "yarn && yarn gulp link-examples",
"lint": "tslint -p tsconfig.json",
"prepublish": "yarn clean && yarn build",
@ -68,13 +68,11 @@
"git add"
]
},
"prettier": "@prisma-labs/prettier-config",
"dependencies": {
"iterall": "^1.2.2",
"tslib": "^1.9.3"
},
"devDependencies": {
"@prisma-labs/prettier-config": "^0.1.0",
"@types/graphql-iso-date": "^3.4.0",
"@types/graphql-relay": "^0.4.11",
"@types/jest": "^25.2.3",