@orion-js/graphql 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/buildSchema/getArgs/getField.js +61 -0
- package/lib/buildSchema/getArgs/index.js +34 -0
- package/lib/buildSchema/getMutation.js +30 -0
- package/lib/buildSchema/getQuery.js +30 -0
- package/lib/buildSchema/getResolvers/index.js +65 -0
- package/lib/buildSchema/getSubscription.js +27 -0
- package/lib/buildSchema/getSubscriptions/index.js +42 -0
- package/lib/buildSchema/getType/BigIntScalar.js +53 -0
- package/lib/buildSchema/getType/DateScalar.js +19 -0
- package/lib/buildSchema/getType/JSONScalar.js +58 -0
- package/lib/buildSchema/getType/getScalar.js +45 -0
- package/lib/buildSchema/getType/getTypeAsResolver.js +42 -0
- package/lib/buildSchema/getType/index.js +85 -0
- package/lib/buildSchema/index.js +29 -0
- package/lib/errorHandler.js +31 -0
- package/lib/getApolloOptions/formatError.js +22 -0
- package/lib/getApolloOptions/index.js +27 -0
- package/lib/index.js +70 -0
- package/lib/pubsub.js +19 -0
- package/lib/resolversSchemas/ResolverParams.js +53 -0
- package/lib/resolversSchemas/getBasicResultQuery.js +28 -0
- package/lib/resolversSchemas/getField.js +54 -0
- package/lib/resolversSchemas/getField.test.js +30 -0
- package/lib/resolversSchemas/index.js +15 -0
- package/lib/resolversSchemas/params.js +46 -0
- package/lib/resolversSchemas/serializeSchema.js +23 -0
- package/lib/resolversSchemas/serializeSchema.test.js +30 -0
- package/lib/startGraphQL.js +73 -0
- package/lib/startGraphiQL.js +211 -0
- package/lib/startWebsocket.js +61 -0
- package/lib/subscription/getChannelName.js +21 -0
- package/lib/subscription/index.js +52 -0
- package/package.json +41 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
function _default(apolloError) {
|
|
9
|
+
let response = { ...apolloError
|
|
10
|
+
};
|
|
11
|
+
const error = apolloError.originalError;
|
|
12
|
+
|
|
13
|
+
if (error && error.isValidationError) {
|
|
14
|
+
response.validationErrors = error.validationErrors;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (error && error.getInfo) {
|
|
18
|
+
response = error.getInfo();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = _default;
|
|
9
|
+
|
|
10
|
+
var _buildSchema = _interopRequireDefault(require("../buildSchema"));
|
|
11
|
+
|
|
12
|
+
var _formatError = _interopRequireDefault(require("./formatError"));
|
|
13
|
+
|
|
14
|
+
async function _default(options) {
|
|
15
|
+
const schema = await (0, _buildSchema.default)(options);
|
|
16
|
+
return {
|
|
17
|
+
endpointURL: '/graphql',
|
|
18
|
+
subscriptionsEndpoint: `/subscriptions`,
|
|
19
|
+
schema,
|
|
20
|
+
formatError: _formatError.default,
|
|
21
|
+
useGraphiql: options.useGraphiql || true,
|
|
22
|
+
context: integrationContext => {
|
|
23
|
+
return integrationContext.req._orionjsViewer;
|
|
24
|
+
},
|
|
25
|
+
...options
|
|
26
|
+
};
|
|
27
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "subscription", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _subscription.default;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "startGraphQL", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _startGraphQL.default;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "startGraphiQL", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _startGraphiQL.default;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "resolversSchemas", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _resolversSchemas.default;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "ResolverParams", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _ResolverParams.default;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "serializeSchema", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _serializeSchema.default;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "getBasicResultQuery", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _getBasicResultQuery.default;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
exports.GraphQL = void 0;
|
|
53
|
+
|
|
54
|
+
var _subscription = _interopRequireDefault(require("./subscription"));
|
|
55
|
+
|
|
56
|
+
var _startGraphQL = _interopRequireDefault(require("./startGraphQL"));
|
|
57
|
+
|
|
58
|
+
var _startGraphiQL = _interopRequireDefault(require("./startGraphiQL"));
|
|
59
|
+
|
|
60
|
+
var _resolversSchemas = _interopRequireDefault(require("./resolversSchemas"));
|
|
61
|
+
|
|
62
|
+
var _ResolverParams = _interopRequireDefault(require("./resolversSchemas/ResolverParams"));
|
|
63
|
+
|
|
64
|
+
var _serializeSchema = _interopRequireDefault(require("./resolversSchemas/serializeSchema"));
|
|
65
|
+
|
|
66
|
+
var _getBasicResultQuery = _interopRequireDefault(require("./resolversSchemas/getBasicResultQuery"));
|
|
67
|
+
|
|
68
|
+
var GraphQL = _interopRequireWildcard(require("graphql"));
|
|
69
|
+
|
|
70
|
+
exports.GraphQL = GraphQL;
|
package/lib/pubsub.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPubsub = exports.setPubsub = void 0;
|
|
7
|
+
let pubsub = null;
|
|
8
|
+
|
|
9
|
+
const setPubsub = function (newPubsub) {
|
|
10
|
+
pubsub = newPubsub;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.setPubsub = setPubsub;
|
|
14
|
+
|
|
15
|
+
const getPubsub = function () {
|
|
16
|
+
return pubsub;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.getPubsub = getPubsub;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _serializeSchema = _interopRequireDefault(require("./serializeSchema"));
|
|
11
|
+
|
|
12
|
+
var _getBasicResultQuery = _interopRequireDefault(require("./getBasicResultQuery"));
|
|
13
|
+
|
|
14
|
+
var _app = require("@orion-js/app");
|
|
15
|
+
|
|
16
|
+
var _default = new _app.Model({
|
|
17
|
+
name: 'ResolverParams',
|
|
18
|
+
schema: {
|
|
19
|
+
name: {
|
|
20
|
+
type: String
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
resolvers: {
|
|
24
|
+
params: (0, _app.resolver)({
|
|
25
|
+
returns: 'blackbox',
|
|
26
|
+
resolve: async function ({
|
|
27
|
+
resolver
|
|
28
|
+
}) {
|
|
29
|
+
return await (0, _serializeSchema.default)(resolver.params);
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
result: (0, _app.resolver)({
|
|
33
|
+
returns: String,
|
|
34
|
+
resolve: async function ({
|
|
35
|
+
resolver
|
|
36
|
+
}) {
|
|
37
|
+
return resolver.returns.name;
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
basicResultQuery: (0, _app.resolver)({
|
|
41
|
+
returns: String,
|
|
42
|
+
resolve: async function ({
|
|
43
|
+
resolver
|
|
44
|
+
}) {
|
|
45
|
+
return await (0, _getBasicResultQuery.default)({
|
|
46
|
+
type: resolver.returns.schema
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
exports.default = _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = getBasicQuery;
|
|
9
|
+
|
|
10
|
+
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
11
|
+
|
|
12
|
+
async function getBasicQuery(field) {
|
|
13
|
+
if (!field.type) return '';
|
|
14
|
+
|
|
15
|
+
if ((0, _isArray.default)(field.type) && field.type[0].__model || field.type.__model) {
|
|
16
|
+
const model = (0, _isArray.default)(field.type) ? field.type[0].__model : field.type.__model;
|
|
17
|
+
const fields = [];
|
|
18
|
+
|
|
19
|
+
for (const field of model.staticFields) {
|
|
20
|
+
fields.push(await getBasicQuery(field));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const key = field.key ? `${field.key} ` : '';
|
|
24
|
+
return `${key}{ ${fields.join(' ')} }`;
|
|
25
|
+
} else {
|
|
26
|
+
return field.key;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = getParams;
|
|
9
|
+
|
|
10
|
+
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
11
|
+
|
|
12
|
+
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
13
|
+
|
|
14
|
+
var _schema = require("@orion-js/schema");
|
|
15
|
+
|
|
16
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
17
|
+
|
|
18
|
+
var _getScalar = _interopRequireDefault(require("../buildSchema/getType/getScalar"));
|
|
19
|
+
|
|
20
|
+
async function getParams(field) {
|
|
21
|
+
const {
|
|
22
|
+
type
|
|
23
|
+
} = field;
|
|
24
|
+
|
|
25
|
+
if ((0, _isArray.default)(type)) {
|
|
26
|
+
const serialized = await getParams({ ...field,
|
|
27
|
+
type: type[0]
|
|
28
|
+
});
|
|
29
|
+
return { ...serialized,
|
|
30
|
+
type: [serialized.type],
|
|
31
|
+
__graphQLType: `[${serialized.__graphQLType}]`
|
|
32
|
+
};
|
|
33
|
+
} else if (!type._isFieldType && ((0, _isPlainObject.default)(type) || type.__isModel)) {
|
|
34
|
+
const model = type.__isModel ? type : type.__model;
|
|
35
|
+
if (!model || !model.__isModel) throw new Error('Type if not a Model', type);
|
|
36
|
+
const fields = {};
|
|
37
|
+
|
|
38
|
+
for (const field of model.staticFields) {
|
|
39
|
+
fields[field.key] = await getParams(field);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { ...(0, _omit.default)(field, 'key'),
|
|
43
|
+
type: fields,
|
|
44
|
+
__graphQLType: model.name + 'Input'
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
const schemaType = await (0, _schema.getFieldType)(type);
|
|
48
|
+
const graphQLType = await (0, _getScalar.default)(schemaType);
|
|
49
|
+
return { ...(0, _omit.default)(field, 'key'),
|
|
50
|
+
type: schemaType.name,
|
|
51
|
+
__graphQLType: graphQLType.name
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _getField = _interopRequireDefault(require("./getField"));
|
|
6
|
+
|
|
7
|
+
it('should return a valid serialization of the field', async () => {
|
|
8
|
+
const schema = {
|
|
9
|
+
name: {
|
|
10
|
+
type: String,
|
|
11
|
+
a: '1234'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const result = await (0, _getField.default)(schema.name);
|
|
15
|
+
expect(result).toEqual({
|
|
16
|
+
type: 'string',
|
|
17
|
+
a: '1234',
|
|
18
|
+
__graphQLType: 'String'
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('should pass field options with simple array fields', async () => {
|
|
22
|
+
const schema = {
|
|
23
|
+
name: {
|
|
24
|
+
type: [String],
|
|
25
|
+
a: '1234'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const result = await (0, _getField.default)(schema.name);
|
|
29
|
+
expect(result.a).toEqual(schema.name.a);
|
|
30
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _params = _interopRequireDefault(require("./params"));
|
|
11
|
+
|
|
12
|
+
var _default = {
|
|
13
|
+
params: _params.default
|
|
14
|
+
};
|
|
15
|
+
exports.default = _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _app = require("@orion-js/app");
|
|
11
|
+
|
|
12
|
+
var _ResolverParams = _interopRequireDefault(require("./ResolverParams"));
|
|
13
|
+
|
|
14
|
+
var _default = (0, _app.resolver)({
|
|
15
|
+
params: {
|
|
16
|
+
name: {
|
|
17
|
+
type: 'ID'
|
|
18
|
+
},
|
|
19
|
+
mutation: {
|
|
20
|
+
type: Boolean
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
returns: _ResolverParams.default,
|
|
24
|
+
mutation: false,
|
|
25
|
+
resolve: async function ({
|
|
26
|
+
mutation,
|
|
27
|
+
name
|
|
28
|
+
}, viewer) {
|
|
29
|
+
const resolver = global.graphQLResolvers[name];
|
|
30
|
+
|
|
31
|
+
if (!resolver) {
|
|
32
|
+
throw new _app.UserError('notFound', `${mutation ? 'Mutation' : 'Query'} named "${name}" not found`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!!resolver.mutation !== !!mutation) {
|
|
36
|
+
throw new _app.UserError('incorrectType', `"${name}" is ${mutation ? 'not' : ''} a mutation`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
resolver,
|
|
41
|
+
name
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
exports.default = _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = serializeSchema;
|
|
9
|
+
|
|
10
|
+
var _getField = _interopRequireDefault(require("./getField"));
|
|
11
|
+
|
|
12
|
+
async function serializeSchema(params) {
|
|
13
|
+
if (!params) return;
|
|
14
|
+
if (Object.keys(params).length === 0) return;
|
|
15
|
+
const fields = {};
|
|
16
|
+
|
|
17
|
+
for (const key of Object.keys(params)) {
|
|
18
|
+
const field = params[key];
|
|
19
|
+
fields[key] = await (0, _getField.default)(field);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return fields;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _serializeSchema = _interopRequireDefault(require("./serializeSchema"));
|
|
6
|
+
|
|
7
|
+
it('should create a JSON of the schema', async () => {
|
|
8
|
+
const schema = {
|
|
9
|
+
name: {
|
|
10
|
+
type: String
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const result = await (0, _serializeSchema.default)(schema);
|
|
14
|
+
expect(result).toEqual({
|
|
15
|
+
name: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
__graphQLType: 'String'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('should pass field options', async () => {
|
|
22
|
+
const schema = {
|
|
23
|
+
name: {
|
|
24
|
+
type: [String],
|
|
25
|
+
a: '1234'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const result = await (0, _serializeSchema.default)(schema);
|
|
29
|
+
expect(result.name.a).toEqual(schema.name.a);
|
|
30
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = _default;
|
|
9
|
+
|
|
10
|
+
var _app = require("@orion-js/app");
|
|
11
|
+
|
|
12
|
+
var _apolloServerMicro = require("apollo-server-micro");
|
|
13
|
+
|
|
14
|
+
var _startGraphiQL = _interopRequireDefault(require("./startGraphiQL"));
|
|
15
|
+
|
|
16
|
+
var _getApolloOptions = _interopRequireDefault(require("./getApolloOptions"));
|
|
17
|
+
|
|
18
|
+
var _startWebsocket = _interopRequireDefault(require("./startWebsocket"));
|
|
19
|
+
|
|
20
|
+
var _micro = _interopRequireDefault(require("micro"));
|
|
21
|
+
|
|
22
|
+
var _apolloServerCore = require("apollo-server-core");
|
|
23
|
+
|
|
24
|
+
global.globalMicro = _micro.default;
|
|
25
|
+
|
|
26
|
+
async function _default(options) {
|
|
27
|
+
const apolloOptions = await (0, _getApolloOptions.default)(options);
|
|
28
|
+
(0, _startGraphiQL.default)(apolloOptions, options);
|
|
29
|
+
|
|
30
|
+
if (options.subscriptions) {
|
|
31
|
+
(0, _startWebsocket.default)(apolloOptions, options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const apolloServer = new _apolloServerMicro.ApolloServer(apolloOptions);
|
|
35
|
+
const handler = apolloServer.createHandler(); // highlight-line
|
|
36
|
+
|
|
37
|
+
(0, _app.route)('/graphql', async function (params) {
|
|
38
|
+
const {
|
|
39
|
+
request,
|
|
40
|
+
response,
|
|
41
|
+
viewer,
|
|
42
|
+
getBodyJSON
|
|
43
|
+
} = params;
|
|
44
|
+
|
|
45
|
+
if (options.executeGraphQLCache) {
|
|
46
|
+
try {
|
|
47
|
+
// this returns the original not-cached answer
|
|
48
|
+
const fallback = async () => {
|
|
49
|
+
const data = await getBodyJSON();
|
|
50
|
+
const gqlResponse = await (0, _apolloServerCore.runHttpQuery)([request, response], {
|
|
51
|
+
method: request.method,
|
|
52
|
+
options: { ...apolloOptions,
|
|
53
|
+
context: viewer
|
|
54
|
+
},
|
|
55
|
+
query: data
|
|
56
|
+
});
|
|
57
|
+
return gqlResponse.graphqlResponse;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const result = await options.executeGraphQLCache(params, fallback);
|
|
61
|
+
|
|
62
|
+
if (result) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.log('Error executing GraphQL cache:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
request._orionjsViewer = viewer;
|
|
71
|
+
handler(request, response);
|
|
72
|
+
});
|
|
73
|
+
}
|