-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphql.js
46 lines (37 loc) · 1.12 KB
/
graphql.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
40
41
42
43
44
45
46
'use strict';
var _require = require('@graphql-tools/load'),
loadSchemaSync = _require.loadSchemaSync;
var _require2 = require('graphql'),
graphql = _require2.graphql;
var _require3 = require('@graphql-tools/graphql-file-loader'),
GraphQLFileLoader = _require3.GraphQLFileLoader;
var _require4 = require('@graphql-tools/mock'),
addMocksToSchema = _require4.addMocksToSchema;
var GraphQL = function GraphQL(_ref) {
var schemaPath = _ref.schemaPath;
var schema = loadSchemaSync(schemaPath, {
loaders: [new GraphQLFileLoader()],
});
var preserveResolvers = false;
var wrapper = function wrapper(mocks) {
return function (req, res, next) {
var schemaWithMocks = addMocksToSchema({
schema: schema,
mocks: mocks,
preserveResolvers: preserveResolvers,
});
graphql(schemaWithMocks, req.body.query, undefined, undefined, req.body.variables)
.then(function (result) {
res.json(result);
})
['catch'](next);
};
};
wrapper.isGraphQLEndpoint = function () {
return true;
};
return wrapper;
};
module.exports = {
GraphQL: GraphQL,
};