npm install -g babel-node
npm install babel-preset-es2015
echo '{ "presets": ["es2015"] }' > .babelrc
babel-node index.js
Last active
March 19, 2016 20:49
-
-
Save kvendrik/cfc8a9276c9180c10edf to your computer and use it in GitHub Desktop.
A GraphQL Example
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
| 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