Created
August 3, 2018 03:54
-
-
Save command-tab/f6994cf094bfef1df999e5891bc97705 to your computer and use it in GitHub Desktop.
Using Apollo Server 2 with GraphiQL instead of GraphQL Playground
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
const express = require('express'); | |
const { ApolloServer, gql } = require('apollo-server-express'); | |
const graphqlHTTP = require('express-graphql'); | |
const typeDefs = gql` | |
type Query { | |
hello: String | |
} | |
`; | |
const resolvers = { | |
Query: { | |
hello: () => 'Hello world!', | |
}, | |
}; | |
const server = new ApolloServer({ typeDefs, resolvers }); | |
const app = express(); | |
app.get('/graphql', graphqlHTTP({ | |
schema: typeDefs, | |
graphiql: true | |
})); | |
server.applyMiddleware({ app }); | |
app.listen({ port: 4000 }, () => | |
console.log(`Apollo Server ready at http://localhost:4000${server.graphqlPath}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment