-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.graphql.js
More file actions
62 lines (51 loc) · 1.5 KB
/
Copy pathindex.graphql.js
File metadata and controls
62 lines (51 loc) · 1.5 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import fs from 'fs';
import express from 'express';
import graphqlHTTP from 'express-graphql';
import { ZeroConf } from 'zeroconf';
import ZeroConfUpload from 'zeroconf_upload';
import appRoot from 'app-root-path';
import { makeExecutableSchema } from 'graphql-tools';
import context from './context';
import sequelizeConfig from './.sequelize.cfg';
const hooksPath = `${appRoot}/clouds/hooks`;
const extendsPath = `${appRoot}/clouds/extends`;
const typesPath = `${appRoot}/clouds/types`;
const initServer = async () => {
const zeroConf = new ZeroConf({
hooksPath,
extendsPath,
typesPath,
sequelizeConfig,
context,
uploads: {
maxFieldSize: 100000000,
maxFileSize: 100000000,
maxFiles: 20,
},
});
zeroConf.use(ZeroConfUpload);
await zeroConf.configuration();
const { typeDefs, resolvers } = zeroConf;
// You can also see the generated schema by zeroconf through to save the file.
fs.writeFileSync(`${appRoot}/.zeroconf/schema.graphql`, typeDefs, 'utf-8');
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
const app = express();
app.use(
'/graphql',
graphqlHTTP(async (...args) => {
return {
schema,
...zeroConf,
context: await zeroConf.context(args)
}
}),
);
app.listen(process.env.GRAPHQL_PORT, process.env.GRAPHQL_HOST, () => {
const url = `http://${process.env.GRAPHQL_HOST}:${process.env.GRAPHQL_PORT}`;
console.log(`Server ready at ${url}/graphql`);
});
};
initServer();