Last active
June 18, 2017 16:32
-
-
Save ivanbtrujillo/a8199fa2ef0a187b51782c4cacd7137d to your computer and use it in GitHub Desktop.
GraphQL. 03 — Schemas y GraphiQL - 05
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
const graphql = require('graphql'); | |
const { | |
GraphQLObjectType, | |
GraphQLString, | |
// Importamos GraphQL Schema de GraphQL mediante destructuring | |
GraphQLSchema | |
} = graphql; | |
const users = [ | |
{ id: '1', firstName: 'Ivan', lastName: 'Bacallado', country: 'España' }, | |
{ id: '2', firstName: 'Ana', lastName: 'Lopez', country: 'Mexico' }, | |
{ id: '3', firstName: 'Bill', lastName: 'Thomson', country: 'EEUU' }, | |
{ id: '4', firstName: 'Maximilian', lastName: 'Lahm', country: 'Alemania' }, | |
]; | |
const UserType = new GraphQLObjectType({ | |
name: 'User', | |
fields: { | |
id: { type: GraphQLString }, | |
firstName: { type: GraphQLString }, | |
lastName: { type: GraphQLString }, | |
country: { type: GraphQLString } | |
} | |
}) | |
const RootQuery = new GraphQLObjectType({ | |
name: 'RootQueryType', | |
fields: { | |
user: { | |
type: UserType, | |
args: { id: { type: GraphQLString }}, | |
resolve(parentValue, args){ | |
return users.find((user) => user.id === args.id); | |
} | |
} | |
} | |
}) | |
// Exportamos nuestro schema | |
module.exports = new GraphQLSchema({ | |
query: RootQuery | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment