-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (25 loc) · 899 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
38
39
const path = require('path');
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const typesArray = loadFilesSync('**/*', {
extensions: ['graphql'],
});
const resolversArray = loadFilesSync(path.join(__dirname, './**/*.resolvers.js'));
async function startApolloServer(typeDefs, resolvers) {
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(3000, () => {
console.log('GraphQL server is running on port 3000');
});
}
startApolloServer();