Created
June 23, 2019 18:12
-
-
Save ssaumyaranjan7/dcc460eba8e9f1f3962f272d1028f095 to your computer and use it in GitHub Desktop.
This is the index file of GraphQL part-2
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 express = require('express'); | |
const mongoose = require(`mongoose`); | |
const { ApolloServer } = require('apollo-server-express'); | |
// Imported the typeders and resolver | |
const { typeDefs } = require( `./typedefs`); | |
const { resolvers } = require( `./resolvers`); | |
// Created a instance of Apollo server with typedefs and resolvers. | |
const server = new ApolloServer({typeDefs, resolvers}); | |
const app = express(); | |
(async () => { | |
await mongoose.connect('mongodb://localhost/company', {useNewUrlParser: true}) | |
})(); | |
// Apollo server is configured as a middleware | |
server.applyMiddleware({app}); | |
app.listen({port: 4000}, () => { | |
console.log(`🚀 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