This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
GraphQLSchema, | |
GraphQLObjectType, | |
GraphQLNonNull, | |
GraphQLInt, | |
GraphQLID, | |
GraphQLString } from 'graphql'; | |
import rp from 'request-promise'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rp from 'request-promise'; | |
{ | |
Query: { | |
person(obj, { id }){ | |
return rp(`https://some-backend.com/person/${id}`) | |
.then( res => JSON.parse(res) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query { | |
person(id: 5) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// resolve functions | |
{ | |
Query: { | |
person: (obj, { id }) => loaders.user.byId(id) | |
} | |
} | |
// loaders | |
{ | |
user: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Person { | |
id: ID, | |
name: String | |
age: Int | |
} | |
type Query { | |
person(id: ID!): Person | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import casual from 'casual'; | |
const mocks = { | |
String: () => 'It works!', | |
Query: () => ({ | |
author: (root, args) => { | |
return { firstName: args.firstName, lastName: args.lastName }; | |
}, | |
}), | |
Author: () => ({ firstName: () => casual.first_name, lastName: () => casual.last_name }), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Author } from './connectors'; | |
const resolvers = { | |
Query: { | |
author(_, args) { | |
return Author.find({ where: args }); | |
}, | |
}, | |
Author: { | |
posts(author) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample GraphQL schema with decorators | |
+connector(storage: "MySQL") | |
+doc(description: "A Person") | |
type Person { | |
+mock(type: "ID") | |
id: Int | |
+mock(raw: "John") | |
name: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { applyDecorators } from 'graphql-tools'; | |
import { | |
GraphQLSchema, | |
GraphQLString, | |
GraphQLObjectType, | |
} from 'graphql'; | |
import { Doc, Log } from 'graphql-decorators'; | |
const Logger = { log: (...args) => console.log(...args) }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import { apolloExpress, OperationStore } from 'apollo-server'; | |
import Schema from './schema'; | |
const PORT = 3000; | |
const store = new OperationStore(Schema); | |
store.put('query testquery{ testString }'); | |
const app = express(); | |
const options = { |
OlderNewer