-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 830 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (24 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const express = require('express');
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express');
const { makeExecutableSchema } = require('graphql-tools');
const typeDefs = require('./GraphQL/schema');
const resolvers = require('./GraphQL/resolver');
const cors = require('cors');
const dotenv = require('dotenv');
dotenv.config();
const app = express();
// Enable All CORS Requests
app.use(cors())
// Put together a schema
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
// The GraphQL endpoint
app.use('/graphql', express.json(), graphqlExpress({ schema }));
// GraphiQL, a visual editor for queries
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
// Start the server
app.listen(3000, () => {
console.log('Go to http://localhost:3000/graphiql to run queries!');
});