Last active
February 24, 2018 05:09
-
-
Save niten2/00d39ddd35b8afbf23ae569d8beeb972 to your computer and use it in GitHub Desktop.
JS
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
| 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