This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| // > npm install graphql-tools | |
| import { mockServer } from 'graphql-tools'; | |
| import schema from './mySchema.graphql'; | |
| const myMockServer = mockServer(schema); | |
| myMockServer.query(`{ | |
| allUsers: { | |
| id | |
| name |
This file contains hidden or 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
| // customize mocking per type (i.e. Integer, Float, String) | |
| mockServer(schema, { | |
| Int: () => 6, | |
| Float: () => 22.1, | |
| String: () => 'Hello', | |
| }); | |
| // customize mocking per field in the schema (i.e. for Person.name and Person.age) | |
| mockServer(schema, { |
This file contains hidden or 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 { mockServer, MockList } from 'graphql-tools'; | |
| import casual from 'casual-browserify'; | |
| // The GraphQL schema. Described in more detail here: | |
| // https://medium.com/apollo-stack/the-apollo-server-bc68762e93b | |
| const schema = ` | |
| type User { | |
| id: ID! | |
| name: String |
This file contains hidden or 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 { | |
| makeExecutableSchema, | |
| addMockFunctionsToSchema, | |
| } from 'graphql-tools'; | |
| import mocks from './mocks' | |
| const typeDefs = ` | |
| type Query { | |
| testString: String | |
| } |
This file contains hidden or 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 { makeExecutableSchema } from 'graphql-tools'; | |
| const typeDefs = ` | |
| type Author { | |
| id: Int | |
| firstName: String | |
| lastName: String | |
| posts: [Post] | |
| } | |
| type Post { |
OlderNewer