Skip to content

Instantly share code, notes, and snippets.

@niten2
Last active February 24, 2018 05:09
Show Gist options
  • Select an option

  • Save niten2/00d39ddd35b8afbf23ae569d8beeb972 to your computer and use it in GitHub Desktop.

Select an option

Save niten2/00d39ddd35b8afbf23ae569d8beeb972 to your computer and use it in GitHub Desktop.
JS
var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
ip: String
}
`);
function loggingMiddleware(req, res, next) {
console.log('ip:', req.ip);
next();
}
var root = {
ip: function (args, request) {
return request.ip;
}
};
var app = express();
app.use(loggingMiddleware);
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,
}));
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment