Skip to content

Commit

Permalink
chore: Keep prettier config local to the project (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser authored Oct 3, 2020
1 parent 2bceeb9 commit 8f3189c
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 151 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 110,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
82 changes: 41 additions & 41 deletions examples/apollo-fullstack/src/typeDefs.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
}
36 changes: 18 additions & 18 deletions examples/ghost/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
24 changes: 11 additions & 13 deletions examples/kitchen-sink/src/example-plugins.ts
Original file line number Diff line number Diff line change
@@ -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
}
},
});
})
116 changes: 58 additions & 58 deletions examples/star-wars/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Character, Human, Droid } from "./types/backingTypes";
import { Character, Human, Droid } from './types/backingTypes'

/**
* Copied from GraphQL JS:
Expand All @@ -18,93 +18,93 @@ 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])
}

/**
* Allows us to query for a character's friends.
*/
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))
}

/**
Expand All @@ -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]
}
Loading

0 comments on commit 8f3189c

Please sign in to comment.