@graphql-tools/apollo-engine-loader 7.3.1 → 7.3.3
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 +1 -1
- package/package.json +2 -2
- package/cjs/index.js +0 -85
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseGraphQLSDL, AggregateError } from '@graphql-tools/utils';
|
|
2
|
-
import { fetch } from '
|
|
2
|
+
import { fetch } from '@whatwg-node/fetch';
|
|
3
3
|
import syncFetch from 'sync-fetch';
|
|
4
4
|
const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/graphql';
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/apollo-engine-loader",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.3",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/utils": "8.8.0",
|
|
11
|
-
"
|
|
11
|
+
"@whatwg-node/fetch": "^0.0.2",
|
|
12
12
|
"sync-fetch": "0.4.1",
|
|
13
13
|
"tslib": "^2.4.0"
|
|
14
14
|
},
|
package/cjs/index.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SCHEMA_QUERY = exports.ApolloEngineLoader = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
-
const cross_undici_fetch_1 = require("cross-undici-fetch");
|
|
7
|
-
const sync_fetch_1 = tslib_1.__importDefault(require("sync-fetch"));
|
|
8
|
-
const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/graphql';
|
|
9
|
-
/**
|
|
10
|
-
* This loader loads a schema from Apollo Engine
|
|
11
|
-
*/
|
|
12
|
-
class ApolloEngineLoader {
|
|
13
|
-
getFetchArgs(options) {
|
|
14
|
-
return [
|
|
15
|
-
options.engine.endpoint || DEFAULT_APOLLO_ENDPOINT,
|
|
16
|
-
{
|
|
17
|
-
method: 'POST',
|
|
18
|
-
headers: {
|
|
19
|
-
'x-api-key': options.engine.apiKey,
|
|
20
|
-
'apollo-client-name': 'Apollo Language Server',
|
|
21
|
-
'apollo-client-reference-id': '146d29c0-912c-46d3-b686-920e52586be6',
|
|
22
|
-
'apollo-client-version': '2.6.8',
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
Accept: 'application/json',
|
|
25
|
-
...options.headers,
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({
|
|
28
|
-
query: exports.SCHEMA_QUERY,
|
|
29
|
-
variables: {
|
|
30
|
-
id: options.graph,
|
|
31
|
-
tag: options.variant,
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
async canLoad(ptr) {
|
|
38
|
-
return this.canLoadSync(ptr);
|
|
39
|
-
}
|
|
40
|
-
canLoadSync(ptr) {
|
|
41
|
-
return typeof ptr === 'string' && ptr === 'apollo-engine';
|
|
42
|
-
}
|
|
43
|
-
async load(pointer, options) {
|
|
44
|
-
if (!(await this.canLoad(pointer))) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
const fetchArgs = this.getFetchArgs(options);
|
|
48
|
-
const response = await (0, cross_undici_fetch_1.fetch)(...fetchArgs);
|
|
49
|
-
const { data, errors } = await response.json();
|
|
50
|
-
if (errors) {
|
|
51
|
-
throw new utils_1.AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
|
|
52
|
-
}
|
|
53
|
-
const source = (0, utils_1.parseGraphQLSDL)(pointer, data.service.schema.document, options);
|
|
54
|
-
return [source];
|
|
55
|
-
}
|
|
56
|
-
loadSync(pointer, options) {
|
|
57
|
-
if (!this.canLoadSync(pointer)) {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
const fetchArgs = this.getFetchArgs(options);
|
|
61
|
-
const response = (0, sync_fetch_1.default)(...fetchArgs);
|
|
62
|
-
const { data, errors } = response.json();
|
|
63
|
-
if (errors) {
|
|
64
|
-
throw new utils_1.AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
|
|
65
|
-
}
|
|
66
|
-
const source = (0, utils_1.parseGraphQLSDL)(pointer, data.service.schema.document, options);
|
|
67
|
-
return [source];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ApolloEngineLoader = ApolloEngineLoader;
|
|
71
|
-
/**
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
exports.SCHEMA_QUERY = `
|
|
75
|
-
query GetSchemaByTag($tag: String!, $id: ID!) {
|
|
76
|
-
service(id: $id) {
|
|
77
|
-
... on Service {
|
|
78
|
-
__typename
|
|
79
|
-
schema(tag: $tag) {
|
|
80
|
-
document
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
`;
|