1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const debug = require('debug')('huncwot:graphql');
|
15 |
|
16 | const { OK, HTMLString } = require('./response.js');
|
17 |
|
18 | const { runHttpQuery } = require('apollo-server-core');
|
19 | const { resolveGraphiQLString } = require('apollo-server-module-graphiql');
|
20 | const { makeExecutableSchema } = require('graphql-tools');
|
21 |
|
22 | function graphql(options) {
|
23 | return async request => {
|
24 | let method = request.request.method;
|
25 | let query = request.params;
|
26 | let { graphqlResponse, responseInit } = await runHttpQuery([], {
|
27 | method,
|
28 | options,
|
29 | query
|
30 | });
|
31 |
|
32 | return OK(graphqlResponse);
|
33 | };
|
34 | }
|
35 |
|
36 | function graphiql(options) {
|
37 | return async request => {
|
38 | let query = request.params;
|
39 | let response = await resolveGraphiQLString(query, options, request);
|
40 |
|
41 | return HTMLString(response);
|
42 | };
|
43 | }
|
44 |
|
45 | module.exports = {
|
46 | graphiql,
|
47 | graphql,
|
48 | makeSchema: makeExecutableSchema
|
49 | };
|