Skip to content

Instantly share code, notes, and snippets.

@helfer
Created April 1, 2016 16:43
Show Gist options
  • Save helfer/6888217303eba05354df108d1b566af1 to your computer and use it in GitHub Desktop.
Save helfer/6888217303eba05354df108d1b566af1 to your computer and use it in GitHub Desktop.
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