Skip to content

Instantly share code, notes, and snippets.

@MrOrz
Created September 5, 2016 10:42
Show Gist options
  • Save MrOrz/86582ad28fd7ddcde1c764f1cb0872ff to your computer and use it in GitHub Desktop.
Save MrOrz/86582ad28fd7ddcde1c764f1cb0872ff to your computer and use it in GitHub Desktop.
Minimal graphql example
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