Skip to content

Instantly share code, notes, and snippets.

@shantanoo-desai
Created August 11, 2019 17:17
Show Gist options
  • Save shantanoo-desai/d298cceac1e14d313e401123a2110425 to your computer and use it in GitHub Desktop.
Save shantanoo-desai/d298cceac1e14d313e401123a2110425 to your computer and use it in GitHub Desktop.
Main GraphQL server app
const http = require('http');
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
// GraphQL Schema and Resolvers
const { typeDefs } = require('./graphql/schema');
const { resolvers } = require('./graphql/resolvers');
const server = new ApolloServer({ typeDefs, resolvers });
const app = express();
// Add Express Middleware
server.applyMiddleware({ app });
// Web Socket Middleware
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen({ port: 4000 }, () => {
console.log(`server ready at http://localhost:4000${server.graphqlPath}`);
console.log(`Subscriptions ready at ws://localhost:4000/${server.subscriptionsPath}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment