@theguild/federation-composition 0.6.2 → 0.7.0-rc-20231220151602-cc7df93
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/validation/rules/known-directives-rule.js +3 -1
- package/cjs/subgraph/validation/validate-state.js +24 -1
- package/esm/subgraph/validation/rules/known-directives-rule.js +3 -1
- package/esm/subgraph/validation/validate-state.js +22 -0
- package/package.json +1 -1
- package/typings/subgraph/validation/validate-state.d.cts +2 -1
- package/typings/subgraph/validation/validate-state.d.ts +2 -1
|
@@ -11,7 +11,9 @@ function KnownDirectivesRule(context) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
for (const specifiedDirective of graphql_1.specifiedDirectives) {
|
|
14
|
-
locationsMap.
|
|
14
|
+
if (!locationsMap.has(specifiedDirective.name)) {
|
|
15
|
+
locationsMap.set(specifiedDirective.name, new Set(specifiedDirective.locations.map(loc => String(loc))));
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
return {
|
|
17
19
|
Directive(node, _key, _parent, _path, ancestors) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUnionType = exports.isInterfaceType = exports.isObjectType = exports.isEnumType = exports.isScalarType = exports.isInputObjectType = exports.typeExists = exports.isInputType = exports.isTypeSubTypeOf = exports.validateSubgraphState = void 0;
|
|
3
|
+
exports.isDirective = exports.isUnionType = exports.isInterfaceType = exports.isObjectType = exports.isEnumType = exports.isScalarType = exports.isInputObjectType = exports.typeExists = exports.isInputType = exports.isTypeSubTypeOf = exports.validateSubgraphState = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const format_js_1 = require("../../utils/format.js");
|
|
6
6
|
const state_js_1 = require("../../utils/state.js");
|
|
@@ -16,6 +16,7 @@ function validateSubgraphState(state) {
|
|
|
16
16
|
}));
|
|
17
17
|
}
|
|
18
18
|
validateRootTypes(state, reportError);
|
|
19
|
+
validateDirectives(state, reportError);
|
|
19
20
|
validateTypes(state, reportError);
|
|
20
21
|
return errors;
|
|
21
22
|
}
|
|
@@ -57,6 +58,24 @@ function validateRootTypes(state, reportError) {
|
|
|
57
58
|
function capitalize(str) {
|
|
58
59
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
59
60
|
}
|
|
61
|
+
function validateDirectives(state, reportError) {
|
|
62
|
+
for (const directive of state.types.values()) {
|
|
63
|
+
if (isDirective(directive)) {
|
|
64
|
+
validateName(reportError, directive.name);
|
|
65
|
+
for (const [argName, arg] of directive.args) {
|
|
66
|
+
validateName(reportError, argName);
|
|
67
|
+
const argInputTypeName = (0, state_js_1.stripTypeModifiers)(arg.type);
|
|
68
|
+
if (!isInputType(state, argInputTypeName)) {
|
|
69
|
+
reportError(`The type of @${directive.name}(${arg.name}:) must be Input Type ` +
|
|
70
|
+
`but got: ${arg.type}.`);
|
|
71
|
+
}
|
|
72
|
+
if (isRequiredArgument(arg) && arg.deprecated?.deprecated === true) {
|
|
73
|
+
reportError(`Required argument @${directive.name}(${arg.name}:) cannot be deprecated.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
60
79
|
function validateTypes(state, reportError) {
|
|
61
80
|
const validateInputObjectCircularRefs = createInputObjectCircularRefsValidator(state, reportError);
|
|
62
81
|
const implementationsMap = new Map();
|
|
@@ -474,3 +493,7 @@ function isUnionType(type) {
|
|
|
474
493
|
return type.kind === state_js_2.TypeKind.UNION;
|
|
475
494
|
}
|
|
476
495
|
exports.isUnionType = isUnionType;
|
|
496
|
+
function isDirective(type) {
|
|
497
|
+
return type.kind === state_js_2.TypeKind.DIRECTIVE;
|
|
498
|
+
}
|
|
499
|
+
exports.isDirective = isDirective;
|
|
@@ -8,7 +8,9 @@ export function KnownDirectivesRule(context) {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
for (const specifiedDirective of specifiedDirectives) {
|
|
11
|
-
locationsMap.
|
|
11
|
+
if (!locationsMap.has(specifiedDirective.name)) {
|
|
12
|
+
locationsMap.set(specifiedDirective.name, new Set(specifiedDirective.locations.map(loc => String(loc))));
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
15
|
return {
|
|
14
16
|
Directive(node, _key, _parent, _path, ancestors) {
|
|
@@ -13,6 +13,7 @@ export function validateSubgraphState(state) {
|
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
15
|
validateRootTypes(state, reportError);
|
|
16
|
+
validateDirectives(state, reportError);
|
|
16
17
|
validateTypes(state, reportError);
|
|
17
18
|
return errors;
|
|
18
19
|
}
|
|
@@ -53,6 +54,24 @@ function validateRootTypes(state, reportError) {
|
|
|
53
54
|
function capitalize(str) {
|
|
54
55
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
55
56
|
}
|
|
57
|
+
function validateDirectives(state, reportError) {
|
|
58
|
+
for (const directive of state.types.values()) {
|
|
59
|
+
if (isDirective(directive)) {
|
|
60
|
+
validateName(reportError, directive.name);
|
|
61
|
+
for (const [argName, arg] of directive.args) {
|
|
62
|
+
validateName(reportError, argName);
|
|
63
|
+
const argInputTypeName = stripTypeModifiers(arg.type);
|
|
64
|
+
if (!isInputType(state, argInputTypeName)) {
|
|
65
|
+
reportError(`The type of @${directive.name}(${arg.name}:) must be Input Type ` +
|
|
66
|
+
`but got: ${arg.type}.`);
|
|
67
|
+
}
|
|
68
|
+
if (isRequiredArgument(arg) && arg.deprecated?.deprecated === true) {
|
|
69
|
+
reportError(`Required argument @${directive.name}(${arg.name}:) cannot be deprecated.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
56
75
|
function validateTypes(state, reportError) {
|
|
57
76
|
const validateInputObjectCircularRefs = createInputObjectCircularRefsValidator(state, reportError);
|
|
58
77
|
const implementationsMap = new Map();
|
|
@@ -461,3 +480,6 @@ export function isInterfaceType(type) {
|
|
|
461
480
|
export function isUnionType(type) {
|
|
462
481
|
return type.kind === TypeKind.UNION;
|
|
463
482
|
}
|
|
483
|
+
export function isDirective(type) {
|
|
484
|
+
return type.kind === TypeKind.DIRECTIVE;
|
|
485
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLError } from 'graphql';
|
|
2
|
-
import { EnumType, InputObjectType, InterfaceType, ObjectType, ScalarType, SubgraphState, SubgraphType, UnionType } from '../state.cjs';
|
|
2
|
+
import { Directive, EnumType, InputObjectType, InterfaceType, ObjectType, ScalarType, SubgraphState, SubgraphType, UnionType } from '../state.cjs';
|
|
3
3
|
export declare function validateSubgraphState(state: SubgraphState): GraphQLError[];
|
|
4
4
|
export declare function isTypeSubTypeOf(state: SubgraphState, implementationsMap: Map<string, Set<string>>, maybeSubTypeName: string, superTypeName: string): boolean;
|
|
5
5
|
export declare function isInputType(state: SubgraphState, typeName: string): boolean;
|
|
@@ -10,4 +10,5 @@ export declare function isEnumType(type: SubgraphType): type is EnumType;
|
|
|
10
10
|
export declare function isObjectType(type: SubgraphType): type is ObjectType;
|
|
11
11
|
export declare function isInterfaceType(type: SubgraphType): type is InterfaceType;
|
|
12
12
|
export declare function isUnionType(type: SubgraphType): type is UnionType;
|
|
13
|
+
export declare function isDirective(type: SubgraphType): type is Directive;
|
|
13
14
|
//# sourceMappingURL=validate-state.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLError } from 'graphql';
|
|
2
|
-
import { EnumType, InputObjectType, InterfaceType, ObjectType, ScalarType, SubgraphState, SubgraphType, UnionType } from '../state.js';
|
|
2
|
+
import { Directive, EnumType, InputObjectType, InterfaceType, ObjectType, ScalarType, SubgraphState, SubgraphType, UnionType } from '../state.js';
|
|
3
3
|
export declare function validateSubgraphState(state: SubgraphState): GraphQLError[];
|
|
4
4
|
export declare function isTypeSubTypeOf(state: SubgraphState, implementationsMap: Map<string, Set<string>>, maybeSubTypeName: string, superTypeName: string): boolean;
|
|
5
5
|
export declare function isInputType(state: SubgraphState, typeName: string): boolean;
|
|
@@ -10,4 +10,5 @@ export declare function isEnumType(type: SubgraphType): type is EnumType;
|
|
|
10
10
|
export declare function isObjectType(type: SubgraphType): type is ObjectType;
|
|
11
11
|
export declare function isInterfaceType(type: SubgraphType): type is InterfaceType;
|
|
12
12
|
export declare function isUnionType(type: SubgraphType): type is UnionType;
|
|
13
|
+
export declare function isDirective(type: SubgraphType): type is Directive;
|
|
13
14
|
//# sourceMappingURL=validate-state.d.ts.map
|