Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Last active March 19, 2016 20:49
Show Gist options
  • Select an option

  • Save kvendrik/cfc8a9276c9180c10edf to your computer and use it in GitHub Desktop.

Select an option

Save kvendrik/cfc8a9276c9180c10edf to your computer and use it in GitHub Desktop.
A GraphQL Example
npm install -g babel-node
npm install babel-preset-es2015
echo '{ "presets": ["es2015"] }' > .babelrc
babel-node index.js

Schema Examples Types Info

import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt
} from 'graphql';
const User = new GraphQLObjectType({
name: 'User',
fields: () => ({
username: {
type: GraphQLString
},
age: {
type: GraphQLString
}
})
});
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: User,
args: {
id: {
type: GraphQLInt
}
},
resolve: () => ({ username: 'mattivdweem', age: '21' })
}
}
})
});
var query = `
{
user(id: 1){
username
age
}
}
`;
graphql(schema, query).then(result => console.log( JSON.stringify(result, null, 4) ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment