@theguild/federation-composition 0.1.4 → 0.2.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/cjs/graphql/helpers.js +1 -48
- package/cjs/graphql/transform-supergraph-to-public-schema.js +98 -0
- package/cjs/index.js +3 -3
- package/esm/graphql/helpers.js +1 -47
- package/esm/graphql/transform-supergraph-to-public-schema.js +94 -0
- package/esm/index.js +1 -1
- package/package.json +1 -1
- package/typings/graphql/helpers.d.cts +1 -2
- package/typings/graphql/helpers.d.ts +1 -2
- package/typings/graphql/transform-supergraph-to-public-schema.d.cts +3 -0
- package/typings/graphql/transform-supergraph-to-public-schema.d.ts +3 -0
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/subgraph/validation/validation-context.d.cts +1 -1
- package/typings/subgraph/validation/validation-context.d.ts +1 -1
package/cjs/graphql/helpers.js
CHANGED
|
@@ -1,55 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isDirectiveDefinition = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
function isDirectiveDefinition(node) {
|
|
6
6
|
return node.kind === graphql_1.Kind.DIRECTIVE_DEFINITION;
|
|
7
7
|
}
|
|
8
8
|
exports.isDirectiveDefinition = isDirectiveDefinition;
|
|
9
|
-
function stripFederationFromSupergraph(supergraph) {
|
|
10
|
-
function removeDirective(node) {
|
|
11
|
-
const directiveName = node.name.value;
|
|
12
|
-
const isSpecifiedDirective = graphql_1.specifiedDirectives.some(d => d.name === directiveName);
|
|
13
|
-
if (!isSpecifiedDirective) {
|
|
14
|
-
const isFederationDirective = directiveName === 'link' ||
|
|
15
|
-
directiveName === 'inaccessible' ||
|
|
16
|
-
directiveName === 'tag' ||
|
|
17
|
-
directiveName === 'join__graph' ||
|
|
18
|
-
directiveName === 'join__type' ||
|
|
19
|
-
directiveName === 'join__implements' ||
|
|
20
|
-
directiveName === 'join__unionMember' ||
|
|
21
|
-
directiveName === 'join__enumValue' ||
|
|
22
|
-
directiveName === 'join__field';
|
|
23
|
-
if (isFederationDirective) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return (0, graphql_1.visit)(supergraph, {
|
|
29
|
-
DirectiveDefinition: removeDirective,
|
|
30
|
-
Directive: removeDirective,
|
|
31
|
-
SchemaDefinition() {
|
|
32
|
-
return null;
|
|
33
|
-
},
|
|
34
|
-
SchemaExtension() {
|
|
35
|
-
return null;
|
|
36
|
-
},
|
|
37
|
-
EnumTypeDefinition: node => {
|
|
38
|
-
if (node.name.value === 'core__Purpose' ||
|
|
39
|
-
node.name.value === 'join__Graph' ||
|
|
40
|
-
node.name.value === 'link__Purpose') {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return node;
|
|
44
|
-
},
|
|
45
|
-
ScalarTypeDefinition: node => {
|
|
46
|
-
if (node.name.value === '_FieldSet' ||
|
|
47
|
-
node.name.value === 'link__Import' ||
|
|
48
|
-
node.name.value === 'join__FieldSet') {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return node;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.stripFederationFromSupergraph = stripFederationFromSupergraph;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformSupergraphToPublicSchema = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const federationScalars = new Set(['_FieldSet', 'link__Import', 'join__FieldSet']);
|
|
6
|
+
const federationEnums = new Set(['core__Purpose', 'join__Graph', 'link__Purpose']);
|
|
7
|
+
const federationDirectives = new Set([
|
|
8
|
+
'link',
|
|
9
|
+
'tag',
|
|
10
|
+
'join__graph',
|
|
11
|
+
'join__type',
|
|
12
|
+
'join__implements',
|
|
13
|
+
'join__unionMember',
|
|
14
|
+
'join__enumValue',
|
|
15
|
+
'join__field',
|
|
16
|
+
'inaccessible',
|
|
17
|
+
]);
|
|
18
|
+
const specifiedDirectives = new Set(graphql_1.specifiedDirectives.map(d => d.name));
|
|
19
|
+
function getAdditionalDirectivesToStrip(documentNode) {
|
|
20
|
+
const schemaDefinitionNode = documentNode.definitions.find((node) => node.kind === graphql_1.Kind.SCHEMA_DEFINITION);
|
|
21
|
+
if (!schemaDefinitionNode?.directives?.length) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const additionalDirectivesToStrip = new Set();
|
|
25
|
+
for (const directive of schemaDefinitionNode.directives) {
|
|
26
|
+
if (directive.name.value !== 'link') {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const asArg = directive.arguments?.find(arg => arg.name.value === 'as');
|
|
30
|
+
if (asArg?.value.kind === graphql_1.Kind.STRING) {
|
|
31
|
+
additionalDirectivesToStrip.add(asArg.value.value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return additionalDirectivesToStrip;
|
|
35
|
+
}
|
|
36
|
+
const federationInaccessibleDirectiveUrlPrefix = 'https://specs.apollo.dev/inaccessible';
|
|
37
|
+
function getInaccessibleDirectiveName(documentNode) {
|
|
38
|
+
const schemaDefinitionNode = documentNode.definitions.find((node) => node.kind === graphql_1.Kind.SCHEMA_DEFINITION);
|
|
39
|
+
if (schemaDefinitionNode?.directives?.length) {
|
|
40
|
+
for (const directive of schemaDefinitionNode.directives) {
|
|
41
|
+
if (directive.name.value !== 'link') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const urlArg = directive.arguments?.find(arg => arg.name.value === 'url');
|
|
45
|
+
const asArg = directive.arguments?.find(arg => arg.name.value === 'as');
|
|
46
|
+
if (urlArg?.value.kind === graphql_1.Kind.STRING &&
|
|
47
|
+
urlArg.value.value.startsWith(federationInaccessibleDirectiveUrlPrefix)) {
|
|
48
|
+
if (asArg?.value.kind === graphql_1.Kind.STRING) {
|
|
49
|
+
return asArg.value.value;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return 'inaccessible';
|
|
56
|
+
}
|
|
57
|
+
function transformSupergraphToPublicSchema(documentNode) {
|
|
58
|
+
const additionalFederationDirectives = getAdditionalDirectivesToStrip(documentNode);
|
|
59
|
+
const inaccessibleDirectiveName = getInaccessibleDirectiveName(documentNode);
|
|
60
|
+
function removeFederationOrSpecifiedDirectives(node) {
|
|
61
|
+
if (federationDirectives.has(node.name.value) ||
|
|
62
|
+
additionalFederationDirectives?.has(node.name.value) ||
|
|
63
|
+
(node.kind === graphql_1.Kind.DIRECTIVE_DEFINITION && specifiedDirectives.has(node.name.value))) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function hasInaccessibleDirective(node) {
|
|
68
|
+
return node.directives?.some(d => d.name.value === inaccessibleDirectiveName);
|
|
69
|
+
}
|
|
70
|
+
function removeInaccessibleNode(node) {
|
|
71
|
+
if (hasInaccessibleDirective(node)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return (0, graphql_1.visit)(documentNode, {
|
|
76
|
+
[graphql_1.Kind.DIRECTIVE_DEFINITION]: removeFederationOrSpecifiedDirectives,
|
|
77
|
+
[graphql_1.Kind.DIRECTIVE]: removeFederationOrSpecifiedDirectives,
|
|
78
|
+
[graphql_1.Kind.SCHEMA_EXTENSION]: () => null,
|
|
79
|
+
[graphql_1.Kind.SCHEMA_DEFINITION]: () => null,
|
|
80
|
+
[graphql_1.Kind.SCALAR_TYPE_DEFINITION](node) {
|
|
81
|
+
if (federationScalars.has(node.name.value) || hasInaccessibleDirective(node)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[graphql_1.Kind.ENUM_TYPE_DEFINITION](node) {
|
|
86
|
+
if (federationEnums.has(node.name.value) || hasInaccessibleDirective(node)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
[graphql_1.Kind.OBJECT_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
91
|
+
[graphql_1.Kind.FIELD_DEFINITION]: removeInaccessibleNode,
|
|
92
|
+
[graphql_1.Kind.INTERFACE_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
93
|
+
[graphql_1.Kind.UNION_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
94
|
+
[graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
95
|
+
[graphql_1.Kind.INPUT_VALUE_DEFINITION]: removeInaccessibleNode,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.transformSupergraphToPublicSchema = transformSupergraphToPublicSchema;
|
package/cjs/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.transformSupergraphToPublicSchema = void 0;
|
|
18
18
|
__exportStar(require("./compose.js"), exports);
|
|
19
19
|
__exportStar(require("./types.js"), exports);
|
|
20
20
|
__exportStar(require("./validate.js"), exports);
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "
|
|
21
|
+
var transform_supergraph_to_public_schema_js_1 = require("./graphql/transform-supergraph-to-public-schema.js");
|
|
22
|
+
Object.defineProperty(exports, "transformSupergraphToPublicSchema", { enumerable: true, get: function () { return transform_supergraph_to_public_schema_js_1.transformSupergraphToPublicSchema; } });
|
package/esm/graphql/helpers.js
CHANGED
|
@@ -1,50 +1,4 @@
|
|
|
1
|
-
import { Kind
|
|
1
|
+
import { Kind } from 'graphql';
|
|
2
2
|
export function isDirectiveDefinition(node) {
|
|
3
3
|
return node.kind === Kind.DIRECTIVE_DEFINITION;
|
|
4
4
|
}
|
|
5
|
-
export function stripFederationFromSupergraph(supergraph) {
|
|
6
|
-
function removeDirective(node) {
|
|
7
|
-
const directiveName = node.name.value;
|
|
8
|
-
const isSpecifiedDirective = specifiedDirectives.some(d => d.name === directiveName);
|
|
9
|
-
if (!isSpecifiedDirective) {
|
|
10
|
-
const isFederationDirective = directiveName === 'link' ||
|
|
11
|
-
directiveName === 'inaccessible' ||
|
|
12
|
-
directiveName === 'tag' ||
|
|
13
|
-
directiveName === 'join__graph' ||
|
|
14
|
-
directiveName === 'join__type' ||
|
|
15
|
-
directiveName === 'join__implements' ||
|
|
16
|
-
directiveName === 'join__unionMember' ||
|
|
17
|
-
directiveName === 'join__enumValue' ||
|
|
18
|
-
directiveName === 'join__field';
|
|
19
|
-
if (isFederationDirective) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return visit(supergraph, {
|
|
25
|
-
DirectiveDefinition: removeDirective,
|
|
26
|
-
Directive: removeDirective,
|
|
27
|
-
SchemaDefinition() {
|
|
28
|
-
return null;
|
|
29
|
-
},
|
|
30
|
-
SchemaExtension() {
|
|
31
|
-
return null;
|
|
32
|
-
},
|
|
33
|
-
EnumTypeDefinition: node => {
|
|
34
|
-
if (node.name.value === 'core__Purpose' ||
|
|
35
|
-
node.name.value === 'join__Graph' ||
|
|
36
|
-
node.name.value === 'link__Purpose') {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return node;
|
|
40
|
-
},
|
|
41
|
-
ScalarTypeDefinition: node => {
|
|
42
|
-
if (node.name.value === '_FieldSet' ||
|
|
43
|
-
node.name.value === 'link__Import' ||
|
|
44
|
-
node.name.value === 'join__FieldSet') {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return node;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Kind, specifiedDirectives as specifiedDirectivesArray, visit, } from 'graphql';
|
|
2
|
+
const federationScalars = new Set(['_FieldSet', 'link__Import', 'join__FieldSet']);
|
|
3
|
+
const federationEnums = new Set(['core__Purpose', 'join__Graph', 'link__Purpose']);
|
|
4
|
+
const federationDirectives = new Set([
|
|
5
|
+
'link',
|
|
6
|
+
'tag',
|
|
7
|
+
'join__graph',
|
|
8
|
+
'join__type',
|
|
9
|
+
'join__implements',
|
|
10
|
+
'join__unionMember',
|
|
11
|
+
'join__enumValue',
|
|
12
|
+
'join__field',
|
|
13
|
+
'inaccessible',
|
|
14
|
+
]);
|
|
15
|
+
const specifiedDirectives = new Set(specifiedDirectivesArray.map(d => d.name));
|
|
16
|
+
function getAdditionalDirectivesToStrip(documentNode) {
|
|
17
|
+
const schemaDefinitionNode = documentNode.definitions.find((node) => node.kind === Kind.SCHEMA_DEFINITION);
|
|
18
|
+
if (!schemaDefinitionNode?.directives?.length) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const additionalDirectivesToStrip = new Set();
|
|
22
|
+
for (const directive of schemaDefinitionNode.directives) {
|
|
23
|
+
if (directive.name.value !== 'link') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const asArg = directive.arguments?.find(arg => arg.name.value === 'as');
|
|
27
|
+
if (asArg?.value.kind === Kind.STRING) {
|
|
28
|
+
additionalDirectivesToStrip.add(asArg.value.value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return additionalDirectivesToStrip;
|
|
32
|
+
}
|
|
33
|
+
const federationInaccessibleDirectiveUrlPrefix = 'https://specs.apollo.dev/inaccessible';
|
|
34
|
+
function getInaccessibleDirectiveName(documentNode) {
|
|
35
|
+
const schemaDefinitionNode = documentNode.definitions.find((node) => node.kind === Kind.SCHEMA_DEFINITION);
|
|
36
|
+
if (schemaDefinitionNode?.directives?.length) {
|
|
37
|
+
for (const directive of schemaDefinitionNode.directives) {
|
|
38
|
+
if (directive.name.value !== 'link') {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const urlArg = directive.arguments?.find(arg => arg.name.value === 'url');
|
|
42
|
+
const asArg = directive.arguments?.find(arg => arg.name.value === 'as');
|
|
43
|
+
if (urlArg?.value.kind === Kind.STRING &&
|
|
44
|
+
urlArg.value.value.startsWith(federationInaccessibleDirectiveUrlPrefix)) {
|
|
45
|
+
if (asArg?.value.kind === Kind.STRING) {
|
|
46
|
+
return asArg.value.value;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return 'inaccessible';
|
|
53
|
+
}
|
|
54
|
+
export function transformSupergraphToPublicSchema(documentNode) {
|
|
55
|
+
const additionalFederationDirectives = getAdditionalDirectivesToStrip(documentNode);
|
|
56
|
+
const inaccessibleDirectiveName = getInaccessibleDirectiveName(documentNode);
|
|
57
|
+
function removeFederationOrSpecifiedDirectives(node) {
|
|
58
|
+
if (federationDirectives.has(node.name.value) ||
|
|
59
|
+
additionalFederationDirectives?.has(node.name.value) ||
|
|
60
|
+
(node.kind === Kind.DIRECTIVE_DEFINITION && specifiedDirectives.has(node.name.value))) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function hasInaccessibleDirective(node) {
|
|
65
|
+
return node.directives?.some(d => d.name.value === inaccessibleDirectiveName);
|
|
66
|
+
}
|
|
67
|
+
function removeInaccessibleNode(node) {
|
|
68
|
+
if (hasInaccessibleDirective(node)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return visit(documentNode, {
|
|
73
|
+
[Kind.DIRECTIVE_DEFINITION]: removeFederationOrSpecifiedDirectives,
|
|
74
|
+
[Kind.DIRECTIVE]: removeFederationOrSpecifiedDirectives,
|
|
75
|
+
[Kind.SCHEMA_EXTENSION]: () => null,
|
|
76
|
+
[Kind.SCHEMA_DEFINITION]: () => null,
|
|
77
|
+
[Kind.SCALAR_TYPE_DEFINITION](node) {
|
|
78
|
+
if (federationScalars.has(node.name.value) || hasInaccessibleDirective(node)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[Kind.ENUM_TYPE_DEFINITION](node) {
|
|
83
|
+
if (federationEnums.has(node.name.value) || hasInaccessibleDirective(node)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
[Kind.OBJECT_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
88
|
+
[Kind.FIELD_DEFINITION]: removeInaccessibleNode,
|
|
89
|
+
[Kind.INTERFACE_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
90
|
+
[Kind.UNION_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
91
|
+
[Kind.INPUT_OBJECT_TYPE_DEFINITION]: removeInaccessibleNode,
|
|
92
|
+
[Kind.INPUT_VALUE_DEFINITION]: removeInaccessibleNode,
|
|
93
|
+
});
|
|
94
|
+
}
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DefinitionNode, DirectiveDefinitionNode
|
|
1
|
+
import { type DefinitionNode, type DirectiveDefinitionNode } from 'graphql';
|
|
2
2
|
export declare function isDirectiveDefinition(node: DefinitionNode): node is DirectiveDefinitionNode;
|
|
3
|
-
export declare function stripFederationFromSupergraph(supergraph: DocumentNode): DocumentNode;
|
|
4
3
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DefinitionNode, DirectiveDefinitionNode
|
|
1
|
+
import { type DefinitionNode, type DirectiveDefinitionNode } from 'graphql';
|
|
2
2
|
export declare function isDirectiveDefinition(node: DefinitionNode): node is DirectiveDefinitionNode;
|
|
3
|
-
export declare function stripFederationFromSupergraph(supergraph: DocumentNode): DocumentNode;
|
|
4
3
|
//# sourceMappingURL=helpers.d.ts.map
|
package/typings/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './compose.cjs';
|
|
2
2
|
export * from './types.cjs';
|
|
3
3
|
export * from './validate.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { transformSupergraphToPublicSchema } from './graphql/transform-supergraph-to-public-schema.cjs';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './compose.js';
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './validate.js';
|
|
4
|
-
export {
|
|
4
|
+
export { transformSupergraphToPublicSchema } from './graphql/transform-supergraph-to-public-schema.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -150,7 +150,7 @@ export declare function createSubgraphValidationContext(subgraph: {
|
|
|
150
150
|
};
|
|
151
151
|
composedDirectives: Set<string>;
|
|
152
152
|
state: import("../state.js").SubgraphState;
|
|
153
|
-
markSpecAsUsed(specName: "link" | "
|
|
153
|
+
markSpecAsUsed(specName: "link" | "tag" | "inaccessible"): void;
|
|
154
154
|
visitor(typeNodeInfo: TypeNodeInfo): import("graphql").ASTVisitor;
|
|
155
155
|
};
|
|
156
156
|
isAvailableFederationType(name: string): boolean;
|
|
@@ -150,7 +150,7 @@ export declare function createSubgraphValidationContext(subgraph: {
|
|
|
150
150
|
};
|
|
151
151
|
composedDirectives: Set<string>;
|
|
152
152
|
state: import("../state.js").SubgraphState;
|
|
153
|
-
markSpecAsUsed(specName: "link" | "
|
|
153
|
+
markSpecAsUsed(specName: "link" | "tag" | "inaccessible"): void;
|
|
154
154
|
visitor(typeNodeInfo: TypeNodeInfo): import("graphql").ASTVisitor;
|
|
155
155
|
};
|
|
156
156
|
isAvailableFederationType(name: string): boolean;
|