Skip to content

Instantly share code, notes, and snippets.

@ssaumyaranjan7
Created June 23, 2019 18:12
Show Gist options
  • Save ssaumyaranjan7/dcc460eba8e9f1f3962f272d1028f095 to your computer and use it in GitHub Desktop.
Save ssaumyaranjan7/dcc460eba8e9f1f3962f272d1028f095 to your computer and use it in GitHub Desktop.
This is the index file of GraphQL part-2
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