Created
April 1, 2016 16:43
-
-
Save helfer/6888217303eba05354df108d1b566af1 to your computer and use it in GitHub Desktop.
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'; | |
const Person = new GraphQLObjectType{ | |
name: "User", | |
fields: { | |
id: { type: GraphQLID } | |
name: { type: GraphQLString }, | |
age: { type: GraphQLInt } | |
} | |
}; | |
const Query = new GraphQLObjectType({ | |
name: 'Query', | |
fields: { | |
person: { | |
type: Person, | |
args: { | |
id: { type: new GraphQLNonNull(GraphQLID) }, | |
}, | |
description: 'Get user by ID', | |
resolve: (root, { id }) => { | |
return rp(`https://some-backend.com/person/${id}`) | |
.then( res => JSON.parse(res) ); | |
}, | |
}, | |
} | |
}); | |
const Schema = new GraphQLSchema({ | |
query: Query | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment