@envelop/apollo-federation 3.0.6 → 3.0.7-alpha-20230220175948-cdba6d9f
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/cjs/index.js +2 -14
- package/esm/index.js +3 -15
- package/package.json +2 -2
package/cjs/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useApolloFederation = void 0;
|
|
4
|
+
const core_1 = require("@envelop/core");
|
|
4
5
|
const graphql_1 = require("graphql");
|
|
5
6
|
const apollo_server_caching_1 = require("apollo-server-caching");
|
|
6
7
|
const new_cache_policy_js_1 = require("./new-cache-policy.js");
|
|
7
8
|
const useApolloFederation = (options) => {
|
|
8
9
|
const { gateway, cache = new apollo_server_caching_1.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = (0, new_cache_policy_js_1.newCachePolicy)(), } = options;
|
|
9
10
|
let schemaHash;
|
|
10
|
-
const documentSourceMap = new WeakMap();
|
|
11
11
|
return {
|
|
12
12
|
onPluginInit({ setSchema }) {
|
|
13
13
|
if (gateway.schema) {
|
|
@@ -22,20 +22,8 @@ const useApolloFederation = (options) => {
|
|
|
22
22
|
schemaHash = (coreSupergraphSdl || (0, graphql_1.printSchema)(apiSchema));
|
|
23
23
|
});
|
|
24
24
|
},
|
|
25
|
-
onParse({ params: { source } }) {
|
|
26
|
-
const key = source instanceof graphql_1.Source ? source.body : source;
|
|
27
|
-
return ({ result }) => {
|
|
28
|
-
if (!result || result instanceof Error)
|
|
29
|
-
return;
|
|
30
|
-
documentSourceMap.set(result, key);
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
25
|
onExecute({ args, setExecuteFn }) {
|
|
34
|
-
|
|
35
|
-
if (documentStr == null) {
|
|
36
|
-
documentStr = (0, graphql_1.print)(args.document);
|
|
37
|
-
documentSourceMap.set(args.document, documentStr);
|
|
38
|
-
}
|
|
26
|
+
const documentStr = (0, core_1.getDocumentString)(args.document, graphql_1.print);
|
|
39
27
|
const operation = (0, graphql_1.getOperationAST)(args.document, args.operationName ?? undefined);
|
|
40
28
|
if (!operation) {
|
|
41
29
|
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDocumentString } from '@envelop/core';
|
|
2
|
+
import { getOperationAST, print, printSchema } from 'graphql';
|
|
2
3
|
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
3
4
|
import { newCachePolicy } from './new-cache-policy.js';
|
|
4
5
|
export const useApolloFederation = (options) => {
|
|
5
6
|
const { gateway, cache = new InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
|
|
6
7
|
let schemaHash;
|
|
7
|
-
const documentSourceMap = new WeakMap();
|
|
8
8
|
return {
|
|
9
9
|
onPluginInit({ setSchema }) {
|
|
10
10
|
if (gateway.schema) {
|
|
@@ -19,20 +19,8 @@ export const useApolloFederation = (options) => {
|
|
|
19
19
|
schemaHash = (coreSupergraphSdl || printSchema(apiSchema));
|
|
20
20
|
});
|
|
21
21
|
},
|
|
22
|
-
onParse({ params: { source } }) {
|
|
23
|
-
const key = source instanceof Source ? source.body : source;
|
|
24
|
-
return ({ result }) => {
|
|
25
|
-
if (!result || result instanceof Error)
|
|
26
|
-
return;
|
|
27
|
-
documentSourceMap.set(result, key);
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
22
|
onExecute({ args, setExecuteFn }) {
|
|
31
|
-
|
|
32
|
-
if (documentStr == null) {
|
|
33
|
-
documentStr = print(args.document);
|
|
34
|
-
documentSourceMap.set(args.document, documentStr);
|
|
35
|
-
}
|
|
23
|
+
const documentStr = getDocumentString(args.document, print);
|
|
36
24
|
const operation = getOperationAST(args.document, args.operationName ?? undefined);
|
|
37
25
|
if (!operation) {
|
|
38
26
|
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-federation",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7-alpha-20230220175948-cdba6d9f",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "3.0.7-alpha-20230220175948-cdba6d9f",
|
|
7
7
|
"@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|