-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d877e5f
commit f524c78
Showing
16 changed files
with
781 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
const graphqlHttp = require('express-graphql'); | ||
const { ApolloServer, graphiqlExpress } = require('apollo-server-express'); | ||
const { createServer } = require('http'); | ||
const { SubscriptionServer } = require('subscriptions-transport-ws'); | ||
const expressPlayground = require('graphql-playground-middleware-express') | ||
.default; | ||
const express = require('express'); | ||
const app = express(); | ||
const cors = require('cors'); | ||
|
||
app.use(cors()); | ||
|
||
const { schema, context } = require('./schema'); | ||
const { typeDefs, resolvers } = require('./schema'); | ||
|
||
const PORT = 3001; | ||
|
||
const initializedGraphQLMiddleware = graphqlHttp({ | ||
// GraphQL’s data schema | ||
schema: schema, | ||
// Pretty Print the JSON response | ||
pretty: true, | ||
// Enable GraphiQL dev tool | ||
graphiql: true, | ||
// A function that returns extra data available to every resolver | ||
context: context, | ||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}); | ||
|
||
app.use(initializedGraphQLMiddleware); | ||
server.applyMiddleware({ app }); | ||
|
||
const webServer = createServer(app); | ||
server.installSubscriptionHandlers(webServer); | ||
|
||
const graphqlEndpoint = `http://localhost:${PORT}${server.graphqlPath}`; | ||
const subscriptionEndpoint = `ws://localhost:${PORT}${ | ||
server.subscriptionsPath | ||
}`; | ||
|
||
app.use(cors()); | ||
app.get( | ||
'/', | ||
expressPlayground({ | ||
endpoint: graphqlEndpoint, | ||
subscriptionEndpoint: subscriptionEndpoint, | ||
}) | ||
); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server running at http://localhost:${PORT}`); | ||
webServer.listen(PORT, () => { | ||
console.log(`🚀 Server ready at ${graphqlEndpoint}`); | ||
console.log(`🚀 Subscriptions ready at ${subscriptionEndpoint}`); | ||
}); |
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
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
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
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
Oops, something went wrong.