-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
30 lines (26 loc) · 829 Bytes
/
index.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
'use strict';
const path = require('path');
const fs = require('fs');
const {makeExecutableSchema} = require('graphql-tools');
const {microGraphql} = require('apollo-server-micro');
const JSONScalar = require('graphql-type-json');
const micro = require('micro');
const Document = require('./resolvers/Document');
const Query = require('./resolvers/Query');
const DateScalar = require('./scalars/Date');
const Store = require('./lib/store');
const schemaSource = fs.readFileSync(path.join(__dirname, 'schema.graphql'), 'utf8');
const schema = makeExecutableSchema({
typeDefs: schemaSource,
resolvers: {
Query,
Document,
Date: DateScalar,
JSON: JSONScalar
}
});
module.exports = documentsPath => {
const store = new Store(documentsPath);
const context = {store};
return micro(microGraphql({schema, context}));
};