Skip to content

Instantly share code, notes, and snippets.

@igaskin
Created June 2, 2017 08:04
Show Gist options
  • Save igaskin/341fadf88ed8fb0cc3bb0b9affc14f2f to your computer and use it in GitHub Desktop.
Save igaskin/341fadf88ed8fb0cc3bb0b9affc14f2f to your computer and use it in GitHub Desktop.
Intro to GraphQL in Docker
version: '3'
services:
web:
build: .
ports:
- "4000:4000"
FROM node:7-alpine
COPY ./ /app
WORKDIR /app
CMD node hello.js
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