@envelop/apollo-federation 2.4.0-alpha-aca44e1.0 → 2.4.0-alpha-ea8de8a.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/index.d.ts +4 -4
- package/index.js +6 -12
- package/index.mjs +6 -12
- package/newCachePolicy.d.ts +1 -1
- package/package.json +7 -3
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Plugin } from '@envelop/core';
|
|
2
|
+
import { ApolloGateway } from '@apollo/gateway';
|
|
3
|
+
import { KeyValueCache } from 'apollo-server-caching';
|
|
4
|
+
import { CachePolicy, GraphQLRequestMetrics, Logger } from 'apollo-server-types';
|
|
5
5
|
export interface ApolloFederationPluginConfig {
|
|
6
6
|
gateway: ApolloGateway;
|
|
7
7
|
metrics?: GraphQLRequestMetrics;
|
package/index.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const graphql = require('graphql');
|
|
6
|
-
const
|
|
6
|
+
const apolloServerCaching = require('apollo-server-caching');
|
|
7
|
+
const apolloServerTypes = require('apollo-server-types');
|
|
7
8
|
|
|
9
|
+
// Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
|
|
8
10
|
function newCachePolicy() {
|
|
9
11
|
return {
|
|
10
12
|
maxAge: undefined,
|
|
@@ -13,7 +15,7 @@ function newCachePolicy() {
|
|
|
13
15
|
if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
|
|
14
16
|
this.maxAge = hint.maxAge;
|
|
15
17
|
}
|
|
16
|
-
if (hint.scope !== undefined && this.scope !==
|
|
18
|
+
if (hint.scope !== undefined && this.scope !== apolloServerTypes.CacheScope.Private) {
|
|
17
19
|
this.scope = hint.scope;
|
|
18
20
|
}
|
|
19
21
|
},
|
|
@@ -30,21 +32,13 @@ function newCachePolicy() {
|
|
|
30
32
|
if (this.maxAge === undefined || this.maxAge === 0) {
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
33
|
-
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a :
|
|
35
|
+
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : apolloServerTypes.CacheScope.Public };
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function getDefaultCache() {
|
|
39
|
-
const lruCache = core.getInMemoryLRUCache();
|
|
40
|
-
return {
|
|
41
|
-
get: async (key) => lruCache.get(key),
|
|
42
|
-
set: async (key, value) => lruCache.set(key, value),
|
|
43
|
-
delete: async (key) => lruCache.delete(key),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
40
|
const useApolloFederation = (options) => {
|
|
47
|
-
const { gateway, cache =
|
|
41
|
+
const { gateway, cache = new apolloServerCaching.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
|
|
48
42
|
let schemaHash;
|
|
49
43
|
const documentSourceMap = new WeakMap();
|
|
50
44
|
return {
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { printSchema, Source, print, getOperationAST } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
3
|
+
import { CacheScope } from 'apollo-server-types';
|
|
3
4
|
|
|
5
|
+
// Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
|
|
4
6
|
function newCachePolicy() {
|
|
5
7
|
return {
|
|
6
8
|
maxAge: undefined,
|
|
@@ -9,7 +11,7 @@ function newCachePolicy() {
|
|
|
9
11
|
if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
|
|
10
12
|
this.maxAge = hint.maxAge;
|
|
11
13
|
}
|
|
12
|
-
if (hint.scope !== undefined && this.scope !==
|
|
14
|
+
if (hint.scope !== undefined && this.scope !== CacheScope.Private) {
|
|
13
15
|
this.scope = hint.scope;
|
|
14
16
|
}
|
|
15
17
|
},
|
|
@@ -26,21 +28,13 @@ function newCachePolicy() {
|
|
|
26
28
|
if (this.maxAge === undefined || this.maxAge === 0) {
|
|
27
29
|
return null;
|
|
28
30
|
}
|
|
29
|
-
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a :
|
|
31
|
+
return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : CacheScope.Public };
|
|
30
32
|
},
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
function getDefaultCache() {
|
|
35
|
-
const lruCache = getInMemoryLRUCache();
|
|
36
|
-
return {
|
|
37
|
-
get: async (key) => lruCache.get(key),
|
|
38
|
-
set: async (key, value) => lruCache.set(key, value),
|
|
39
|
-
delete: async (key) => lruCache.delete(key),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
36
|
const useApolloFederation = (options) => {
|
|
43
|
-
const { gateway, cache =
|
|
37
|
+
const { gateway, cache = new InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
|
|
44
38
|
let schemaHash;
|
|
45
39
|
const documentSourceMap = new WeakMap();
|
|
46
40
|
return {
|
package/newCachePolicy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CachePolicy } from 'apollo-server-types';
|
|
2
2
|
export declare function newCachePolicy(): CachePolicy;
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-federation",
|
|
3
|
-
"version": "2.4.0-alpha-
|
|
3
|
+
"version": "2.4.0-alpha-ea8de8a.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0",
|
|
7
|
-
"@envelop/core": "2.
|
|
6
|
+
"@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0 || ^2.0.0",
|
|
7
|
+
"@envelop/core": "^2.3.1",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"apollo-server-caching": "^3.1.0",
|
|
12
|
+
"apollo-server-types": "^3.2.0"
|
|
13
|
+
},
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
12
16
|
"url": "https://github.com/dotansimha/envelop.git",
|