@envelop/apollo-federation 0.2.0 → 0.2.3-alpha-1e6c37b.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 +1 -1
- package/index.js +24 -19
- package/index.mjs +25 -20
- package/package.json +4 -2
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from '@envelop/
|
|
1
|
+
import { Plugin } from '@envelop/core';
|
|
2
2
|
import { ApolloGateway } from '@apollo/gateway';
|
|
3
3
|
import { KeyValueCache } from 'apollo-server-caching';
|
|
4
4
|
import { CachePolicy, GraphQLRequestMetrics, Logger } from 'apollo-server-types';
|
package/index.js
CHANGED
|
@@ -43,14 +43,17 @@ const useApolloFederation = (options) => {
|
|
|
43
43
|
const documentSourceMap = new WeakMap();
|
|
44
44
|
return {
|
|
45
45
|
onPluginInit({ setSchema }) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
46
|
+
if (gateway.schema) {
|
|
47
|
+
setSchema(gateway.schema);
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
else {
|
|
50
|
+
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.`);
|
|
51
|
+
gateway.load();
|
|
52
|
+
}
|
|
53
|
+
gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = graphql.printSchema(apiSchema) }) => {
|
|
54
|
+
setSchema(apiSchema);
|
|
55
|
+
schemaHash = (coreSupergraphSdl || graphql.printSchema(apiSchema));
|
|
56
|
+
});
|
|
54
57
|
},
|
|
55
58
|
onParse({ params: { source } }) {
|
|
56
59
|
const key = source instanceof graphql.Source ? source.body : source;
|
|
@@ -61,25 +64,27 @@ const useApolloFederation = (options) => {
|
|
|
61
64
|
};
|
|
62
65
|
},
|
|
63
66
|
onExecute({ args, setExecuteFn }) {
|
|
67
|
+
var _a;
|
|
68
|
+
let documentStr = documentSourceMap.get(args.document);
|
|
69
|
+
if (documentStr == null) {
|
|
70
|
+
documentStr = graphql.print(args.document);
|
|
71
|
+
documentSourceMap.set(args.document, documentStr);
|
|
72
|
+
}
|
|
73
|
+
const operation = graphql.getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
|
|
74
|
+
if (!operation) {
|
|
75
|
+
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
|
76
|
+
}
|
|
64
77
|
setExecuteFn(function federationExecutor() {
|
|
65
|
-
var _a, _b, _c
|
|
66
|
-
const documentStr = documentSourceMap.get(args.document);
|
|
67
|
-
if (!documentStr) {
|
|
68
|
-
throw new Error(`Parse error!`);
|
|
69
|
-
}
|
|
70
|
-
const operation = graphql.getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
|
|
71
|
-
if (!operation) {
|
|
72
|
-
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
|
73
|
-
}
|
|
78
|
+
var _a, _b, _c;
|
|
74
79
|
return gateway.executor({
|
|
75
80
|
document: args.document,
|
|
76
81
|
request: {
|
|
77
82
|
query: documentStr,
|
|
78
|
-
operationName: (
|
|
79
|
-
variables: (
|
|
83
|
+
operationName: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
84
|
+
variables: (_b = args.variableValues) !== null && _b !== void 0 ? _b : undefined,
|
|
80
85
|
},
|
|
81
86
|
overallCachePolicy,
|
|
82
|
-
operationName: (
|
|
87
|
+
operationName: (_c = args.operationName) !== null && _c !== void 0 ? _c : null,
|
|
83
88
|
cache,
|
|
84
89
|
context: args.contextValue,
|
|
85
90
|
queryHash: documentStr,
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { printSchema, Source, getOperationAST } from 'graphql';
|
|
1
|
+
import { printSchema, Source, print, getOperationAST } from 'graphql';
|
|
2
2
|
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
3
3
|
import { CacheScope } from 'apollo-server-types';
|
|
4
4
|
|
|
@@ -39,14 +39,17 @@ const useApolloFederation = (options) => {
|
|
|
39
39
|
const documentSourceMap = new WeakMap();
|
|
40
40
|
return {
|
|
41
41
|
onPluginInit({ setSchema }) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
42
|
+
if (gateway.schema) {
|
|
43
|
+
setSchema(gateway.schema);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
else {
|
|
46
|
+
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.`);
|
|
47
|
+
gateway.load();
|
|
48
|
+
}
|
|
49
|
+
gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = printSchema(apiSchema) }) => {
|
|
50
|
+
setSchema(apiSchema);
|
|
51
|
+
schemaHash = (coreSupergraphSdl || printSchema(apiSchema));
|
|
52
|
+
});
|
|
50
53
|
},
|
|
51
54
|
onParse({ params: { source } }) {
|
|
52
55
|
const key = source instanceof Source ? source.body : source;
|
|
@@ -57,25 +60,27 @@ const useApolloFederation = (options) => {
|
|
|
57
60
|
};
|
|
58
61
|
},
|
|
59
62
|
onExecute({ args, setExecuteFn }) {
|
|
63
|
+
var _a;
|
|
64
|
+
let documentStr = documentSourceMap.get(args.document);
|
|
65
|
+
if (documentStr == null) {
|
|
66
|
+
documentStr = print(args.document);
|
|
67
|
+
documentSourceMap.set(args.document, documentStr);
|
|
68
|
+
}
|
|
69
|
+
const operation = getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
|
|
70
|
+
if (!operation) {
|
|
71
|
+
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
|
72
|
+
}
|
|
60
73
|
setExecuteFn(function federationExecutor() {
|
|
61
|
-
var _a, _b, _c
|
|
62
|
-
const documentStr = documentSourceMap.get(args.document);
|
|
63
|
-
if (!documentStr) {
|
|
64
|
-
throw new Error(`Parse error!`);
|
|
65
|
-
}
|
|
66
|
-
const operation = getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
|
|
67
|
-
if (!operation) {
|
|
68
|
-
throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
|
|
69
|
-
}
|
|
74
|
+
var _a, _b, _c;
|
|
70
75
|
return gateway.executor({
|
|
71
76
|
document: args.document,
|
|
72
77
|
request: {
|
|
73
78
|
query: documentStr,
|
|
74
|
-
operationName: (
|
|
75
|
-
variables: (
|
|
79
|
+
operationName: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
80
|
+
variables: (_b = args.variableValues) !== null && _b !== void 0 ? _b : undefined,
|
|
76
81
|
},
|
|
77
82
|
overallCachePolicy,
|
|
78
|
-
operationName: (
|
|
83
|
+
operationName: (_c = args.operationName) !== null && _c !== void 0 ? _c : null,
|
|
79
84
|
cache,
|
|
80
85
|
context: args.contextValue,
|
|
81
86
|
queryHash: documentStr,
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-federation",
|
|
3
|
-
"version": "0.2.0",
|
|
3
|
+
"version": "0.2.3-alpha-1e6c37b.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0",
|
|
7
|
+
"@envelop/core": "1.6.6-alpha-1e6c37b.0",
|
|
7
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
9
|
},
|
|
9
10
|
"dependencies": {
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"./*": {
|
|
32
33
|
"require": "./*.js",
|
|
33
34
|
"import": "./*.mjs"
|
|
34
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
35
37
|
}
|
|
36
38
|
}
|