Created
June 2, 2017 08:04
-
-
Save igaskin/341fadf88ed8fb0cc3bb0b9affc14f2f to your computer and use it in GitHub Desktop.
Intro to GraphQL in Docker
This file contains 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
version: '3' | |
services: | |
web: | |
build: . | |
ports: | |
- "4000:4000" |
This file contains 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
FROM node:7-alpine | |
COPY ./ /app | |
WORKDIR /app | |
CMD node hello.js |
This file contains 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'); | |
// Construct a schema, using GraphQL schema language | |
var schema = buildSchema(` | |
type Query { | |
hello: String | |
} | |
`); | |
// The root provides a resolver function for each API endpoint | |
var root = { | |
hello: () => { | |
return 'Hello world!'; | |
}, | |
}; | |
var app = express(); | |
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