Skip to content

Instantly share code, notes, and snippets.

@ivanbtrujillo
Last active June 18, 2017 16:34
Show Gist options
  • Save ivanbtrujillo/938322193d8b9844bab3ef6b26b2b558 to your computer and use it in GitHub Desktop.
Save ivanbtrujillo/938322193d8b9844bab3ef6b26b2b558 to your computer and use it in GitHub Desktop.
GraphQL. 05 — Conectando GraphQL con el JSON-server - 01
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