chore: Keep prettier config local to the project (#531)
This commit is contained in:
parent
2bceeb915f
commit
8f3189c069
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"printWidth": 110,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"arrowParens": "always"
|
||||||
|
}
|
||||||
|
|
@ -1,46 +1,46 @@
|
||||||
import { RESTDataSource } from "apollo-datasource-rest";
|
import { RESTDataSource } from 'apollo-datasource-rest'
|
||||||
import { DataSource } from "apollo-datasource";
|
import { DataSource } from 'apollo-datasource'
|
||||||
|
|
||||||
export interface Mission {
|
export interface Mission {
|
||||||
name: string;
|
name: string
|
||||||
missionPatchSmall: string;
|
missionPatchSmall: string
|
||||||
missionPatchLarge: string;
|
missionPatchLarge: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Rocket {
|
export interface Rocket {
|
||||||
id: number;
|
id: number
|
||||||
name: string;
|
name: string
|
||||||
type: string;
|
type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Launch {
|
export interface Launch {
|
||||||
id: number;
|
id: number
|
||||||
cursor: string;
|
cursor: string
|
||||||
site: string;
|
site: string
|
||||||
mission: Mission;
|
mission: Mission
|
||||||
rocket: Rocket;
|
rocket: Rocket
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DBUser {
|
export interface DBUser {
|
||||||
id: string;
|
id: string
|
||||||
createdAt: Date;
|
createdAt: Date
|
||||||
updatedAt: Date;
|
updatedAt: Date
|
||||||
email: string;
|
email: string
|
||||||
token: string;
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DBTrip {
|
export interface DBTrip {
|
||||||
id: number;
|
id: number
|
||||||
createdAt: Date;
|
createdAt: Date
|
||||||
updatedAt: Date;
|
updatedAt: Date
|
||||||
launchId: number;
|
launchId: number
|
||||||
userId: number;
|
userId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LaunchApi extends RESTDataSource {
|
export interface LaunchApi extends RESTDataSource {
|
||||||
getAllLaunches(): Promise<Launch[]>;
|
getAllLaunches(): Promise<Launch[]>
|
||||||
getLaunchById(opts: { launchId: string }): Promise<Launch>;
|
getLaunchById(opts: { launchId: string }): Promise<Launch>
|
||||||
getLaunchesByIds(opts: { launchIds: string[] }): Promise<Launch[]>;
|
getLaunchesByIds(opts: { launchIds: string[] }): Promise<Launch[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserApi extends DataSource {
|
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
|
* have to be. If the user is already on the context, it will use that user
|
||||||
* instead
|
* instead
|
||||||
*/
|
*/
|
||||||
findOrCreateUser(obj?: { email?: string | null }): Promise<DBUser | null>;
|
findOrCreateUser(obj?: { email?: string | null }): Promise<DBUser | null>
|
||||||
bookTrips(obj: { launchIds: string[] }): Promise<DBTrip[]>;
|
bookTrips(obj: { launchIds: string[] }): Promise<DBTrip[]>
|
||||||
bookTrip(obj: { launchId: string }): Promise<DBTrip | false>;
|
bookTrip(obj: { launchId: string }): Promise<DBTrip | false>
|
||||||
cancelTrip(obj: { launchId: string }): Promise<void>;
|
cancelTrip(obj: { launchId: string }): Promise<void>
|
||||||
getLaunchIdsByUser(): Promise<string[]>;
|
getLaunchIdsByUser(): Promise<string[]>
|
||||||
isBookedOnLaunch(obj: { launchId: string }): boolean;
|
isBookedOnLaunch(obj: { launchId: string }): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Utils {
|
export interface Utils {
|
||||||
paginateResults<T>(opts: {
|
paginateResults<T>(opts: {
|
||||||
after?: string | null;
|
after?: string | null
|
||||||
pageSize?: number | null;
|
pageSize?: number | null
|
||||||
results: T[];
|
results: T[]
|
||||||
getCursor?: Function;
|
getCursor?: Function
|
||||||
}): T[];
|
}): T[]
|
||||||
createStore(): {};
|
createStore(): {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Context {
|
export interface Context {
|
||||||
dataSources: {
|
dataSources: {
|
||||||
userAPI: UserApi;
|
userAPI: UserApi
|
||||||
launchAPI: LaunchApi;
|
launchAPI: LaunchApi
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import ghost from "ghost";
|
import ghost from 'ghost'
|
||||||
import db from "ghost/core/server/data/db";
|
import db from 'ghost/core/server/data/db'
|
||||||
import { ApolloServer } from "apollo-server-express";
|
import { ApolloServer } from 'apollo-server-express'
|
||||||
import express from "express";
|
import express from 'express'
|
||||||
import { schema } from "./ghost-schema";
|
import { schema } from './ghost-schema'
|
||||||
import { Context } from "./data-sources/Context";
|
import { Context } from './data-sources/Context'
|
||||||
import { knex } from "./utils/knexInstance";
|
import { knex } from './utils/knexInstance'
|
||||||
|
|
||||||
const demoApp = express();
|
const demoApp = express()
|
||||||
|
|
||||||
// Note: This isn't (yet) protected by any sort of
|
// Note: This isn't (yet) protected by any sort of
|
||||||
// authentication/authorization, so don't try running queries in
|
// authentication/authorization, so don't try running queries in
|
||||||
|
|
@ -15,15 +15,15 @@ ghost().then((ghostServer) => {
|
||||||
const apolloServer = new ApolloServer({
|
const apolloServer = new ApolloServer({
|
||||||
schema,
|
schema,
|
||||||
context: () => new Context(),
|
context: () => new Context(),
|
||||||
});
|
})
|
||||||
apolloServer.applyMiddleware({ app: demoApp });
|
apolloServer.applyMiddleware({ app: demoApp })
|
||||||
demoApp.use("/", ghostServer.rootApp);
|
demoApp.use('/', ghostServer.rootApp)
|
||||||
ghostServer.start(demoApp);
|
ghostServer.start(demoApp)
|
||||||
console.log("Ghost server Ready!");
|
console.log('Ghost server Ready!')
|
||||||
});
|
})
|
||||||
function closeKnex() {
|
function closeKnex() {
|
||||||
db.knex.destroy();
|
db.knex.destroy()
|
||||||
knex.destroy();
|
knex.destroy()
|
||||||
}
|
}
|
||||||
process.on("SIGTERM", closeKnex);
|
process.on('SIGTERM', closeKnex)
|
||||||
process.on("SIGINT", closeKnex);
|
process.on('SIGINT', closeKnex)
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
import { plugin } from "@nexus/schema";
|
import { plugin } from '@nexus/schema'
|
||||||
|
|
||||||
export const logMutationTimePlugin = plugin({
|
export const logMutationTimePlugin = plugin({
|
||||||
name: "LogMutationTime",
|
name: 'LogMutationTime',
|
||||||
onCreateFieldResolver(config) {
|
onCreateFieldResolver(config) {
|
||||||
if (config.parentTypeConfig.name !== "Mutation") {
|
if (config.parentTypeConfig.name !== 'Mutation') {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
return async (root, args, ctx, info, next) => {
|
return async (root, args, ctx, info, next) => {
|
||||||
const startTimeMs = new Date().valueOf();
|
const startTimeMs = new Date().valueOf()
|
||||||
const value = await next(root, args, ctx, info);
|
const value = await next(root, args, ctx, info)
|
||||||
const endTimeMs = new Date().valueOf();
|
const endTimeMs = new Date().valueOf()
|
||||||
console.log(
|
console.log(`Mutation ${info.operation.name} took ${endTimeMs - startTimeMs} ms`)
|
||||||
`Mutation ${info.operation.name} took ${endTimeMs - startTimeMs} ms`
|
return value
|
||||||
);
|
}
|
||||||
return value;
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Character, Human, Droid } from "./types/backingTypes";
|
import { Character, Human, Droid } from './types/backingTypes'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copied from GraphQL JS:
|
* Copied from GraphQL JS:
|
||||||
|
|
@ -18,85 +18,85 @@ import { Character, Human, Droid } from "./types/backingTypes";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const luke = {
|
const luke = {
|
||||||
type: "Human",
|
type: 'Human',
|
||||||
id: "1000",
|
id: '1000',
|
||||||
name: "Luke Skywalker",
|
name: 'Luke Skywalker',
|
||||||
friends: ["1002", "1003", "2000", "2001"],
|
friends: ['1002', '1003', '2000', '2001'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
home_planet: "Tatooine",
|
home_planet: 'Tatooine',
|
||||||
};
|
}
|
||||||
|
|
||||||
const vader = {
|
const vader = {
|
||||||
type: "Human",
|
type: 'Human',
|
||||||
id: "1001",
|
id: '1001',
|
||||||
name: "Darth Vader",
|
name: 'Darth Vader',
|
||||||
friends: ["1004"],
|
friends: ['1004'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
home_planet: "Tatooine",
|
home_planet: 'Tatooine',
|
||||||
};
|
}
|
||||||
|
|
||||||
const han = {
|
const han = {
|
||||||
type: "Human",
|
type: 'Human',
|
||||||
id: "1002",
|
id: '1002',
|
||||||
name: "Han Solo",
|
name: 'Han Solo',
|
||||||
friends: ["1000", "1003", "2001"],
|
friends: ['1000', '1003', '2001'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
};
|
}
|
||||||
|
|
||||||
const leia = {
|
const leia = {
|
||||||
type: "Human",
|
type: 'Human',
|
||||||
id: "1003",
|
id: '1003',
|
||||||
name: "Leia Organa",
|
name: 'Leia Organa',
|
||||||
friends: ["1000", "1002", "2000", "2001"],
|
friends: ['1000', '1002', '2000', '2001'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
home_planet: "Alderaan",
|
home_planet: 'Alderaan',
|
||||||
};
|
}
|
||||||
|
|
||||||
const tarkin = {
|
const tarkin = {
|
||||||
type: "Human",
|
type: 'Human',
|
||||||
id: "1004",
|
id: '1004',
|
||||||
name: "Wilhuff Tarkin",
|
name: 'Wilhuff Tarkin',
|
||||||
friends: ["1001"],
|
friends: ['1001'],
|
||||||
appears_in: [4],
|
appears_in: [4],
|
||||||
};
|
}
|
||||||
|
|
||||||
const humanData = {
|
const humanData = {
|
||||||
"1000": luke,
|
'1000': luke,
|
||||||
"1001": vader,
|
'1001': vader,
|
||||||
"1002": han,
|
'1002': han,
|
||||||
"1003": leia,
|
'1003': leia,
|
||||||
"1004": tarkin,
|
'1004': tarkin,
|
||||||
} as { [key in string]: Human };
|
} as { [key in string]: Human }
|
||||||
|
|
||||||
const threepio = {
|
const threepio = {
|
||||||
type: "Droid",
|
type: 'Droid',
|
||||||
id: "2000",
|
id: '2000',
|
||||||
name: "C-3PO",
|
name: 'C-3PO',
|
||||||
friends: ["1000", "1002", "1003", "2001"],
|
friends: ['1000', '1002', '1003', '2001'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
primary_function: "Protocol",
|
primary_function: 'Protocol',
|
||||||
};
|
}
|
||||||
|
|
||||||
const artoo = {
|
const artoo = {
|
||||||
type: "Droid",
|
type: 'Droid',
|
||||||
id: "2001",
|
id: '2001',
|
||||||
name: "R2-D2",
|
name: 'R2-D2',
|
||||||
friends: ["1000", "1002", "1003"],
|
friends: ['1000', '1002', '1003'],
|
||||||
appears_in: [4, 5, 6],
|
appears_in: [4, 5, 6],
|
||||||
primary_function: "Astromech",
|
primary_function: 'Astromech',
|
||||||
};
|
}
|
||||||
|
|
||||||
const droidData = {
|
const droidData = {
|
||||||
"2000": threepio,
|
'2000': threepio,
|
||||||
"2001": artoo,
|
'2001': artoo,
|
||||||
} as { [key in string]: Droid };
|
} as { [key in string]: Droid }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get a character by ID.
|
* Helper function to get a character by ID.
|
||||||
*/
|
*/
|
||||||
function getCharacter(id: string) {
|
function getCharacter(id: string) {
|
||||||
// Returning a promise just to illustrate GraphQL.js's support.
|
// 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) {
|
export function getFriends(character: Character) {
|
||||||
// Notice that GraphQL accepts Arrays of Promises.
|
// 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 {
|
export function getHero(episode?: number | null): Character {
|
||||||
if (episode === 5) {
|
if (episode === 5) {
|
||||||
// Luke is the hero of Episode V.
|
// Luke is the hero of Episode V.
|
||||||
return luke as Human;
|
return luke as Human
|
||||||
}
|
}
|
||||||
// Artoo is the hero otherwise.
|
// 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.
|
* Allows us to query for the human with the given id.
|
||||||
*/
|
*/
|
||||||
export function getHuman(id: string): Human {
|
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.
|
* Allows us to query for the droid with the given id.
|
||||||
*/
|
*/
|
||||||
export function getDroid(id: string): Droid {
|
export function getDroid(id: string): Droid {
|
||||||
return droidData[id];
|
return droidData[id]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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({
|
const server = new ApolloServer({
|
||||||
schema,
|
schema,
|
||||||
});
|
})
|
||||||
|
|
||||||
const port = process.env.PORT || 4000;
|
const port = process.env.PORT || 4000
|
||||||
|
|
||||||
server.listen({ port }, () =>
|
server.listen({ port }, () => console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`))
|
||||||
console.log(
|
|
||||||
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
import { ApolloServer } from "apollo-server";
|
import { ApolloServer } from 'apollo-server'
|
||||||
import { schema } from "./schema";
|
import { schema } from './schema'
|
||||||
|
|
||||||
const server = new ApolloServer({
|
const server = new ApolloServer({
|
||||||
schema,
|
schema,
|
||||||
});
|
})
|
||||||
|
|
||||||
const port = process.env.PORT || 4000;
|
const port = process.env.PORT || 4000
|
||||||
|
|
||||||
server.listen({ port }, () =>
|
server.listen({ port }, () => console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`))
|
||||||
console.log(
|
|
||||||
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
"dev:examples": "yarn -s link-examples && tsc -w",
|
"dev:examples": "yarn -s link-examples && tsc -w",
|
||||||
"dev:test": "jest --watch",
|
"dev:test": "jest --watch",
|
||||||
"examples": "yarn link-examples && yarn gulp run-examples",
|
"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",
|
"link-examples": "yarn && yarn gulp link-examples",
|
||||||
"lint": "tslint -p tsconfig.json",
|
"lint": "tslint -p tsconfig.json",
|
||||||
"prepublish": "yarn clean && yarn build",
|
"prepublish": "yarn clean && yarn build",
|
||||||
|
|
@ -68,13 +68,11 @@
|
||||||
"git add"
|
"git add"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"prettier": "@prisma-labs/prettier-config",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"iterall": "^1.2.2",
|
"iterall": "^1.2.2",
|
||||||
"tslib": "^1.9.3"
|
"tslib": "^1.9.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@prisma-labs/prettier-config": "^0.1.0",
|
|
||||||
"@types/graphql-iso-date": "^3.4.0",
|
"@types/graphql-iso-date": "^3.4.0",
|
||||||
"@types/graphql-relay": "^0.4.11",
|
"@types/graphql-relay": "^0.4.11",
|
||||||
"@types/jest": "^25.2.3",
|
"@types/jest": "^25.2.3",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue