-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (27 loc) · 838 Bytes
/
server.js
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
30
31
32
33
34
35
36
37
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { loadFilesSync } = require('@graphql-tools/load-files')
const PORT = 4000;
const typesArray = loadFilesSync('**/*', {
extensions: ['graphql'],
});
const resolversArray = loadFilesSync('**/*', {
extensions: ['resolvers.js']
})
async function startApolloServer(){
const app = express();
const schema = makeExecutableSchema({
typeDefs: typesArray,
resolvers: resolversArray
});
const server = new ApolloServer({
schema
});
await server.start();
server.applyMiddleware({app, path:'/graphql'});
app.listen(PORT, () => {
console.log(`Running GraphQL server...`);
})
}
startApolloServer();