@theguild/federation-composition 0.3.0 → 0.4.0-alpha-20231213171835-c0ecad8
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/subgraph/helpers.js +8 -1
- package/cjs/subgraph/validation/rules/elements/provides.js +4 -0
- package/esm/subgraph/helpers.js +8 -1
- package/esm/subgraph/validation/rules/elements/provides.js +4 -0
- package/package.json +1 -1
- package/typings/subgraph/helpers.d.cts +6 -1
- package/typings/subgraph/helpers.d.ts +6 -1
package/cjs/subgraph/helpers.js
CHANGED
|
@@ -87,7 +87,7 @@ function validateDirectiveAgainstOriginal(providedDirectiveNode, directiveName,
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
exports.validateDirectiveAgainstOriginal = validateDirectiveAgainstOriginal;
|
|
90
|
-
function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, }) {
|
|
90
|
+
function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, interceptFieldWithMissingSelectionSet, }) {
|
|
91
91
|
for (const selection of selectionSet.selections) {
|
|
92
92
|
if (selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
93
93
|
continue;
|
|
@@ -197,6 +197,13 @@ function visitFields({ context, selectionSet, typeDefinition, interceptField, in
|
|
|
197
197
|
}
|
|
198
198
|
const innerSelection = selection.selectionSet;
|
|
199
199
|
if (!innerSelection) {
|
|
200
|
+
if (interceptFieldWithMissingSelectionSet) {
|
|
201
|
+
interceptFieldWithMissingSelectionSet({
|
|
202
|
+
typeDefinition,
|
|
203
|
+
fieldName: selection.name.value,
|
|
204
|
+
outputType: (0, printer_js_1.print)(selectionFieldDef.type),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
200
207
|
continue;
|
|
201
208
|
}
|
|
202
209
|
visitFields({
|
|
@@ -78,6 +78,10 @@ function ProvidesRules(context) {
|
|
|
78
78
|
context,
|
|
79
79
|
selectionSet,
|
|
80
80
|
typeDefinition: targetType,
|
|
81
|
+
interceptFieldWithMissingSelectionSet(info) {
|
|
82
|
+
isValid = false;
|
|
83
|
+
context.reportError(new graphql_1.GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Invalid empty selection set for field "${info.typeDefinition.name.value}.${info.fieldName}" of non-leaf type ${info.outputType}`, { nodes: directiveNode, extensions: { code: 'PROVIDES_INVALID_FIELDS' } }));
|
|
84
|
+
},
|
|
81
85
|
interceptUnknownField(info) {
|
|
82
86
|
isValid = false;
|
|
83
87
|
context.reportError(new graphql_1.GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Cannot query field "${info.fieldName}" on type "${info.typeDefinition.name.value}" (if the field is defined in another subgraph, you need to add it to this subgraph with @external).`, { nodes: directiveNode, extensions: { code: 'PROVIDES_INVALID_FIELDS' } }));
|
package/esm/subgraph/helpers.js
CHANGED
|
@@ -83,7 +83,7 @@ export function validateDirectiveAgainstOriginal(providedDirectiveNode, directiv
|
|
|
83
83
|
context.markAsFederationDefinitionReplacement(providedDirectiveNode.name.value);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
export function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, }) {
|
|
86
|
+
export function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, interceptFieldWithMissingSelectionSet, }) {
|
|
87
87
|
for (const selection of selectionSet.selections) {
|
|
88
88
|
if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
89
89
|
continue;
|
|
@@ -193,6 +193,13 @@ export function visitFields({ context, selectionSet, typeDefinition, interceptFi
|
|
|
193
193
|
}
|
|
194
194
|
const innerSelection = selection.selectionSet;
|
|
195
195
|
if (!innerSelection) {
|
|
196
|
+
if (interceptFieldWithMissingSelectionSet) {
|
|
197
|
+
interceptFieldWithMissingSelectionSet({
|
|
198
|
+
typeDefinition,
|
|
199
|
+
fieldName: selection.name.value,
|
|
200
|
+
outputType: print(selectionFieldDef.type),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
196
203
|
continue;
|
|
197
204
|
}
|
|
198
205
|
visitFields({
|
|
@@ -75,6 +75,10 @@ export function ProvidesRules(context) {
|
|
|
75
75
|
context,
|
|
76
76
|
selectionSet,
|
|
77
77
|
typeDefinition: targetType,
|
|
78
|
+
interceptFieldWithMissingSelectionSet(info) {
|
|
79
|
+
isValid = false;
|
|
80
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Invalid empty selection set for field "${info.typeDefinition.name.value}.${info.fieldName}" of non-leaf type ${info.outputType}`, { nodes: directiveNode, extensions: { code: 'PROVIDES_INVALID_FIELDS' } }));
|
|
81
|
+
},
|
|
78
82
|
interceptUnknownField(info) {
|
|
79
83
|
isValid = false;
|
|
80
84
|
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Cannot query field "${info.fieldName}" on type "${info.typeDefinition.name.value}" (if the field is defined in another subgraph, you need to add it to this subgraph with @external).`, { nodes: directiveNode, extensions: { code: 'PROVIDES_INVALID_FIELDS' } }));
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { DirectiveDefinitionNode, DirectiveNode, InterfaceTypeDefinitionNode, In
|
|
|
2
2
|
import { SubgraphValidationContext } from './validation/validation-context.cjs';
|
|
3
3
|
export declare function validateDirectiveAgainstOriginal(providedDirectiveNode: DirectiveDefinitionNode, directiveName: string, context: SubgraphValidationContext): void;
|
|
4
4
|
type ObjectOrInterface = ObjectTypeDefinitionNode | ObjectTypeExtensionNode | InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;
|
|
5
|
-
export declare function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, }: {
|
|
5
|
+
export declare function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, interceptFieldWithMissingSelectionSet, }: {
|
|
6
6
|
context: SubgraphValidationContext;
|
|
7
7
|
selectionSet: SelectionSetNode;
|
|
8
8
|
typeDefinition: ObjectOrInterface;
|
|
@@ -10,6 +10,11 @@ export declare function visitFields({ context, selectionSet, typeDefinition, int
|
|
|
10
10
|
typeDefinition: ObjectOrInterface;
|
|
11
11
|
fieldName: string;
|
|
12
12
|
}): void;
|
|
13
|
+
interceptFieldWithMissingSelectionSet?(info: {
|
|
14
|
+
typeDefinition: ObjectOrInterface;
|
|
15
|
+
fieldName: string;
|
|
16
|
+
outputType: string;
|
|
17
|
+
}): void;
|
|
13
18
|
interceptArguments?(info: {
|
|
14
19
|
typeDefinition: ObjectOrInterface;
|
|
15
20
|
fieldName: string;
|
|
@@ -2,7 +2,7 @@ import { DirectiveDefinitionNode, DirectiveNode, InterfaceTypeDefinitionNode, In
|
|
|
2
2
|
import { SubgraphValidationContext } from './validation/validation-context.js';
|
|
3
3
|
export declare function validateDirectiveAgainstOriginal(providedDirectiveNode: DirectiveDefinitionNode, directiveName: string, context: SubgraphValidationContext): void;
|
|
4
4
|
type ObjectOrInterface = ObjectTypeDefinitionNode | ObjectTypeExtensionNode | InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;
|
|
5
|
-
export declare function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, }: {
|
|
5
|
+
export declare function visitFields({ context, selectionSet, typeDefinition, interceptField, interceptArguments, interceptUnknownField, interceptDirective, interceptInterfaceType, interceptExternalField, interceptNonExternalField, interceptFieldWithMissingSelectionSet, }: {
|
|
6
6
|
context: SubgraphValidationContext;
|
|
7
7
|
selectionSet: SelectionSetNode;
|
|
8
8
|
typeDefinition: ObjectOrInterface;
|
|
@@ -10,6 +10,11 @@ export declare function visitFields({ context, selectionSet, typeDefinition, int
|
|
|
10
10
|
typeDefinition: ObjectOrInterface;
|
|
11
11
|
fieldName: string;
|
|
12
12
|
}): void;
|
|
13
|
+
interceptFieldWithMissingSelectionSet?(info: {
|
|
14
|
+
typeDefinition: ObjectOrInterface;
|
|
15
|
+
fieldName: string;
|
|
16
|
+
outputType: string;
|
|
17
|
+
}): void;
|
|
13
18
|
interceptArguments?(info: {
|
|
14
19
|
typeDefinition: ObjectOrInterface;
|
|
15
20
|
fieldName: string;
|