@theguild/federation-composition 0.0.0-alpha-20230916192321-bb37b43
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/LICENSE +18 -0
- package/cjs/compose.js +85 -0
- package/cjs/graphql/helpers.js +32 -0
- package/cjs/graphql/printer.js +248 -0
- package/cjs/graphql/type-node-info.js +142 -0
- package/cjs/index.js +22 -0
- package/cjs/package.json +1 -0
- package/cjs/specifications/federation.js +211 -0
- package/cjs/specifications/inaccessible.js +10 -0
- package/cjs/specifications/join.js +35 -0
- package/cjs/specifications/link.js +222 -0
- package/cjs/specifications/tag.js +12 -0
- package/cjs/subgraph/helpers.js +255 -0
- package/cjs/subgraph/state.js +1154 -0
- package/cjs/subgraph/validation/rules/elements/compose-directive.js +41 -0
- package/cjs/subgraph/validation/rules/elements/extends.js +34 -0
- package/cjs/subgraph/validation/rules/elements/external.js +57 -0
- package/cjs/subgraph/validation/rules/elements/field-set.js +37 -0
- package/cjs/subgraph/validation/rules/elements/inaccessible.js +112 -0
- package/cjs/subgraph/validation/rules/elements/key.js +148 -0
- package/cjs/subgraph/validation/rules/elements/override.js +56 -0
- package/cjs/subgraph/validation/rules/elements/provides.js +173 -0
- package/cjs/subgraph/validation/rules/elements/requires.js +119 -0
- package/cjs/subgraph/validation/rules/elements/shareable.js +43 -0
- package/cjs/subgraph/validation/rules/elements/tag.js +120 -0
- package/cjs/subgraph/validation/rules/known-argument-names-on-directives-rule.js +34 -0
- package/cjs/subgraph/validation/rules/known-directives-rule.js +105 -0
- package/cjs/subgraph/validation/rules/known-federation-directive-rule.js +34 -0
- package/cjs/subgraph/validation/rules/known-root-type-rule.js +25 -0
- package/cjs/subgraph/validation/rules/known-type-names-rule.js +34 -0
- package/cjs/subgraph/validation/rules/lone-schema-definition-rule.js +20 -0
- package/cjs/subgraph/validation/rules/provided-arguments-on-directives-rule.js +104 -0
- package/cjs/subgraph/validation/rules/provided-required-arguments-on-directives-rule.js +46 -0
- package/cjs/subgraph/validation/rules/query-root-type-inaccessible-rule.js +33 -0
- package/cjs/subgraph/validation/rules/reserved-subgraph-name-rule.js +15 -0
- package/cjs/subgraph/validation/rules/root-type-used-rule.js +59 -0
- package/cjs/subgraph/validation/rules/unique-argument-definition-names-rule.js +42 -0
- package/cjs/subgraph/validation/rules/unique-argument-names-rule.js +27 -0
- package/cjs/subgraph/validation/rules/unique-directive-names-rule.js +24 -0
- package/cjs/subgraph/validation/rules/unique-directives-per-location-rule.js +52 -0
- package/cjs/subgraph/validation/rules/unique-enum-value-names-rule.js +33 -0
- package/cjs/subgraph/validation/rules/unique-field-definition-names-rule.js +37 -0
- package/cjs/subgraph/validation/rules/unique-input-field-names-rule.js +37 -0
- package/cjs/subgraph/validation/rules/unique-operation-types-rule.js +29 -0
- package/cjs/subgraph/validation/rules/unique-type-names-rule.js +29 -0
- package/cjs/subgraph/validation/validate-state.js +476 -0
- package/cjs/subgraph/validation/validate-subgraph.js +329 -0
- package/cjs/subgraph/validation/validation-context.js +267 -0
- package/cjs/supergraph/composition/ast.js +779 -0
- package/cjs/supergraph/composition/common.js +7 -0
- package/cjs/supergraph/composition/directive.js +93 -0
- package/cjs/supergraph/composition/enum-type.js +132 -0
- package/cjs/supergraph/composition/input-object-type.js +119 -0
- package/cjs/supergraph/composition/interface-type.js +226 -0
- package/cjs/supergraph/composition/object-type.js +380 -0
- package/cjs/supergraph/composition/scalar-type.js +63 -0
- package/cjs/supergraph/composition/union-type.js +64 -0
- package/cjs/supergraph/composition/visitor.js +62 -0
- package/cjs/supergraph/state.js +249 -0
- package/cjs/supergraph/validation/rules/default-value-uses-inaccessible-rule.js +35 -0
- package/cjs/supergraph/validation/rules/directive-composition-rule.js +98 -0
- package/cjs/supergraph/validation/rules/enum-values-rule.js +59 -0
- package/cjs/supergraph/validation/rules/extension-with-base.js +31 -0
- package/cjs/supergraph/validation/rules/external-argument-missing-rule.js +32 -0
- package/cjs/supergraph/validation/rules/external-missing-on-base-rule.js +48 -0
- package/cjs/supergraph/validation/rules/external-type-mismatch-rule.js +52 -0
- package/cjs/supergraph/validation/rules/field-argument-default-mismatch-rule.js +40 -0
- package/cjs/supergraph/validation/rules/field-arguments-of-the-same-type-rule.js +49 -0
- package/cjs/supergraph/validation/rules/fields-of-the-same-type-rule.js +89 -0
- package/cjs/supergraph/validation/rules/input-field-default-mismatch-rule.js +40 -0
- package/cjs/supergraph/validation/rules/input-object-values-rule.js +25 -0
- package/cjs/supergraph/validation/rules/interface-key-missing-implementation-type.js +46 -0
- package/cjs/supergraph/validation/rules/invalid-field-sharing-rule.js +45 -0
- package/cjs/supergraph/validation/rules/only-inaccessible-children-rule.js +40 -0
- package/cjs/supergraph/validation/rules/override-source-has-override.js +36 -0
- package/cjs/supergraph/validation/rules/referenced-inaccessible-rule.js +44 -0
- package/cjs/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.js +32 -0
- package/cjs/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.js +32 -0
- package/cjs/supergraph/validation/rules/required-query-rule.js +14 -0
- package/cjs/supergraph/validation/rules/satisfiablity-rule.js +866 -0
- package/cjs/supergraph/validation/rules/subgraph-name-rule.js +18 -0
- package/cjs/supergraph/validation/rules/types-of-the-same-kind-rule.js +54 -0
- package/cjs/supergraph/validation/validate-supergraph.js +77 -0
- package/cjs/supergraph/validation/validation-context.js +25 -0
- package/cjs/types.js +0 -0
- package/cjs/utils/dependency-graph.js +227 -0
- package/cjs/utils/format.js +27 -0
- package/cjs/utils/helpers.js +7 -0
- package/cjs/utils/state.js +23 -0
- package/cjs/validate.js +117 -0
- package/esm/compose.js +78 -0
- package/esm/graphql/helpers.js +27 -0
- package/esm/graphql/printer.js +244 -0
- package/esm/graphql/type-node-info.js +137 -0
- package/esm/index.js +4 -0
- package/esm/specifications/federation.js +204 -0
- package/esm/specifications/inaccessible.js +7 -0
- package/esm/specifications/join.js +32 -0
- package/esm/specifications/link.js +210 -0
- package/esm/specifications/tag.js +9 -0
- package/esm/subgraph/helpers.js +245 -0
- package/esm/subgraph/state.js +1148 -0
- package/esm/subgraph/validation/rules/elements/compose-directive.js +37 -0
- package/esm/subgraph/validation/rules/elements/extends.js +30 -0
- package/esm/subgraph/validation/rules/elements/external.js +53 -0
- package/esm/subgraph/validation/rules/elements/field-set.js +33 -0
- package/esm/subgraph/validation/rules/elements/inaccessible.js +108 -0
- package/esm/subgraph/validation/rules/elements/key.js +144 -0
- package/esm/subgraph/validation/rules/elements/override.js +52 -0
- package/esm/subgraph/validation/rules/elements/provides.js +169 -0
- package/esm/subgraph/validation/rules/elements/requires.js +115 -0
- package/esm/subgraph/validation/rules/elements/shareable.js +39 -0
- package/esm/subgraph/validation/rules/elements/tag.js +116 -0
- package/esm/subgraph/validation/rules/known-argument-names-on-directives-rule.js +30 -0
- package/esm/subgraph/validation/rules/known-directives-rule.js +101 -0
- package/esm/subgraph/validation/rules/known-federation-directive-rule.js +30 -0
- package/esm/subgraph/validation/rules/known-root-type-rule.js +21 -0
- package/esm/subgraph/validation/rules/known-type-names-rule.js +30 -0
- package/esm/subgraph/validation/rules/lone-schema-definition-rule.js +16 -0
- package/esm/subgraph/validation/rules/provided-arguments-on-directives-rule.js +100 -0
- package/esm/subgraph/validation/rules/provided-required-arguments-on-directives-rule.js +42 -0
- package/esm/subgraph/validation/rules/query-root-type-inaccessible-rule.js +29 -0
- package/esm/subgraph/validation/rules/reserved-subgraph-name-rule.js +11 -0
- package/esm/subgraph/validation/rules/root-type-used-rule.js +55 -0
- package/esm/subgraph/validation/rules/unique-argument-definition-names-rule.js +38 -0
- package/esm/subgraph/validation/rules/unique-argument-names-rule.js +23 -0
- package/esm/subgraph/validation/rules/unique-directive-names-rule.js +20 -0
- package/esm/subgraph/validation/rules/unique-directives-per-location-rule.js +48 -0
- package/esm/subgraph/validation/rules/unique-enum-value-names-rule.js +29 -0
- package/esm/subgraph/validation/rules/unique-field-definition-names-rule.js +33 -0
- package/esm/subgraph/validation/rules/unique-input-field-names-rule.js +33 -0
- package/esm/subgraph/validation/rules/unique-operation-types-rule.js +25 -0
- package/esm/subgraph/validation/rules/unique-type-names-rule.js +25 -0
- package/esm/subgraph/validation/validate-state.js +463 -0
- package/esm/subgraph/validation/validate-subgraph.js +323 -0
- package/esm/subgraph/validation/validation-context.js +262 -0
- package/esm/supergraph/composition/ast.js +765 -0
- package/esm/supergraph/composition/common.js +3 -0
- package/esm/supergraph/composition/directive.js +89 -0
- package/esm/supergraph/composition/enum-type.js +128 -0
- package/esm/supergraph/composition/input-object-type.js +115 -0
- package/esm/supergraph/composition/interface-type.js +222 -0
- package/esm/supergraph/composition/object-type.js +375 -0
- package/esm/supergraph/composition/scalar-type.js +59 -0
- package/esm/supergraph/composition/union-type.js +60 -0
- package/esm/supergraph/composition/visitor.js +58 -0
- package/esm/supergraph/state.js +245 -0
- package/esm/supergraph/validation/rules/default-value-uses-inaccessible-rule.js +31 -0
- package/esm/supergraph/validation/rules/directive-composition-rule.js +94 -0
- package/esm/supergraph/validation/rules/enum-values-rule.js +55 -0
- package/esm/supergraph/validation/rules/extension-with-base.js +27 -0
- package/esm/supergraph/validation/rules/external-argument-missing-rule.js +28 -0
- package/esm/supergraph/validation/rules/external-missing-on-base-rule.js +44 -0
- package/esm/supergraph/validation/rules/external-type-mismatch-rule.js +48 -0
- package/esm/supergraph/validation/rules/field-argument-default-mismatch-rule.js +36 -0
- package/esm/supergraph/validation/rules/field-arguments-of-the-same-type-rule.js +45 -0
- package/esm/supergraph/validation/rules/fields-of-the-same-type-rule.js +85 -0
- package/esm/supergraph/validation/rules/input-field-default-mismatch-rule.js +36 -0
- package/esm/supergraph/validation/rules/input-object-values-rule.js +21 -0
- package/esm/supergraph/validation/rules/interface-key-missing-implementation-type.js +42 -0
- package/esm/supergraph/validation/rules/invalid-field-sharing-rule.js +41 -0
- package/esm/supergraph/validation/rules/only-inaccessible-children-rule.js +36 -0
- package/esm/supergraph/validation/rules/override-source-has-override.js +32 -0
- package/esm/supergraph/validation/rules/referenced-inaccessible-rule.js +40 -0
- package/esm/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.js +28 -0
- package/esm/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.js +28 -0
- package/esm/supergraph/validation/rules/required-query-rule.js +10 -0
- package/esm/supergraph/validation/rules/satisfiablity-rule.js +862 -0
- package/esm/supergraph/validation/rules/subgraph-name-rule.js +14 -0
- package/esm/supergraph/validation/rules/types-of-the-same-kind-rule.js +50 -0
- package/esm/supergraph/validation/validate-supergraph.js +73 -0
- package/esm/supergraph/validation/validation-context.js +21 -0
- package/esm/types.js +0 -0
- package/esm/utils/dependency-graph.js +222 -0
- package/esm/utils/format.js +23 -0
- package/esm/utils/helpers.js +3 -0
- package/esm/utils/state.js +15 -0
- package/esm/validate.js +113 -0
- package/package.json +46 -0
- package/typings/compose.d.cts +16 -0
- package/typings/compose.d.ts +16 -0
- package/typings/graphql/helpers.d.cts +4 -0
- package/typings/graphql/helpers.d.ts +4 -0
- package/typings/graphql/printer.d.cts +3 -0
- package/typings/graphql/printer.d.ts +3 -0
- package/typings/graphql/type-node-info.d.cts +19 -0
- package/typings/graphql/type-node-info.d.ts +19 -0
- package/typings/index.d.cts +5 -0
- package/typings/index.d.ts +5 -0
- package/typings/specifications/federation.d.cts +45 -0
- package/typings/specifications/federation.d.ts +45 -0
- package/typings/specifications/inaccessible.d.cts +4 -0
- package/typings/specifications/inaccessible.d.ts +4 -0
- package/typings/specifications/join.d.cts +2 -0
- package/typings/specifications/join.d.ts +2 -0
- package/typings/specifications/link.d.cts +61 -0
- package/typings/specifications/link.d.ts +61 -0
- package/typings/specifications/tag.d.cts +4 -0
- package/typings/specifications/tag.d.ts +4 -0
- package/typings/subgraph/helpers.d.cts +44 -0
- package/typings/subgraph/helpers.d.ts +44 -0
- package/typings/subgraph/state.d.cts +322 -0
- package/typings/subgraph/state.d.ts +322 -0
- package/typings/subgraph/validation/rules/elements/compose-directive.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/compose-directive.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/extends.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/extends.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/external.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/external.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/field-set.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/field-set.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/inaccessible.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/inaccessible.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/key.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/key.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/override.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/override.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/provides.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/provides.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/requires.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/requires.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/shareable.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/shareable.d.ts +4 -0
- package/typings/subgraph/validation/rules/elements/tag.d.cts +4 -0
- package/typings/subgraph/validation/rules/elements/tag.d.ts +4 -0
- package/typings/subgraph/validation/rules/known-argument-names-on-directives-rule.d.cts +6 -0
- package/typings/subgraph/validation/rules/known-argument-names-on-directives-rule.d.ts +6 -0
- package/typings/subgraph/validation/rules/known-directives-rule.d.cts +6 -0
- package/typings/subgraph/validation/rules/known-directives-rule.d.ts +6 -0
- package/typings/subgraph/validation/rules/known-federation-directive-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/known-federation-directive-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/known-root-type-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/known-root-type-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/known-type-names-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/known-type-names-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/lone-schema-definition-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/lone-schema-definition-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/provided-arguments-on-directives-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/provided-arguments-on-directives-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/provided-required-arguments-on-directives-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/provided-required-arguments-on-directives-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/query-root-type-inaccessible-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/query-root-type-inaccessible-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/reserved-subgraph-name-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/reserved-subgraph-name-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/root-type-used-rule.d.cts +4 -0
- package/typings/subgraph/validation/rules/root-type-used-rule.d.ts +4 -0
- package/typings/subgraph/validation/rules/unique-argument-definition-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-argument-definition-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-argument-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-argument-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-directive-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-directive-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-directives-per-location-rule.d.cts +6 -0
- package/typings/subgraph/validation/rules/unique-directives-per-location-rule.d.ts +6 -0
- package/typings/subgraph/validation/rules/unique-enum-value-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-enum-value-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-field-definition-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-field-definition-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-input-field-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-input-field-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-operation-types-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-operation-types-rule.d.ts +5 -0
- package/typings/subgraph/validation/rules/unique-type-names-rule.d.cts +5 -0
- package/typings/subgraph/validation/rules/unique-type-names-rule.d.ts +5 -0
- package/typings/subgraph/validation/validate-state.d.cts +13 -0
- package/typings/subgraph/validation/validate-state.d.ts +13 -0
- package/typings/subgraph/validation/validate-subgraph.d.cts +43 -0
- package/typings/subgraph/validation/validate-subgraph.d.ts +43 -0
- package/typings/subgraph/validation/validation-context.d.cts +182 -0
- package/typings/subgraph/validation/validation-context.d.ts +182 -0
- package/typings/supergraph/composition/ast.d.cts +216 -0
- package/typings/supergraph/composition/ast.d.ts +216 -0
- package/typings/supergraph/composition/common.d.cts +19 -0
- package/typings/supergraph/composition/common.d.ts +19 -0
- package/typings/supergraph/composition/directive.d.cts +32 -0
- package/typings/supergraph/composition/directive.d.ts +32 -0
- package/typings/supergraph/composition/enum-type.d.cts +32 -0
- package/typings/supergraph/composition/enum-type.d.ts +32 -0
- package/typings/supergraph/composition/input-object-type.d.cts +32 -0
- package/typings/supergraph/composition/input-object-type.d.ts +32 -0
- package/typings/supergraph/composition/interface-type.d.cts +61 -0
- package/typings/supergraph/composition/interface-type.d.ts +61 -0
- package/typings/supergraph/composition/object-type.d.cts +79 -0
- package/typings/supergraph/composition/object-type.d.ts +79 -0
- package/typings/supergraph/composition/scalar-type.d.cts +20 -0
- package/typings/supergraph/composition/scalar-type.d.ts +20 -0
- package/typings/supergraph/composition/union-type.d.cts +17 -0
- package/typings/supergraph/composition/union-type.d.ts +17 -0
- package/typings/supergraph/composition/visitor.d.cts +18 -0
- package/typings/supergraph/composition/visitor.d.ts +18 -0
- package/typings/supergraph/state.d.cts +51 -0
- package/typings/supergraph/state.d.ts +51 -0
- package/typings/supergraph/validation/rules/default-value-uses-inaccessible-rule.d.cts +5 -0
- package/typings/supergraph/validation/rules/default-value-uses-inaccessible-rule.d.ts +5 -0
- package/typings/supergraph/validation/rules/directive-composition-rule.d.cts +5 -0
- package/typings/supergraph/validation/rules/directive-composition-rule.d.ts +5 -0
- package/typings/supergraph/validation/rules/enum-values-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/enum-values-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/extension-with-base.d.cts +4 -0
- package/typings/supergraph/validation/rules/extension-with-base.d.ts +4 -0
- package/typings/supergraph/validation/rules/external-argument-missing-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/external-argument-missing-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/external-missing-on-base-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/external-missing-on-base-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/external-type-mismatch-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/external-type-mismatch-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/field-argument-default-mismatch-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/field-argument-default-mismatch-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/field-arguments-of-the-same-type-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/field-arguments-of-the-same-type-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/fields-of-the-same-type-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/fields-of-the-same-type-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/input-field-default-mismatch-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/input-field-default-mismatch-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/input-object-values-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/input-object-values-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/interface-key-missing-implementation-type.d.cts +4 -0
- package/typings/supergraph/validation/rules/interface-key-missing-implementation-type.d.ts +4 -0
- package/typings/supergraph/validation/rules/invalid-field-sharing-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/invalid-field-sharing-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/only-inaccessible-children-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/only-inaccessible-children-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/override-source-has-override.d.cts +4 -0
- package/typings/supergraph/validation/rules/override-source-has-override.d.ts +4 -0
- package/typings/supergraph/validation/rules/referenced-inaccessible-rule.d.cts +5 -0
- package/typings/supergraph/validation/rules/referenced-inaccessible-rule.d.ts +5 -0
- package/typings/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.d.cts +4 -0
- package/typings/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.d.ts +4 -0
- package/typings/supergraph/validation/rules/required-query-rule.d.cts +3 -0
- package/typings/supergraph/validation/rules/required-query-rule.d.ts +3 -0
- package/typings/supergraph/validation/rules/satisfiablity-rule.d.cts +5 -0
- package/typings/supergraph/validation/rules/satisfiablity-rule.d.ts +5 -0
- package/typings/supergraph/validation/rules/subgraph-name-rule.d.cts +3 -0
- package/typings/supergraph/validation/rules/subgraph-name-rule.d.ts +3 -0
- package/typings/supergraph/validation/rules/types-of-the-same-kind-rule.d.cts +3 -0
- package/typings/supergraph/validation/rules/types-of-the-same-kind-rule.d.ts +3 -0
- package/typings/supergraph/validation/validate-supergraph.d.cts +6 -0
- package/typings/supergraph/validation/validate-supergraph.d.ts +6 -0
- package/typings/supergraph/validation/validation-context.d.cts +10 -0
- package/typings/supergraph/validation/validation-context.d.ts +10 -0
- package/typings/types.d.cts +7 -0
- package/typings/types.d.ts +7 -0
- package/typings/utils/dependency-graph.d.cts +31 -0
- package/typings/utils/dependency-graph.d.ts +31 -0
- package/typings/utils/format.d.cts +2 -0
- package/typings/utils/format.d.ts +2 -0
- package/typings/utils/helpers.d.cts +2 -0
- package/typings/utils/helpers.d.ts +2 -0
- package/typings/utils/state.d.cts +6 -0
- package/typings/utils/state.d.ts +6 -0
- package/typings/validate.d.cts +37 -0
- package/typings/validate.d.ts +37 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GraphQLError, Kind } from 'graphql';
|
|
2
|
+
import { isDirectiveDefinitionNode, validateDirectiveAgainstOriginal } from '../../../helpers.js';
|
|
3
|
+
export function ComposeDirectiveRules(context) {
|
|
4
|
+
return {
|
|
5
|
+
DirectiveDefinition(node) {
|
|
6
|
+
validateDirectiveAgainstOriginal(node, 'composeDirective', context);
|
|
7
|
+
},
|
|
8
|
+
Directive(node) {
|
|
9
|
+
if (!context.isAvailableFederationDirective('composeDirective', node)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!context.satisfiesVersionRange('>= v2.1')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const nameArg = node.arguments?.find(arg => arg.name.value === 'name');
|
|
16
|
+
if (!nameArg || nameArg.value.kind !== Kind.STRING) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const name = nameArg.value.value.replace(/^@/, '');
|
|
20
|
+
const definedDirectives = context.getDocument().definitions.filter(isDirectiveDefinitionNode);
|
|
21
|
+
const matchingDirective = definedDirectives.find(directive => directive.name.value === name);
|
|
22
|
+
if (matchingDirective) {
|
|
23
|
+
context.stateBuilder.directive.setComposed(matchingDirective.name.value);
|
|
24
|
+
context.stateBuilder.composedDirectives.add(matchingDirective.name.value);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
context.reportError(new GraphQLError(`Could not find matching directive definition for argument to @composeDirective "@${name}" in subgraph "${context.getSubgraphName()}".`, {
|
|
28
|
+
nodes: node,
|
|
29
|
+
extensions: {
|
|
30
|
+
code: 'DIRECTIVE_COMPOSITION_ERROR',
|
|
31
|
+
subgraphName: context.getSubgraphName(),
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Kind } from 'graphql';
|
|
2
|
+
import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
|
|
3
|
+
export function ExtendsRules(context) {
|
|
4
|
+
return {
|
|
5
|
+
DirectiveDefinition(node) {
|
|
6
|
+
validateDirectiveAgainstOriginal(node, 'extends', context);
|
|
7
|
+
},
|
|
8
|
+
Directive(node) {
|
|
9
|
+
if (!context.isAvailableFederationDirective('extends', node)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
13
|
+
if (!typeDef ||
|
|
14
|
+
!(typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
15
|
+
typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (typeDef.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
19
|
+
context.stateBuilder.objectType.setExtension(typeDef.name.value, '@extends');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
context.stateBuilder.interfaceType.setExtension(typeDef.name.value);
|
|
23
|
+
}
|
|
24
|
+
const fields = typeDef.fields;
|
|
25
|
+
for (const field of fields ?? []) {
|
|
26
|
+
context.markAsUsed('@extends', typeDef.kind, typeDef.name.value, field.name.value);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GraphQLError, Kind } from 'graphql';
|
|
2
|
+
import { print } from '../../../../graphql/printer.js';
|
|
3
|
+
import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
|
|
4
|
+
export function ExternalRules(context) {
|
|
5
|
+
return {
|
|
6
|
+
DirectiveDefinition(node) {
|
|
7
|
+
validateDirectiveAgainstOriginal(node, 'external', context);
|
|
8
|
+
},
|
|
9
|
+
Directive(node) {
|
|
10
|
+
if (!context.isAvailableFederationDirective('external', node)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
14
|
+
const fieldDef = context.typeNodeInfo.getFieldDef();
|
|
15
|
+
if (!typeDef ||
|
|
16
|
+
!(typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
17
|
+
typeDef.kind === Kind.OBJECT_TYPE_EXTENSION)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const fieldDefinitions = [];
|
|
21
|
+
if (fieldDef) {
|
|
22
|
+
if (fieldDef.kind !== Kind.FIELD_DEFINITION) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
fieldDefinitions.push(fieldDef);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const fields = typeDef.fields;
|
|
29
|
+
if (fields) {
|
|
30
|
+
if (context.satisfiesVersionRange('>= v2.0')) {
|
|
31
|
+
fieldDefinitions.push(...fields);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const field of fieldDefinitions) {
|
|
36
|
+
context.markAsExternal(`${typeDef.name.value}.${field.name.value}`);
|
|
37
|
+
const conflictingDirectives = field.directives?.filter(directive => context.isAvailableFederationDirective('tag', directive) ||
|
|
38
|
+
context.isAvailableFederationDirective('inaccessible', directive));
|
|
39
|
+
if (conflictingDirectives?.length && context.satisfiesVersionRange('>= v2.0')) {
|
|
40
|
+
for (const directive of conflictingDirectives) {
|
|
41
|
+
context.reportError(new GraphQLError(`Cannot apply merged directive ${print(directive).trim()} to external field "${typeDef.name.value}.${field.name.value}"`, {
|
|
42
|
+
nodes: node,
|
|
43
|
+
extensions: { code: 'MERGED_DIRECTIVE_APPLICATION_ON_EXTERNAL' },
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
context.stateBuilder.objectType.field.setExternal(typeDef.name.value, field.name.value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function FieldSetRules(context) {
|
|
3
|
+
function validateFieldSet(node, receivedType) {
|
|
4
|
+
if (node.name.value === 'FieldSet' && context.isAvailableFederationType('FieldSet')) {
|
|
5
|
+
context.reportError(new GraphQLError(`Invalid definition for type FieldSet: FieldSet should be a ScalarType but is defined as a ${receivedType}`, {
|
|
6
|
+
nodes: node,
|
|
7
|
+
extensions: { code: 'TYPE_DEFINITION_INVALID' },
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
ScalarTypeDefinition(node) {
|
|
13
|
+
if (node.name.value === 'FieldSet' && context.isAvailableFederationType('FieldSet')) {
|
|
14
|
+
context.markAsFederationDefinitionReplacement('FieldSet');
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
ObjectTypeDefinition(node) {
|
|
18
|
+
validateFieldSet(node, 'ObjectType');
|
|
19
|
+
},
|
|
20
|
+
InterfaceTypeDefinition(node) {
|
|
21
|
+
validateFieldSet(node, 'InterfaceType');
|
|
22
|
+
},
|
|
23
|
+
UnionTypeDefinition(node) {
|
|
24
|
+
validateFieldSet(node, 'UnionType');
|
|
25
|
+
},
|
|
26
|
+
EnumTypeDefinition(node) {
|
|
27
|
+
validateFieldSet(node, 'EnumType');
|
|
28
|
+
},
|
|
29
|
+
InputObjectTypeDefinition(node) {
|
|
30
|
+
validateFieldSet(node, 'InputObjectType');
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Kind } from 'graphql';
|
|
2
|
+
import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
|
|
3
|
+
export function InaccessibleRules(context) {
|
|
4
|
+
return {
|
|
5
|
+
DirectiveDefinition(node) {
|
|
6
|
+
validateDirectiveAgainstOriginal(node, 'inaccessible', context);
|
|
7
|
+
},
|
|
8
|
+
Directive(node, _key, _parent, paths, ancestors) {
|
|
9
|
+
if (!context.isAvailableFederationDirective('inaccessible', node)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const directivesKeyAt = paths.findIndex(path => path === 'directives');
|
|
13
|
+
if (directivesKeyAt === -1) {
|
|
14
|
+
throw new Error('Could not find "directives" key in ancestors');
|
|
15
|
+
}
|
|
16
|
+
const parent = ancestors[directivesKeyAt];
|
|
17
|
+
if (!parent) {
|
|
18
|
+
throw new Error('Could not find the node annotated with @inaccessible');
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(parent)) {
|
|
21
|
+
throw new Error('Expected parent to be a single node');
|
|
22
|
+
}
|
|
23
|
+
if (!('kind' in parent)) {
|
|
24
|
+
throw new Error('Expected parent to be a node');
|
|
25
|
+
}
|
|
26
|
+
switch (parent.kind) {
|
|
27
|
+
case Kind.SCALAR_TYPE_DEFINITION:
|
|
28
|
+
case Kind.SCALAR_TYPE_EXTENSION:
|
|
29
|
+
context.stateBuilder.scalarType.setInaccessible(parent.name.value);
|
|
30
|
+
break;
|
|
31
|
+
case Kind.FIELD_DEFINITION: {
|
|
32
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
33
|
+
if (!typeDef) {
|
|
34
|
+
throw new Error('Could not find the parent type of the field annotated with @inaccessible');
|
|
35
|
+
}
|
|
36
|
+
if (typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
37
|
+
typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) {
|
|
38
|
+
context.stateBuilder.interfaceType.field.setInaccessible(typeDef.name.value, parent.name.value);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
context.stateBuilder.objectType.field.setInaccessible(typeDef.name.value, parent.name.value);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case Kind.INPUT_VALUE_DEFINITION: {
|
|
46
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
47
|
+
if (!typeDef) {
|
|
48
|
+
throw new Error('Could not find the parent type of the field annotated with @inaccessible');
|
|
49
|
+
}
|
|
50
|
+
if (typeDef.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
|
|
51
|
+
typeDef.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
|
|
52
|
+
context.stateBuilder.inputObjectType.field.setInaccessible(typeDef.name.value, parent.name.value);
|
|
53
|
+
}
|
|
54
|
+
else if (typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
55
|
+
typeDef.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
56
|
+
const fieldDef = context.typeNodeInfo.getFieldDef();
|
|
57
|
+
if (!fieldDef) {
|
|
58
|
+
throw new Error('Could not find the parent field of the input value annotated with @inaccessible');
|
|
59
|
+
}
|
|
60
|
+
context.stateBuilder.objectType.field.arg.setInaccessible(typeDef.name.value, fieldDef.name.value, parent.name.value);
|
|
61
|
+
}
|
|
62
|
+
else if (typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
63
|
+
typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) {
|
|
64
|
+
const fieldDef = context.typeNodeInfo.getFieldDef();
|
|
65
|
+
if (!fieldDef) {
|
|
66
|
+
throw new Error('Could not find the parent field of the input value annotated with @inaccessible');
|
|
67
|
+
}
|
|
68
|
+
context.stateBuilder.interfaceType.field.arg.setInaccessible(typeDef.name.value, fieldDef.name.value, parent.name.value);
|
|
69
|
+
}
|
|
70
|
+
else if (typeDef.kind === Kind.DIRECTIVE_DEFINITION) {
|
|
71
|
+
context.stateBuilder.directive.arg.setInaccessible(typeDef.name.value, parent.name.value);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case Kind.OBJECT_TYPE_DEFINITION:
|
|
76
|
+
case Kind.OBJECT_TYPE_EXTENSION:
|
|
77
|
+
context.stateBuilder.objectType.setInaccessible(parent.name.value);
|
|
78
|
+
break;
|
|
79
|
+
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
80
|
+
case Kind.INTERFACE_TYPE_EXTENSION:
|
|
81
|
+
context.stateBuilder.interfaceType.setInaccessible(parent.name.value);
|
|
82
|
+
break;
|
|
83
|
+
case Kind.UNION_TYPE_DEFINITION:
|
|
84
|
+
case Kind.UNION_TYPE_EXTENSION:
|
|
85
|
+
context.stateBuilder.unionType.setInaccessible(parent.name.value);
|
|
86
|
+
break;
|
|
87
|
+
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
88
|
+
case Kind.INPUT_OBJECT_TYPE_EXTENSION:
|
|
89
|
+
context.stateBuilder.inputObjectType.setInaccessible(parent.name.value);
|
|
90
|
+
break;
|
|
91
|
+
case Kind.ENUM_TYPE_DEFINITION:
|
|
92
|
+
case Kind.ENUM_TYPE_EXTENSION:
|
|
93
|
+
context.stateBuilder.enumType.setInaccessible(parent.name.value);
|
|
94
|
+
break;
|
|
95
|
+
case Kind.ENUM_VALUE_DEFINITION: {
|
|
96
|
+
const enumValue = parent.name.value;
|
|
97
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
98
|
+
if (!typeDef) {
|
|
99
|
+
throw new Error('Could not find the parent type of the enum value annotated with @inaccessible');
|
|
100
|
+
}
|
|
101
|
+
context.stateBuilder.enumType.value.setInaccessible(typeDef.name.value, enumValue);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
context.stateBuilder.markSpecAsUsed('inaccessible');
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { GraphQLError, Kind } from 'graphql';
|
|
2
|
+
import { print } from '../../../../graphql/printer.js';
|
|
3
|
+
import { getFieldsArgument, parseFields, validateDirectiveAgainstOriginal, visitFields, } from '../../../helpers.js';
|
|
4
|
+
export function KeyRules(context) {
|
|
5
|
+
return {
|
|
6
|
+
DirectiveDefinition(node) {
|
|
7
|
+
validateDirectiveAgainstOriginal(node, 'key', context);
|
|
8
|
+
},
|
|
9
|
+
Directive(directiveNode) {
|
|
10
|
+
if (!context.isAvailableFederationDirective('key', directiveNode)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
14
|
+
if (!typeDef) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const typeCoordinate = typeDef.name.value;
|
|
18
|
+
const usedOnInterface = typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
19
|
+
typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION;
|
|
20
|
+
const usedOnObject = typeDef.kind === Kind.OBJECT_TYPE_DEFINITION || typeDef.kind === Kind.OBJECT_TYPE_EXTENSION;
|
|
21
|
+
if (!usedOnObject && !usedOnInterface) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (usedOnInterface &&
|
|
25
|
+
context.satisfiesVersionRange('> v1.0') &&
|
|
26
|
+
context.satisfiesVersionRange('< v2.3')) {
|
|
27
|
+
context.reportError(new GraphQLError(`Cannot use @key on interface "${typeCoordinate}": @key is not yet supported on interfaces`, {
|
|
28
|
+
nodes: directiveNode,
|
|
29
|
+
extensions: { code: 'KEY_UNSUPPORTED_ON_INTERFACE' },
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const fieldsArg = getFieldsArgument(directiveNode);
|
|
34
|
+
if (!fieldsArg) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const printedFieldsValue = print(fieldsArg.value);
|
|
38
|
+
if (fieldsArg.value.kind !== Kind.STRING) {
|
|
39
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): Invalid value for argument "fields": must be a string.`, {
|
|
40
|
+
nodes: directiveNode,
|
|
41
|
+
extensions: {
|
|
42
|
+
code: 'KEY_INVALID_FIELDS_TYPE',
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
let selectionSet;
|
|
48
|
+
try {
|
|
49
|
+
selectionSet = parseFields(fieldsArg.value.value);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof GraphQLError) {
|
|
53
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): ${error.message}`, {
|
|
54
|
+
nodes: directiveNode,
|
|
55
|
+
extensions: {
|
|
56
|
+
code: 'KEY_INVALID_FIELDS',
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (!selectionSet) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const knownObjectsAndInterfaces = context.getSubgraphObjectOrInterfaceTypes();
|
|
67
|
+
let isValid = true;
|
|
68
|
+
const fieldsUsedInKey = new Set();
|
|
69
|
+
visitFields({
|
|
70
|
+
context,
|
|
71
|
+
selectionSet,
|
|
72
|
+
typeDefinition: typeDef,
|
|
73
|
+
interceptField(info) {
|
|
74
|
+
if (info.typeDefinition.name.value === typeDef.name.value) {
|
|
75
|
+
fieldsUsedInKey.add(info.fieldName);
|
|
76
|
+
context.markAsKeyField(`${info.typeDefinition.name}.${info.fieldName}`);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
interceptUnknownField(info) {
|
|
80
|
+
isValid = false;
|
|
81
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): Cannot query field "${info.fieldName}" on type "${info.typeDefinition.name.value}" (the field should either be added to this subgraph or, if it should not be resolved by this subgraph, you need to add it to this subgraph with @external).`, { nodes: directiveNode, extensions: { code: 'KEY_INVALID_FIELDS' } }));
|
|
82
|
+
},
|
|
83
|
+
interceptDirective(info) {
|
|
84
|
+
isValid = false;
|
|
85
|
+
if (info.isKnown) {
|
|
86
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): cannot have directive applications in the @key(fields:) argument but found @${info.directiveName}.`, {
|
|
87
|
+
nodes: directiveNode,
|
|
88
|
+
extensions: { code: 'KEY_DIRECTIVE_IN_FIELDS_ARG' },
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): Unknown directive "@${info.directiveName}"`, {
|
|
93
|
+
nodes: directiveNode,
|
|
94
|
+
extensions: { code: 'KEY_INVALID_FIELDS' },
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
interceptArguments(info) {
|
|
99
|
+
isValid = false;
|
|
100
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): field ${info.typeDefinition.name.value}.${info.fieldName} cannot be included because it has arguments (fields with argument are not allowed in @key)`, { nodes: directiveNode, extensions: { code: 'KEY_FIELDS_HAS_ARGS' } }));
|
|
101
|
+
},
|
|
102
|
+
interceptInterfaceType(info) {
|
|
103
|
+
isValid = false;
|
|
104
|
+
context.reportError(new GraphQLError(`On type "${typeCoordinate}", for @key(fields: ${printedFieldsValue}): field "${info.typeDefinition.name.value}.${info.fieldName}" is a Interface type which is not allowed in @key`, { nodes: directiveNode, extensions: { code: 'KEY_FIELDS_SELECT_INVALID_TYPE' } }));
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
if (usedOnInterface) {
|
|
108
|
+
const expectedFieldsValue = fieldsArg.value.value;
|
|
109
|
+
knownObjectsAndInterfaces.forEach(def => {
|
|
110
|
+
if (def.interfaces?.some(i => i.name.value === typeDef.name.value)) {
|
|
111
|
+
let shouldError = true;
|
|
112
|
+
const keyDirectives = def.directives?.filter(d => context.isAvailableFederationDirective('key', d));
|
|
113
|
+
if (!!keyDirectives?.length) {
|
|
114
|
+
for (const keyDirective of keyDirectives) {
|
|
115
|
+
const fieldsArg = getFieldsArgument(keyDirective);
|
|
116
|
+
if (fieldsArg &&
|
|
117
|
+
fieldsArg.value.kind === Kind.STRING &&
|
|
118
|
+
fieldsArg.value.value === expectedFieldsValue) {
|
|
119
|
+
shouldError = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (shouldError && context.satisfiesVersionRange('> v1.0')) {
|
|
124
|
+
isValid = false;
|
|
125
|
+
context.reportError(new GraphQLError(`Key @key(fields: ${printedFieldsValue}) on interface type "${typeDef.name.value}" is missing on implementation type "${def.name.value}".`, {
|
|
126
|
+
nodes: directiveNode,
|
|
127
|
+
extensions: { code: 'INTERFACE_KEY_NOT_ON_IMPLEMENTATION' },
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (isValid) {
|
|
134
|
+
const resolvableArgValue = directiveNode.arguments?.find(arg => arg.name.value === 'resolvable' && arg.value.kind === Kind.BOOLEAN)?.value;
|
|
135
|
+
const resolvable = resolvableArgValue?.value ?? true;
|
|
136
|
+
if (usedOnInterface) {
|
|
137
|
+
context.stateBuilder.interfaceType.setKey(typeDef.name.value, fieldsArg.value.value, fieldsUsedInKey, resolvable);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
context.stateBuilder.objectType.setKey(typeDef.name.value, fieldsArg.value.value, fieldsUsedInKey, resolvable);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GraphQLError, Kind } from 'graphql';
|
|
2
|
+
import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
|
|
3
|
+
export function OverrideRules(context) {
|
|
4
|
+
return {
|
|
5
|
+
DirectiveDefinition(node) {
|
|
6
|
+
validateDirectiveAgainstOriginal(node, 'override', context);
|
|
7
|
+
},
|
|
8
|
+
Directive(node) {
|
|
9
|
+
if (!context.isAvailableFederationDirective('override', node)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const fieldDef = context.typeNodeInfo.getFieldDef();
|
|
13
|
+
const typeDef = context.typeNodeInfo.getTypeDef();
|
|
14
|
+
if (!fieldDef || !typeDef) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if ((typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
18
|
+
typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) &&
|
|
19
|
+
context.satisfiesVersionRange('>= v2.3')) {
|
|
20
|
+
context.reportError(new GraphQLError(`@override cannot be used on field "${typeDef.name.value}.${fieldDef.name.value}" on subgraph "${context.getSubgraphName()}": @override is not supported on interface type fields.`, { nodes: node, extensions: { code: 'OVERRIDE_ON_INTERFACE' } }));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const fromArg = node.arguments?.find(arg => arg.name.value === 'from');
|
|
24
|
+
if (!fromArg || fromArg.value.kind !== Kind.STRING) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!typeDef) {
|
|
28
|
+
throw new Error('Parent type not found but `@override` directive is present on a field.');
|
|
29
|
+
}
|
|
30
|
+
const conflictingDirectives = fieldDef.directives?.filter(directive => context.isAvailableFederationDirective('external', directive));
|
|
31
|
+
if (conflictingDirectives?.length) {
|
|
32
|
+
conflictingDirectives.forEach(directive => {
|
|
33
|
+
context.reportError(new GraphQLError(`@override cannot be used on field "${typeDef.name.value}.${fieldDef.name.value}" on subgraph "${context.getSubgraphName()}" since "${typeDef.name.value}.${fieldDef.name.value}" on "${context.getSubgraphName()}" is marked with directive "@${directive.name.value}"`, {
|
|
34
|
+
extensions: {
|
|
35
|
+
code: 'OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE',
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (fromArg.value.value === context.getSubgraphName()) {
|
|
41
|
+
context.reportError(new GraphQLError(`Source and destination subgraphs "${fromArg.value.value}" are the same for overridden field "${typeDef.name.value}.${fieldDef.name.value}"`, { nodes: node, extensions: { code: 'OVERRIDE_FROM_SELF_ERROR' } }));
|
|
42
|
+
}
|
|
43
|
+
if (typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
44
|
+
typeDef.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
45
|
+
context.stateBuilder.objectType.field.setOverride(typeDef.name.value, fieldDef.name.value, fromArg.value.value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
context.stateBuilder.interfaceType.field.setOverride(typeDef.name.value, fieldDef.name.value, fromArg.value.value);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { GraphQLError, Kind } from 'graphql';
|
|
2
|
+
import { print } from '../../../../graphql/printer.js';
|
|
3
|
+
import { getFieldsArgument, namedTypeFromTypeNode, parseFields, validateDirectiveAgainstOriginal, visitFields, } from '../../../helpers.js';
|
|
4
|
+
export function ProvidesRules(context) {
|
|
5
|
+
return {
|
|
6
|
+
DirectiveDefinition(node) {
|
|
7
|
+
validateDirectiveAgainstOriginal(node, 'provides', context);
|
|
8
|
+
},
|
|
9
|
+
Directive(directiveNode) {
|
|
10
|
+
if (!context.isAvailableFederationDirective('provides', directiveNode)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const annotatedType = context.typeNodeInfo.getTypeDef();
|
|
14
|
+
const annotatedField = context.typeNodeInfo.getFieldDef();
|
|
15
|
+
if (!annotatedType || !annotatedField) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const fieldCoordinate = `${annotatedType.name.value}.${annotatedField.name.value}`;
|
|
19
|
+
const usedOnInterface = annotatedType.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
20
|
+
annotatedType?.kind === Kind.INTERFACE_TYPE_EXTENSION;
|
|
21
|
+
const knownObjectsAndInterfaces = context.getSubgraphObjectOrInterfaceTypes();
|
|
22
|
+
const outputType = namedTypeFromTypeNode(annotatedField.type);
|
|
23
|
+
const targetType = knownObjectsAndInterfaces.get(outputType.name.value);
|
|
24
|
+
if (!targetType) {
|
|
25
|
+
context.reportError(new GraphQLError(`Invalid @provides directive on field "${fieldCoordinate}": field has type "${print(annotatedField.type)}" which is not a Composite Type`, {
|
|
26
|
+
nodes: directiveNode,
|
|
27
|
+
extensions: {
|
|
28
|
+
code: 'PROVIDES_ON_NON_OBJECT_FIELD',
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (usedOnInterface) {
|
|
34
|
+
context.reportError(new GraphQLError(`Cannot use @provides on field "${fieldCoordinate}" of parent type "${annotatedType.name.value}": @provides is not yet supported within interfaces`, {
|
|
35
|
+
nodes: directiveNode,
|
|
36
|
+
extensions: { code: 'PROVIDES_UNSUPPORTED_ON_INTERFACE' },
|
|
37
|
+
}));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const fieldsArg = getFieldsArgument(directiveNode);
|
|
41
|
+
if (!fieldsArg) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const printedFieldsValue = print(fieldsArg.value);
|
|
45
|
+
if (fieldsArg.value.kind !== Kind.STRING) {
|
|
46
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Invalid value for argument "fields": must be a string.`, {
|
|
47
|
+
nodes: directiveNode,
|
|
48
|
+
extensions: {
|
|
49
|
+
code: 'PROVIDES_INVALID_FIELDS_TYPE',
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let selectionSet;
|
|
55
|
+
try {
|
|
56
|
+
selectionSet = parseFields(fieldsArg.value.value);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof GraphQLError) {
|
|
60
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): ${error.message}`, {
|
|
61
|
+
nodes: directiveNode,
|
|
62
|
+
extensions: {
|
|
63
|
+
code: 'PROVIDES_INVALID_FIELDS',
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
if (!selectionSet) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let isValid = true;
|
|
74
|
+
visitFields({
|
|
75
|
+
context,
|
|
76
|
+
selectionSet,
|
|
77
|
+
typeDefinition: targetType,
|
|
78
|
+
interceptUnknownField(info) {
|
|
79
|
+
isValid = false;
|
|
80
|
+
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' } }));
|
|
81
|
+
},
|
|
82
|
+
interceptDirective(info) {
|
|
83
|
+
isValid = false;
|
|
84
|
+
if (info.isKnown) {
|
|
85
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): cannot have directive applications in the @provides(fields:) argument but found @${info.directiveName}.`, {
|
|
86
|
+
nodes: directiveNode,
|
|
87
|
+
extensions: { code: 'PROVIDES_DIRECTIVE_IN_FIELDS_ARG' },
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): Unknown directive "@${info.directiveName}" in selection`, {
|
|
92
|
+
nodes: directiveNode,
|
|
93
|
+
extensions: { code: 'PROVIDES_INVALID_FIELDS' },
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
interceptArguments(info) {
|
|
98
|
+
isValid = false;
|
|
99
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): field ${info.typeDefinition.name.value}.${info.fieldName} cannot be included because it has arguments (fields with argument are not allowed in @provides)`, { nodes: directiveNode, extensions: { code: 'PROVIDES_FIELDS_HAS_ARGS' } }));
|
|
100
|
+
},
|
|
101
|
+
interceptNonExternalField(info) {
|
|
102
|
+
isValid = false;
|
|
103
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): field "${info.typeDefinition.name.value}.${info.fieldName}" should not be part of a @provides since it is already provided by this subgraph (it is not marked @external)`, {
|
|
104
|
+
extensions: {
|
|
105
|
+
code: 'PROVIDES_FIELDS_MISSING_EXTERNAL',
|
|
106
|
+
},
|
|
107
|
+
}));
|
|
108
|
+
},
|
|
109
|
+
interceptExternalField(info) {
|
|
110
|
+
if (context.satisfiesVersionRange('< v2.0')) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const keyDirectives = info.typeDefinition.directives?.filter(directive => context.isAvailableFederationDirective('key', directive));
|
|
114
|
+
if (!keyDirectives?.length) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let interceptedFieldIsPrimaryKeyFromExtension = false;
|
|
118
|
+
for (const keyDirective of keyDirectives) {
|
|
119
|
+
if (interceptedFieldIsPrimaryKeyFromExtension) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
const fieldsArg = keyDirective.arguments?.find(arg => arg.name.value === 'fields' && arg.value.kind === Kind.STRING);
|
|
123
|
+
if (fieldsArg) {
|
|
124
|
+
const keyFields = parseFields(fieldsArg.value.value);
|
|
125
|
+
if (keyFields) {
|
|
126
|
+
visitFields({
|
|
127
|
+
context,
|
|
128
|
+
selectionSet: keyFields,
|
|
129
|
+
typeDefinition: info.typeDefinition,
|
|
130
|
+
interceptField(keyFieldInfo) {
|
|
131
|
+
if (keyFieldInfo.typeDefinition.name.value === info.typeDefinition.name.value &&
|
|
132
|
+
keyFieldInfo.fieldName === info.fieldName) {
|
|
133
|
+
const isInterfaceType = keyFieldInfo.typeDefinition.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
134
|
+
keyFieldInfo.typeDefinition.kind === Kind.INTERFACE_TYPE_EXTENSION;
|
|
135
|
+
if (isInterfaceType) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const isExtension = keyFieldInfo.typeDefinition.kind === Kind.OBJECT_TYPE_EXTENSION ||
|
|
139
|
+
keyFieldInfo.typeDefinition.kind === Kind.INTERFACE_TYPE_EXTENSION ||
|
|
140
|
+
keyFieldInfo.typeDefinition.directives?.some(directive => context.isAvailableFederationDirective('extends', directive));
|
|
141
|
+
if (isExtension) {
|
|
142
|
+
interceptedFieldIsPrimaryKeyFromExtension = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (info.typeDefinition.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
146
|
+
info.typeDefinition.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
147
|
+
context.stateBuilder.objectType.field.markAsProvided(info.typeDefinition.name.value, info.fieldName);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (interceptedFieldIsPrimaryKeyFromExtension) {
|
|
155
|
+
isValid = false;
|
|
156
|
+
context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @provides(fields: ${printedFieldsValue}): field "${info.typeDefinition.name.value}.${info.fieldName}" should not be part of a @provides since it is already "effectively" provided by this subgraph (while it is marked @external, it is a @key field of an extension type, which are not internally considered external for historical/backward compatibility reasons)`, {
|
|
157
|
+
extensions: {
|
|
158
|
+
code: 'PROVIDES_FIELDS_MISSING_EXTERNAL',
|
|
159
|
+
},
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
if (isValid) {
|
|
165
|
+
context.stateBuilder.objectType.field.setProvides(annotatedType.name.value, annotatedField.name.value, fieldsArg.value.value);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|