Last active
June 18, 2017 16:34
-
-
Save ivanbtrujillo/938322193d8b9844bab3ef6b26b2b558 to your computer and use it in GitHub Desktop.
GraphQL. 05 — Conectando GraphQL con el JSON-server - 01
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
const graphql = require('graphql'), | |
// Importamos axios | |
axios = require('axios'); | |
const { | |
GraphQLObjectType, | |
GraphQLString, | |
GraphQLSchema | |
} = graphql; | |
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){ | |
// Ahora hacemos una peticion axios al JSON-Server | |
return axios.get(`http://localhost:3000/users/${args.id}`) | |
.then(response => resp.data); | |
} | |
} | |
} | |
}) | |
module.exports = new GraphQLSchema({ | |
query: RootQuery | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment