@depup/graphql-codegen__plugin-helpers 6.2.0-depup.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/README.md +33 -0
- package/changes.json +18 -0
- package/cjs/federation.js +436 -0
- package/cjs/getCachedDocumentNodeFromSchema.js +5 -0
- package/cjs/helpers.js +178 -0
- package/cjs/index.js +13 -0
- package/cjs/oldVisit.js +19 -0
- package/cjs/package.json +1 -0
- package/cjs/profiler.js +49 -0
- package/cjs/resolve-external-module-and-fn.js +31 -0
- package/cjs/types.js +6 -0
- package/cjs/utils.js +35 -0
- package/esm/federation.js +430 -0
- package/esm/getCachedDocumentNodeFromSchema.js +2 -0
- package/esm/helpers.js +168 -0
- package/esm/index.js +8 -0
- package/esm/oldVisit.js +16 -0
- package/esm/profiler.js +45 -0
- package/esm/resolve-external-module-and-fn.js +27 -0
- package/esm/types.js +3 -0
- package/esm/utils.js +29 -0
- package/package.json +76 -0
- package/typings/federation.d.cts +102 -0
- package/typings/federation.d.ts +102 -0
- package/typings/getCachedDocumentNodeFromSchema.d.cts +2 -0
- package/typings/getCachedDocumentNodeFromSchema.d.ts +2 -0
- package/typings/helpers.d.cts +13 -0
- package/typings/helpers.d.ts +13 -0
- package/typings/index.d.cts +9 -0
- package/typings/index.d.ts +9 -0
- package/typings/oldVisit.d.cts +9 -0
- package/typings/oldVisit.d.ts +9 -0
- package/typings/profiler.d.cts +28 -0
- package/typings/profiler.d.ts +28 -0
- package/typings/resolve-external-module-and-fn.d.cts +1 -0
- package/typings/resolve-external-module-and-fn.d.ts +1 -0
- package/typings/types.d.cts +635 -0
- package/typings/types.d.ts +635 -0
- package/typings/utils.d.cts +6 -0
- package/typings/utils.d.ts +6 -0
package/esm/helpers.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { isListType, isNonNullType, isObjectType, Kind, visit, } from 'graphql';
|
|
2
|
+
import { getBaseType } from './utils.js';
|
|
3
|
+
export function isOutputConfigArray(type) {
|
|
4
|
+
return Array.isArray(type);
|
|
5
|
+
}
|
|
6
|
+
export function isConfiguredOutput(type) {
|
|
7
|
+
return typeof type === 'object';
|
|
8
|
+
}
|
|
9
|
+
export function normalizeOutputParam(config) {
|
|
10
|
+
// In case of direct array with a list of plugins
|
|
11
|
+
if (isOutputConfigArray(config)) {
|
|
12
|
+
return {
|
|
13
|
+
documents: [],
|
|
14
|
+
schema: [],
|
|
15
|
+
plugins: isConfiguredOutput(config) ? config.plugins : config,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (isConfiguredOutput(config)) {
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Invalid "generates" config!`);
|
|
22
|
+
}
|
|
23
|
+
export function normalizeInstanceOrArray(type) {
|
|
24
|
+
if (Array.isArray(type)) {
|
|
25
|
+
return type;
|
|
26
|
+
}
|
|
27
|
+
if (!type) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
return [type];
|
|
31
|
+
}
|
|
32
|
+
export function normalizeConfig(config) {
|
|
33
|
+
if (typeof config === 'string') {
|
|
34
|
+
return [{ [config]: {} }];
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(config)) {
|
|
37
|
+
return config.map(plugin => (typeof plugin === 'string' ? { [plugin]: {} } : plugin));
|
|
38
|
+
}
|
|
39
|
+
if (typeof config === 'object') {
|
|
40
|
+
return Object.keys(config).reduce((prev, pluginName) => [...prev, { [pluginName]: config[pluginName] }], []);
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
export function hasNullableTypeRecursively(type) {
|
|
45
|
+
if (!isNonNullType(type)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (isListType(type) || isNonNullType(type)) {
|
|
49
|
+
return hasNullableTypeRecursively(type.ofType);
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export function isUsingTypes(document, externalFragments, schema) {
|
|
54
|
+
let foundFields = 0;
|
|
55
|
+
const typesStack = [];
|
|
56
|
+
visit(document, {
|
|
57
|
+
SelectionSet: {
|
|
58
|
+
enter(node, key, parent, anscestors) {
|
|
59
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
60
|
+
if (insideIgnoredFragment) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const selections = node.selections || [];
|
|
64
|
+
if (schema && selections.length > 0) {
|
|
65
|
+
const nextTypeName = (() => {
|
|
66
|
+
if (parent.kind === Kind.FRAGMENT_DEFINITION) {
|
|
67
|
+
return parent.typeCondition.name.value;
|
|
68
|
+
}
|
|
69
|
+
if (parent.kind === Kind.FIELD) {
|
|
70
|
+
const lastType = typesStack[typesStack.length - 1];
|
|
71
|
+
if (!lastType) {
|
|
72
|
+
throw new Error(`Unable to find parent type! Please make sure you operation passes validation`);
|
|
73
|
+
}
|
|
74
|
+
const field = lastType.getFields()[parent.name.value];
|
|
75
|
+
if (!field) {
|
|
76
|
+
throw new Error(`Unable to find field "${parent.name.value}" on type "${lastType}"!`);
|
|
77
|
+
}
|
|
78
|
+
return getBaseType(field.type).name;
|
|
79
|
+
}
|
|
80
|
+
if (parent.kind === Kind.OPERATION_DEFINITION) {
|
|
81
|
+
if (parent.operation === 'query') {
|
|
82
|
+
return schema.getQueryType().name;
|
|
83
|
+
}
|
|
84
|
+
if (parent.operation === 'mutation') {
|
|
85
|
+
return schema.getMutationType().name;
|
|
86
|
+
}
|
|
87
|
+
if (parent.operation === 'subscription') {
|
|
88
|
+
return schema.getSubscriptionType().name;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (parent.kind === Kind.INLINE_FRAGMENT) {
|
|
92
|
+
if (parent.typeCondition) {
|
|
93
|
+
return parent.typeCondition.name.value;
|
|
94
|
+
}
|
|
95
|
+
return typesStack[typesStack.length - 1].name;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
})();
|
|
99
|
+
typesStack.push(schema.getType(nextTypeName));
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
leave(node) {
|
|
103
|
+
const selections = node.selections || [];
|
|
104
|
+
if (schema && selections.length > 0) {
|
|
105
|
+
typesStack.pop();
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
Field: {
|
|
110
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
111
|
+
if (node.name.value.startsWith('__')) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
115
|
+
if (insideIgnoredFragment) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const selections = node.selectionSet ? node.selectionSet.selections || [] : [];
|
|
119
|
+
const relevantFragmentSpreads = selections.filter(s => s.kind === Kind.FRAGMENT_SPREAD && !externalFragments.includes(s.name.value));
|
|
120
|
+
if (selections.length === 0 || relevantFragmentSpreads.length > 0) {
|
|
121
|
+
foundFields++;
|
|
122
|
+
}
|
|
123
|
+
if (schema) {
|
|
124
|
+
const lastType = typesStack[typesStack.length - 1];
|
|
125
|
+
if (lastType && isObjectType(lastType)) {
|
|
126
|
+
const field = lastType.getFields()[node.name.value];
|
|
127
|
+
if (!field) {
|
|
128
|
+
throw new Error(`Unable to find field "${node.name.value}" on type "${lastType}"!`);
|
|
129
|
+
}
|
|
130
|
+
const currentType = field.type;
|
|
131
|
+
// To handle `Maybe` usage
|
|
132
|
+
if (hasNullableTypeRecursively(currentType)) {
|
|
133
|
+
foundFields++;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
VariableDefinition: {
|
|
140
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
141
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
142
|
+
if (insideIgnoredFragment) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
foundFields++;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
InputValueDefinition: {
|
|
149
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
150
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
151
|
+
if (insideIgnoredFragment) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
foundFields++;
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
return foundFields > 0;
|
|
159
|
+
}
|
|
160
|
+
export function normalizeImportExtension({ emitLegacyCommonJSImports, importExtension, }) {
|
|
161
|
+
if (importExtension !== undefined) {
|
|
162
|
+
return importExtension;
|
|
163
|
+
}
|
|
164
|
+
if (emitLegacyCommonJSImports === undefined || emitLegacyCommonJSImports === true) {
|
|
165
|
+
return '';
|
|
166
|
+
}
|
|
167
|
+
return '.js';
|
|
168
|
+
}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './federation.js';
|
|
2
|
+
export * from './getCachedDocumentNodeFromSchema.js';
|
|
3
|
+
export * from './helpers.js';
|
|
4
|
+
export * from './oldVisit.js';
|
|
5
|
+
export * from './profiler.js';
|
|
6
|
+
export { resolveExternalModuleAndFn } from './resolve-external-module-and-fn.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './utils.js';
|
package/esm/oldVisit.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { visit } from 'graphql';
|
|
2
|
+
export function oldVisit(root, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }) {
|
|
3
|
+
if (typeof enterVisitors === 'object') {
|
|
4
|
+
for (const key in enterVisitors) {
|
|
5
|
+
newVisitor[key] ||= {};
|
|
6
|
+
newVisitor[key].enter = enterVisitors[key];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
if (typeof leaveVisitors === 'object') {
|
|
10
|
+
for (const key in leaveVisitors) {
|
|
11
|
+
newVisitor[key] ||= {};
|
|
12
|
+
newVisitor[key].leave = leaveVisitors[key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return visit(root, newVisitor);
|
|
16
|
+
}
|
package/esm/profiler.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function createNoopProfiler() {
|
|
2
|
+
return {
|
|
3
|
+
run(fn) {
|
|
4
|
+
return Promise.resolve().then(() => fn());
|
|
5
|
+
},
|
|
6
|
+
collect() {
|
|
7
|
+
return [];
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function createProfiler() {
|
|
12
|
+
const events = [];
|
|
13
|
+
return {
|
|
14
|
+
collect() {
|
|
15
|
+
return events;
|
|
16
|
+
},
|
|
17
|
+
run(fn, name, cat) {
|
|
18
|
+
let startTime;
|
|
19
|
+
return Promise.resolve()
|
|
20
|
+
.then(() => {
|
|
21
|
+
startTime = process.hrtime();
|
|
22
|
+
})
|
|
23
|
+
.then(() => fn())
|
|
24
|
+
.then(value => {
|
|
25
|
+
const duration = process.hrtime(startTime);
|
|
26
|
+
// Trace Event Format documentation:
|
|
27
|
+
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
|
|
28
|
+
const event = {
|
|
29
|
+
name,
|
|
30
|
+
cat,
|
|
31
|
+
ph: 'X',
|
|
32
|
+
ts: hrtimeToMicroseconds(startTime),
|
|
33
|
+
pid: 1,
|
|
34
|
+
tid: 0,
|
|
35
|
+
dur: hrtimeToMicroseconds(duration),
|
|
36
|
+
};
|
|
37
|
+
events.push(event);
|
|
38
|
+
return value;
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function hrtimeToMicroseconds(hrtime) {
|
|
44
|
+
return (hrtime[0] * 1e9 + hrtime[1]) / 1000;
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { cwd } from 'process';
|
|
3
|
+
import * as changeCaseAll from 'change-case-all';
|
|
4
|
+
export function resolveExternalModuleAndFn(pointer) {
|
|
5
|
+
if (typeof pointer === 'function') {
|
|
6
|
+
return pointer;
|
|
7
|
+
}
|
|
8
|
+
let [moduleName, functionName] = pointer.split('#');
|
|
9
|
+
// Temp workaround until v2
|
|
10
|
+
if (moduleName === 'change-case') {
|
|
11
|
+
moduleName = 'change-case-all';
|
|
12
|
+
}
|
|
13
|
+
let loadedModule;
|
|
14
|
+
if (moduleName === 'change-case-all') {
|
|
15
|
+
loadedModule = changeCaseAll;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// we have to use a path to a filename here (it does not need to exist.)
|
|
19
|
+
// https://github.com/dotansimha/graphql-code-generator/issues/6553
|
|
20
|
+
const cwdRequire = createRequire(cwd() + '/index.js');
|
|
21
|
+
loadedModule = cwdRequire(moduleName);
|
|
22
|
+
if (!(functionName in loadedModule) && typeof loadedModule !== 'function') {
|
|
23
|
+
throw new Error(`${functionName} couldn't be found in module ${moduleName}!`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return loadedModule[functionName] || loadedModule;
|
|
27
|
+
}
|
package/esm/types.js
ADDED
package/esm/utils.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isListType, isNonNullType } from 'graphql';
|
|
2
|
+
export function mergeOutputs(content) {
|
|
3
|
+
const result = { content: '', prepend: [], append: [] };
|
|
4
|
+
if (Array.isArray(content)) {
|
|
5
|
+
for (const item of content) {
|
|
6
|
+
if (typeof item === 'string') {
|
|
7
|
+
result.content += item;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
result.content += item.content;
|
|
11
|
+
result.prepend.push(...(item.prepend || []));
|
|
12
|
+
result.append.push(...(item.append || []));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return [...result.prepend, result.content, ...result.append].join('\n');
|
|
17
|
+
}
|
|
18
|
+
export function isWrapperType(t) {
|
|
19
|
+
return isListType(t) || isNonNullType(t);
|
|
20
|
+
}
|
|
21
|
+
export function getBaseType(type) {
|
|
22
|
+
if (isWrapperType(type)) {
|
|
23
|
+
return getBaseType(type.ofType);
|
|
24
|
+
}
|
|
25
|
+
return type;
|
|
26
|
+
}
|
|
27
|
+
export function removeNonNullWrapper(type) {
|
|
28
|
+
return isNonNullType(type) ? type.ofType : type;
|
|
29
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/graphql-codegen__plugin-helpers",
|
|
3
|
+
"version": "6.2.0-depup.0",
|
|
4
|
+
"description": "[DepUp] GraphQL Code Generator common utils and types",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@graphql-tools/utils": "^11.0.0",
|
|
10
|
+
"change-case-all": "^2.1.0",
|
|
11
|
+
"common-tags": "1.8.2",
|
|
12
|
+
"import-from": "4.0.0",
|
|
13
|
+
"lodash": "^4.17.23",
|
|
14
|
+
"tslib": "^2.8.1"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/dotansimha/graphql-code-generator.git",
|
|
19
|
+
"directory": "packages/utils/plugins-helpers"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=16"
|
|
24
|
+
},
|
|
25
|
+
"main": "cjs/index.js",
|
|
26
|
+
"module": "esm/index.js",
|
|
27
|
+
"typings": "typings/index.d.ts",
|
|
28
|
+
"typescript": {
|
|
29
|
+
"definition": "typings/index.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./typings/index.d.cts",
|
|
36
|
+
"default": "./cjs/index.js"
|
|
37
|
+
},
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"default": {
|
|
43
|
+
"types": "./typings/index.d.ts",
|
|
44
|
+
"default": "./esm/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"depup",
|
|
51
|
+
"dependency-bumped",
|
|
52
|
+
"updated-deps",
|
|
53
|
+
"@graphql-codegen/plugin-helpers"
|
|
54
|
+
],
|
|
55
|
+
"depup": {
|
|
56
|
+
"changes": {
|
|
57
|
+
"change-case-all": {
|
|
58
|
+
"from": "1.0.15",
|
|
59
|
+
"to": "^2.1.0"
|
|
60
|
+
},
|
|
61
|
+
"lodash": {
|
|
62
|
+
"from": "~4.17.0",
|
|
63
|
+
"to": "^4.17.23"
|
|
64
|
+
},
|
|
65
|
+
"tslib": {
|
|
66
|
+
"from": "~2.6.0",
|
|
67
|
+
"to": "^2.8.1"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"depsUpdated": 3,
|
|
71
|
+
"originalPackage": "@graphql-codegen/plugin-helpers",
|
|
72
|
+
"originalVersion": "6.2.0",
|
|
73
|
+
"processedAt": "2026-03-17T16:31:52.141Z",
|
|
74
|
+
"smokeTest": "passed"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { DirectiveNode, FieldDefinitionNode, GraphQLSchema, InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Federation Spec
|
|
4
|
+
*/
|
|
5
|
+
export declare const federationSpec: import("graphql").DocumentNode;
|
|
6
|
+
type ReferenceSelectionSet = Record<string, boolean>;
|
|
7
|
+
interface TypeMeta {
|
|
8
|
+
hasResolveReference: boolean;
|
|
9
|
+
resolvableKeyDirectives: readonly DirectiveNode[];
|
|
10
|
+
/**
|
|
11
|
+
* referenceSelectionSets
|
|
12
|
+
* @description Each element can be `ReferenceSelectionSet[]`.
|
|
13
|
+
* Elements at the root level are combined with `&` and nested elements are combined with `|`.
|
|
14
|
+
*
|
|
15
|
+
* @example:
|
|
16
|
+
* - [[A, B], [C], [D]] -> (A | B) & C & D
|
|
17
|
+
* - [[A, B], [C, D], [E]] -> (A | B) & (C | D) & E
|
|
18
|
+
*/
|
|
19
|
+
referenceSelectionSets: {
|
|
20
|
+
directive: '@key' | '@requires';
|
|
21
|
+
selectionSets: ReferenceSelectionSet[];
|
|
22
|
+
}[];
|
|
23
|
+
referenceSelectionSetsString: string;
|
|
24
|
+
}
|
|
25
|
+
export type FederationMeta = {
|
|
26
|
+
[typeName: string]: TypeMeta;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Adds `__resolveReference` in each ObjectType and InterfaceType involved in Federation.
|
|
30
|
+
* We do this to utilise the existing FieldDefinition logic of the plugin, which includes many logic:
|
|
31
|
+
* - mapper
|
|
32
|
+
* - return type
|
|
33
|
+
* @param schema
|
|
34
|
+
*/
|
|
35
|
+
export declare function addFederationReferencesToSchema(schema: GraphQLSchema): {
|
|
36
|
+
transformedSchema: GraphQLSchema;
|
|
37
|
+
federationMeta: FederationMeta;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Removes Federation Spec from GraphQL Schema
|
|
41
|
+
* @param schema
|
|
42
|
+
* @param config
|
|
43
|
+
*/
|
|
44
|
+
export declare function removeFederation(schema: GraphQLSchema): GraphQLSchema;
|
|
45
|
+
export declare class ApolloFederation {
|
|
46
|
+
private enabled;
|
|
47
|
+
private schema;
|
|
48
|
+
private providesMap;
|
|
49
|
+
/**
|
|
50
|
+
* `fieldsToGenerate` is a meta object where the keys are object type names
|
|
51
|
+
* and the values are fields that must be generated for that object.
|
|
52
|
+
*/
|
|
53
|
+
private fieldsToGenerate;
|
|
54
|
+
protected meta: FederationMeta;
|
|
55
|
+
constructor({ enabled, schema, meta }: {
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
schema: GraphQLSchema;
|
|
58
|
+
meta: FederationMeta;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Excludes types definde by Federation
|
|
62
|
+
* @param typeNames List of type names
|
|
63
|
+
*/
|
|
64
|
+
filterTypeNames(typeNames: string[]): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Excludes `__resolveReference` fields
|
|
67
|
+
* @param fieldNames List of field names
|
|
68
|
+
*/
|
|
69
|
+
filterFieldNames(fieldNames: string[]): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Decides if directive should not be generated
|
|
72
|
+
* @param name directive's name
|
|
73
|
+
*/
|
|
74
|
+
skipDirective(name: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Decides if scalar should not be generated
|
|
77
|
+
* @param name directive's name
|
|
78
|
+
*/
|
|
79
|
+
skipScalar(name: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* findFieldNodesToGenerate
|
|
82
|
+
* @description Function to find field nodes to generate.
|
|
83
|
+
* In a normal setup, all fields must be generated.
|
|
84
|
+
* However, in a Federatin setup, a field should not be generated if:
|
|
85
|
+
* - The field is marked as `@external` and there is no `@provides` path to the field
|
|
86
|
+
* - The parent object is marked as `@external` and there is no `@provides` path to the field
|
|
87
|
+
*/
|
|
88
|
+
findFieldNodesToGenerate({ node, }: {
|
|
89
|
+
node: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode;
|
|
90
|
+
}): readonly FieldDefinitionNode[];
|
|
91
|
+
isResolveReferenceField(fieldNode: FieldDefinitionNode): boolean;
|
|
92
|
+
addFederationTypeGenericIfApplicable({ genericTypes, typeName, federationTypesType, }: {
|
|
93
|
+
genericTypes: string[];
|
|
94
|
+
typeName: string;
|
|
95
|
+
federationTypesType: string;
|
|
96
|
+
}): void;
|
|
97
|
+
getMeta(): FederationMeta;
|
|
98
|
+
private isExternal;
|
|
99
|
+
private hasProvides;
|
|
100
|
+
private createMapOfProvides;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { DirectiveNode, FieldDefinitionNode, GraphQLSchema, InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Federation Spec
|
|
4
|
+
*/
|
|
5
|
+
export declare const federationSpec: import("graphql").DocumentNode;
|
|
6
|
+
type ReferenceSelectionSet = Record<string, boolean>;
|
|
7
|
+
interface TypeMeta {
|
|
8
|
+
hasResolveReference: boolean;
|
|
9
|
+
resolvableKeyDirectives: readonly DirectiveNode[];
|
|
10
|
+
/**
|
|
11
|
+
* referenceSelectionSets
|
|
12
|
+
* @description Each element can be `ReferenceSelectionSet[]`.
|
|
13
|
+
* Elements at the root level are combined with `&` and nested elements are combined with `|`.
|
|
14
|
+
*
|
|
15
|
+
* @example:
|
|
16
|
+
* - [[A, B], [C], [D]] -> (A | B) & C & D
|
|
17
|
+
* - [[A, B], [C, D], [E]] -> (A | B) & (C | D) & E
|
|
18
|
+
*/
|
|
19
|
+
referenceSelectionSets: {
|
|
20
|
+
directive: '@key' | '@requires';
|
|
21
|
+
selectionSets: ReferenceSelectionSet[];
|
|
22
|
+
}[];
|
|
23
|
+
referenceSelectionSetsString: string;
|
|
24
|
+
}
|
|
25
|
+
export type FederationMeta = {
|
|
26
|
+
[typeName: string]: TypeMeta;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Adds `__resolveReference` in each ObjectType and InterfaceType involved in Federation.
|
|
30
|
+
* We do this to utilise the existing FieldDefinition logic of the plugin, which includes many logic:
|
|
31
|
+
* - mapper
|
|
32
|
+
* - return type
|
|
33
|
+
* @param schema
|
|
34
|
+
*/
|
|
35
|
+
export declare function addFederationReferencesToSchema(schema: GraphQLSchema): {
|
|
36
|
+
transformedSchema: GraphQLSchema;
|
|
37
|
+
federationMeta: FederationMeta;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Removes Federation Spec from GraphQL Schema
|
|
41
|
+
* @param schema
|
|
42
|
+
* @param config
|
|
43
|
+
*/
|
|
44
|
+
export declare function removeFederation(schema: GraphQLSchema): GraphQLSchema;
|
|
45
|
+
export declare class ApolloFederation {
|
|
46
|
+
private enabled;
|
|
47
|
+
private schema;
|
|
48
|
+
private providesMap;
|
|
49
|
+
/**
|
|
50
|
+
* `fieldsToGenerate` is a meta object where the keys are object type names
|
|
51
|
+
* and the values are fields that must be generated for that object.
|
|
52
|
+
*/
|
|
53
|
+
private fieldsToGenerate;
|
|
54
|
+
protected meta: FederationMeta;
|
|
55
|
+
constructor({ enabled, schema, meta }: {
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
schema: GraphQLSchema;
|
|
58
|
+
meta: FederationMeta;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Excludes types definde by Federation
|
|
62
|
+
* @param typeNames List of type names
|
|
63
|
+
*/
|
|
64
|
+
filterTypeNames(typeNames: string[]): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Excludes `__resolveReference` fields
|
|
67
|
+
* @param fieldNames List of field names
|
|
68
|
+
*/
|
|
69
|
+
filterFieldNames(fieldNames: string[]): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Decides if directive should not be generated
|
|
72
|
+
* @param name directive's name
|
|
73
|
+
*/
|
|
74
|
+
skipDirective(name: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Decides if scalar should not be generated
|
|
77
|
+
* @param name directive's name
|
|
78
|
+
*/
|
|
79
|
+
skipScalar(name: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* findFieldNodesToGenerate
|
|
82
|
+
* @description Function to find field nodes to generate.
|
|
83
|
+
* In a normal setup, all fields must be generated.
|
|
84
|
+
* However, in a Federatin setup, a field should not be generated if:
|
|
85
|
+
* - The field is marked as `@external` and there is no `@provides` path to the field
|
|
86
|
+
* - The parent object is marked as `@external` and there is no `@provides` path to the field
|
|
87
|
+
*/
|
|
88
|
+
findFieldNodesToGenerate({ node, }: {
|
|
89
|
+
node: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode;
|
|
90
|
+
}): readonly FieldDefinitionNode[];
|
|
91
|
+
isResolveReferenceField(fieldNode: FieldDefinitionNode): boolean;
|
|
92
|
+
addFederationTypeGenericIfApplicable({ genericTypes, typeName, federationTypesType, }: {
|
|
93
|
+
genericTypes: string[];
|
|
94
|
+
typeName: string;
|
|
95
|
+
federationTypesType: string;
|
|
96
|
+
}): void;
|
|
97
|
+
getMeta(): FederationMeta;
|
|
98
|
+
private isExternal;
|
|
99
|
+
private hasProvides;
|
|
100
|
+
private createMapOfProvides;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLOutputType, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { Types } from './types.cjs';
|
|
3
|
+
export declare function isOutputConfigArray(type: any): type is Types.OutputConfig[];
|
|
4
|
+
export declare function isConfiguredOutput(type: any): type is Types.ConfiguredOutput;
|
|
5
|
+
export declare function normalizeOutputParam(config: Types.OutputConfig | Types.ConfiguredPlugin[] | Types.ConfiguredOutput): Types.ConfiguredOutput;
|
|
6
|
+
export declare function normalizeInstanceOrArray<T>(type: T | T[]): T[];
|
|
7
|
+
export declare function normalizeConfig(config: Types.OutputConfig | Types.OutputConfig[]): Types.ConfiguredPlugin[];
|
|
8
|
+
export declare function hasNullableTypeRecursively(type: GraphQLOutputType): boolean;
|
|
9
|
+
export declare function isUsingTypes(document: DocumentNode, externalFragments: string[], schema?: GraphQLSchema): boolean;
|
|
10
|
+
export declare function normalizeImportExtension({ emitLegacyCommonJSImports, importExtension, }: {
|
|
11
|
+
emitLegacyCommonJSImports: boolean | undefined;
|
|
12
|
+
importExtension: '' | `.${string}` | undefined;
|
|
13
|
+
}): '' | `.${string}`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLOutputType, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { Types } from './types.js';
|
|
3
|
+
export declare function isOutputConfigArray(type: any): type is Types.OutputConfig[];
|
|
4
|
+
export declare function isConfiguredOutput(type: any): type is Types.ConfiguredOutput;
|
|
5
|
+
export declare function normalizeOutputParam(config: Types.OutputConfig | Types.ConfiguredPlugin[] | Types.ConfiguredOutput): Types.ConfiguredOutput;
|
|
6
|
+
export declare function normalizeInstanceOrArray<T>(type: T | T[]): T[];
|
|
7
|
+
export declare function normalizeConfig(config: Types.OutputConfig | Types.OutputConfig[]): Types.ConfiguredPlugin[];
|
|
8
|
+
export declare function hasNullableTypeRecursively(type: GraphQLOutputType): boolean;
|
|
9
|
+
export declare function isUsingTypes(document: DocumentNode, externalFragments: string[], schema?: GraphQLSchema): boolean;
|
|
10
|
+
export declare function normalizeImportExtension({ emitLegacyCommonJSImports, importExtension, }: {
|
|
11
|
+
emitLegacyCommonJSImports: boolean | undefined;
|
|
12
|
+
importExtension: '' | `.${string}` | undefined;
|
|
13
|
+
}): '' | `.${string}`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './federation.cjs';
|
|
2
|
+
export * from './getCachedDocumentNodeFromSchema.cjs';
|
|
3
|
+
export * from './helpers.cjs';
|
|
4
|
+
export * from './oldVisit.cjs';
|
|
5
|
+
export * from './profiler.cjs';
|
|
6
|
+
export { resolveExternalModuleAndFn } from './resolve-external-module-and-fn.cjs';
|
|
7
|
+
export * from './types.cjs';
|
|
8
|
+
export { Types } from './types.cjs';
|
|
9
|
+
export * from './utils.cjs';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './federation.js';
|
|
2
|
+
export * from './getCachedDocumentNodeFromSchema.js';
|
|
3
|
+
export * from './helpers.js';
|
|
4
|
+
export * from './oldVisit.js';
|
|
5
|
+
export * from './profiler.js';
|
|
6
|
+
export { resolveExternalModuleAndFn } from './resolve-external-module-and-fn.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export { Types } from './types.js';
|
|
9
|
+
export * from './utils.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTNode, visit } from 'graphql';
|
|
2
|
+
type VisitFn = typeof visit;
|
|
3
|
+
type NewVisitor = Partial<Parameters<VisitFn>[1]>;
|
|
4
|
+
type OldVisitor = {
|
|
5
|
+
enter?: Partial<Record<keyof NewVisitor, NonNullable<NewVisitor[keyof NewVisitor]>['enter']>>;
|
|
6
|
+
leave?: Partial<Record<keyof NewVisitor, NonNullable<NewVisitor[keyof NewVisitor]>['leave']>>;
|
|
7
|
+
} & NewVisitor;
|
|
8
|
+
export declare function oldVisit(root: ASTNode, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }: OldVisitor): any;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTNode, visit } from 'graphql';
|
|
2
|
+
type VisitFn = typeof visit;
|
|
3
|
+
type NewVisitor = Partial<Parameters<VisitFn>[1]>;
|
|
4
|
+
type OldVisitor = {
|
|
5
|
+
enter?: Partial<Record<keyof NewVisitor, NonNullable<NewVisitor[keyof NewVisitor]>['enter']>>;
|
|
6
|
+
leave?: Partial<Record<keyof NewVisitor, NonNullable<NewVisitor[keyof NewVisitor]>['leave']>>;
|
|
7
|
+
} & NewVisitor;
|
|
8
|
+
export declare function oldVisit(root: ASTNode, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }: OldVisitor): any;
|
|
9
|
+
export {};
|