Skip to content

Instantly share code, notes, and snippets.

@command-tab
Created August 3, 2018 03:54
Show Gist options
  • Save command-tab/f6994cf094bfef1df999e5891bc97705 to your computer and use it in GitHub Desktop.
Save command-tab/f6994cf094bfef1df999e5891bc97705 to your computer and use it in GitHub Desktop.
Using Apollo Server 2 with GraphiQL instead of GraphQL Playground
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