Created
September 5, 2016 10:42
-
-
Save MrOrz/86582ad28fd7ddcde1c764f1cb0872ff to your computer and use it in GitHub Desktop.
Minimal 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
const { | |
graphql, | |
GraphQLSchema, | |
GraphQLObjectType, | |
GraphQLString, | |
} = require('graphql'); | |
const schema = new GraphQLSchema({ | |
query: new GraphQLObjectType({ | |
name: 'Query', | |
fields: { | |
serverTime: { | |
type: GraphQLString, | |
resolve() { | |
return (new Date).toLocaleString(); | |
} | |
} | |
}, | |
}) | |
}); | |
const query = `{ | |
serverTime | |
}`; | |
graphql(schema, query).then(result => {console.log(result);}); | |
// Prints: | |
// {data: {serverTime: "9/5/2016, 6:28:46 PM"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment