Created
August 11, 2019 17:17
-
-
Save shantanoo-desai/d298cceac1e14d313e401123a2110425 to your computer and use it in GitHub Desktop.
Main GraphQL server app
This file contains hidden or 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 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