@envelop/apollo-federation 2.4.0-alpha-e9434aa.0 → 2.4.0-alpha-05dbec7.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/esm/index.js +10 -14
- package/esm/newCachePolicy.js +4 -8
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const newCachePolicy_js_1 = require("./newCachePolicy.js");
|
|
7
|
-
const useApolloFederation = (options) => {
|
|
8
|
-
const { gateway, cache = new apollo_server_caching_1.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = (0, newCachePolicy_js_1.newCachePolicy)(), } = options;
|
|
1
|
+
import { getOperationAST, print, printSchema, Source } from 'graphql';
|
|
2
|
+
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
3
|
+
import { newCachePolicy } from './newCachePolicy.js';
|
|
4
|
+
export const useApolloFederation = (options) => {
|
|
5
|
+
const { gateway, cache = new InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
|
|
9
6
|
let schemaHash;
|
|
10
7
|
const documentSourceMap = new WeakMap();
|
|
11
8
|
return {
|
|
@@ -17,13 +14,13 @@ const useApolloFederation = (options) => {
|
|
|
17
14
|
logger.warn(`ApolloGateway doesn't have the schema loaded. Please make sure ApolloGateway is loaded with .load() method. Otherwise this plugin might not work consistently, especially if you are using ApolloServer.`);
|
|
18
15
|
gateway.load();
|
|
19
16
|
}
|
|
20
|
-
gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl =
|
|
17
|
+
gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = printSchema(apiSchema) }) => {
|
|
21
18
|
setSchema(apiSchema);
|
|
22
|
-
schemaHash = (coreSupergraphSdl ||
|
|
19
|
+
schemaHash = (coreSupergraphSdl || printSchema(apiSchema));
|
|
23
20
|
});
|
|
24
21
|
},
|
|
25
22
|
onParse({ params: { source } }) {
|
|
26
|
-
const key = source instanceof
|
|
23
|
+
const key = source instanceof Source ? source.body : source;
|
|
27
24
|
return ({ result }) => {
|
|
28
25
|
if (!result || result instanceof Error)
|
|
29
26
|
return;
|
|
@@ -34,10 +31,10 @@ const useApolloFederation = (options) => {
|
|
|
34
31
|
var _a;
|
|
35
32
|
let documentStr = documentSourceMap.get(args.document);
|
|
36
33
|
if (documentStr == null) {
|
|
37
|
-
documentStr =
|
|
34
|
+
documentStr = print(args.document);
|
|
38
35
|
documentSourceMap.set(args.document, documentStr);
|
|
39
36
|
}
|
|
40
|
-
const operation =
|
|
37
|
+
const operation = getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
|
|
41
38
|
if (!operation) {
|
|
42
39
|
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
|
43
40
|
}
|
|
@@ -66,4 +63,3 @@ const useApolloFederation = (options) => {
|
|
|
66
63
|
},
|
|
67
64
|
};
|
|
68
65
|
};
|
|
69
|
-
exports.useApolloFederation = useApolloFederation;
|
package/esm/newCachePolicy.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newCachePolicy = void 0;
|
|
4
1
|
// Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
|
|
5
|
-
|
|
6
|
-
function newCachePolicy() {
|
|
2
|
+
import { CacheScope } from 'apollo-server-types';
|
|
3
|
+
export function newCachePolicy() {
|
|
7
4
|
return {
|
|
8
5
|
maxAge: undefined,
|
|
9
6
|
scope: undefined,
|
|
@@ -11,7 +8,7 @@ function newCachePolicy() {
|
|
|
11
8
|
if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
|
|
12
9
|
this.maxAge = hint.maxAge;
|
|
13
10
|
}
|
|
14
|
-
if (hint.scope !== undefined && this.scope !==
|
|
11
|
+
if (hint.scope !== undefined && this.scope !== CacheScope.Private) {
|
|
15
12
|
this.scope = hint.scope;
|
|
16
13
|
}
|
|
17
14
|
},
|
|
@@ -28,8 +25,7 @@ function newCachePolicy() {
|
|
|
28
25
|
if (this.maxAge === undefined || this.maxAge === 0) {
|
|
29
26
|
return null;
|
|
30
27
|
}
|
|
31
|
-
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a :
|
|
28
|
+
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : CacheScope.Public };
|
|
32
29
|
},
|
|
33
30
|
};
|
|
34
31
|
}
|
|
35
|
-
exports.newCachePolicy = newCachePolicy;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-federation",
|
|
3
|
-
"version": "2.4.0-alpha-
|
|
3
|
+
"version": "2.4.0-alpha-05dbec7.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-05dbec7.0",
|
|
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
|
},
|