Skip to content

Instantly share code, notes, and snippets.

@freddi301
Created June 17, 2016 09:38
Show Gist options
  • Save freddi301/0c04eed646a0f8b31ab6042599b2c6f6 to your computer and use it in GitHub Desktop.
Save freddi301/0c04eed646a0f8b31ab6042599b2c6f6 to your computer and use it in GitHub Desktop.
GraphQL Node Hello World with thron
const g = require('graphql'),
graphql = g.graphql,
GraphQLSchema = g.GraphQLSchema,
GraphQLObjectType = g.GraphQLObjectType,
GraphQLString = g.GraphQLString
const schema = new GraphQLSchema({
query: new GraphQLObjectType({ name: 'RootQueryType', fields: {
hello: { type: GraphQLString, resolve() { return 'world'; } },
ciao: { type: GraphQLString, resolve(){return Promise.resolve("heila")} }
}}),
mutation: new GraphQLObjectType({ name: 'RootMutationType', fields: {
hello: { type: GraphQLString, resolve() { return 'gur'; } },
ciao: { type: GraphQLString, resolve(){return Promise.resolve("bil")}}
}})
});
/*graphql(schema, 'mutation { hello ciao }').then(result => {
console.log(result);
});*/
const express = require('express'),
throng = require('throng'),
graphqlHTTP = require('express-graphql')
throng(()=>{
const app = express()
app.use('/graphql', graphqlHTTP({ schema, graphiql: true }));
app.listen(7777, ()=>console.log("listening"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment