@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,245 @@
|
|
|
1
|
+
import { Kind, stripIgnoredCharacters, } from 'graphql';
|
|
2
|
+
import { print } from '../graphql/printer.js';
|
|
3
|
+
import { mergeLinks } from '../specifications/link.js';
|
|
4
|
+
import { parseFields } from '../subgraph/helpers.js';
|
|
5
|
+
import { createJoinGraphEnumTypeNode } from './composition/ast.js';
|
|
6
|
+
import { directiveBuilder } from './composition/directive.js';
|
|
7
|
+
import { enumTypeBuilder } from './composition/enum-type.js';
|
|
8
|
+
import { inputObjectTypeBuilder } from './composition/input-object-type.js';
|
|
9
|
+
import { interfaceTypeBuilder } from './composition/interface-type.js';
|
|
10
|
+
import { objectTypeBuilder } from './composition/object-type.js';
|
|
11
|
+
import { scalarTypeBuilder } from './composition/scalar-type.js';
|
|
12
|
+
import { unionTypeBuilder } from './composition/union-type.js';
|
|
13
|
+
export function createSupergraphStateBuilder() {
|
|
14
|
+
const state = {
|
|
15
|
+
graphs: new Map(),
|
|
16
|
+
scalarTypes: new Map(),
|
|
17
|
+
objectTypes: new Map(),
|
|
18
|
+
interfaceTypes: new Map(),
|
|
19
|
+
unionTypes: new Map(),
|
|
20
|
+
enumTypes: new Map(),
|
|
21
|
+
inputObjectTypes: new Map(),
|
|
22
|
+
directives: new Map(),
|
|
23
|
+
links: [],
|
|
24
|
+
specs: {
|
|
25
|
+
tag: false,
|
|
26
|
+
inaccessible: false,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const directive = directiveBuilder();
|
|
30
|
+
const scalarType = scalarTypeBuilder();
|
|
31
|
+
const enumType = enumTypeBuilder();
|
|
32
|
+
const inputObjectType = inputObjectTypeBuilder();
|
|
33
|
+
const interfaceType = interfaceTypeBuilder();
|
|
34
|
+
const objectType = objectTypeBuilder();
|
|
35
|
+
const unionType = unionTypeBuilder();
|
|
36
|
+
return {
|
|
37
|
+
addGraph(graph) {
|
|
38
|
+
if (state.graphs.has(graph.id)) {
|
|
39
|
+
throw new Error(`Graph with ID "${graph.id}" already exists`);
|
|
40
|
+
}
|
|
41
|
+
state.graphs.set(graph.id, {
|
|
42
|
+
id: graph.id,
|
|
43
|
+
name: graph.name,
|
|
44
|
+
url: graph.url,
|
|
45
|
+
version: graph.version,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
getGraph(id) {
|
|
49
|
+
return state.graphs.get(id);
|
|
50
|
+
},
|
|
51
|
+
visitSubgraphState(subgraphState) {
|
|
52
|
+
for (const link of subgraphState.links) {
|
|
53
|
+
state.links.push(linkWithGraph(link, subgraphState.graph.id));
|
|
54
|
+
}
|
|
55
|
+
if (subgraphState.specs.tag) {
|
|
56
|
+
state.specs.tag = true;
|
|
57
|
+
}
|
|
58
|
+
if (subgraphState.specs.inaccessible) {
|
|
59
|
+
state.specs.inaccessible = true;
|
|
60
|
+
}
|
|
61
|
+
for (const [typeName, type] of subgraphState.types) {
|
|
62
|
+
switch (type.kind) {
|
|
63
|
+
case 'OBJECT': {
|
|
64
|
+
objectType.visitSubgraphState(subgraphState.graph, state.objectTypes, typeName, type);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'INTERFACE': {
|
|
68
|
+
interfaceType.visitSubgraphState(subgraphState.graph, state.interfaceTypes, typeName, type);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 'UNION': {
|
|
72
|
+
unionType.visitSubgraphState(subgraphState.graph, state.unionTypes, typeName, type);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'ENUM': {
|
|
76
|
+
enumType.visitSubgraphState(subgraphState.graph, state.enumTypes, typeName, type);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'INPUT_OBJECT': {
|
|
80
|
+
inputObjectType.visitSubgraphState(subgraphState.graph, state.inputObjectTypes, typeName, type);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'DIRECTIVE': {
|
|
84
|
+
directive.visitSubgraphState(subgraphState.graph, state.directives, typeName, type);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'SCALAR': {
|
|
88
|
+
scalarType.visitSubgraphState(subgraphState.graph, state.scalarTypes, typeName, type);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
getSupergraphState() {
|
|
95
|
+
return state;
|
|
96
|
+
},
|
|
97
|
+
links() {
|
|
98
|
+
return mergeLinks(state.links);
|
|
99
|
+
},
|
|
100
|
+
build() {
|
|
101
|
+
const transformFields = createFieldsTransformer(state);
|
|
102
|
+
const numberOfExpectedNodes = state.directives.size +
|
|
103
|
+
state.scalarTypes.size +
|
|
104
|
+
state.objectTypes.size +
|
|
105
|
+
state.interfaceTypes.size +
|
|
106
|
+
state.unionTypes.size +
|
|
107
|
+
state.enumTypes.size +
|
|
108
|
+
state.inputObjectTypes.size +
|
|
109
|
+
1;
|
|
110
|
+
const nodes = new Array(numberOfExpectedNodes);
|
|
111
|
+
let i = 0;
|
|
112
|
+
nodes[i++] = createJoinGraphEnumTypeNode(Array.from(state.graphs.values()).map(graph => ({
|
|
113
|
+
name: graph.name,
|
|
114
|
+
enumValue: graph.id,
|
|
115
|
+
url: graph.url ?? '',
|
|
116
|
+
})));
|
|
117
|
+
for (const directiveState of state.directives.values()) {
|
|
118
|
+
nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs);
|
|
119
|
+
}
|
|
120
|
+
for (const scalarTypeState of state.scalarTypes.values()) {
|
|
121
|
+
nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs);
|
|
122
|
+
}
|
|
123
|
+
for (const objectTypeState of state.objectTypes.values()) {
|
|
124
|
+
nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs);
|
|
125
|
+
}
|
|
126
|
+
for (const interfaceTypeState of state.interfaceTypes.values()) {
|
|
127
|
+
nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs);
|
|
128
|
+
}
|
|
129
|
+
for (const unionTypeState of state.unionTypes.values()) {
|
|
130
|
+
nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs);
|
|
131
|
+
}
|
|
132
|
+
for (const enumTypeState of state.enumTypes.values()) {
|
|
133
|
+
nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs);
|
|
134
|
+
}
|
|
135
|
+
for (const inputObjectTypeState of state.inputObjectTypes.values()) {
|
|
136
|
+
nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs);
|
|
137
|
+
}
|
|
138
|
+
return nodes;
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function linkWithGraph(link, graph) {
|
|
143
|
+
link.graph = graph;
|
|
144
|
+
return link;
|
|
145
|
+
}
|
|
146
|
+
function visitSelectionSetNode(selectionSet, locations, currentPath) {
|
|
147
|
+
for (const selection of selectionSet.selections) {
|
|
148
|
+
if (selection.kind === Kind.FIELD) {
|
|
149
|
+
if (selection.selectionSet) {
|
|
150
|
+
visitSelectionSetNode(selection.selectionSet, locations, currentPath.concat(selection.name.value));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
locations.add(currentPath.concat(selection.name.value).join('.'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function createFieldsSet(selectionSet) {
|
|
159
|
+
const locations = new Set();
|
|
160
|
+
visitSelectionSetNode(selectionSet, locations, []);
|
|
161
|
+
return locations;
|
|
162
|
+
}
|
|
163
|
+
function filterSelectionSetNode(selectionSet, removableFields, currentPath) {
|
|
164
|
+
const fieldsToDelete = [];
|
|
165
|
+
for (const selection of selectionSet.selections) {
|
|
166
|
+
if (selection.kind === Kind.FIELD) {
|
|
167
|
+
if (selection.selectionSet) {
|
|
168
|
+
filterSelectionSetNode(selection.selectionSet, removableFields, currentPath + '.' + selection.name.value);
|
|
169
|
+
if (selectionSet.selections.length === 0) {
|
|
170
|
+
fieldsToDelete.push(selection.name.value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const lookingFor = currentPath === '' ? selection.name.value : currentPath + '.' + selection.name.value;
|
|
175
|
+
if (removableFields.has(lookingFor)) {
|
|
176
|
+
fieldsToDelete.push(selection.name.value);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const fieldName of fieldsToDelete) {
|
|
182
|
+
selectionSet.selections = selectionSet.selections.filter(selection => selection.kind === Kind.FIELD && selection.name.value === fieldName ? false : true);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function createFieldsTransformer(state) {
|
|
186
|
+
function transformFields(removableFields, fields) {
|
|
187
|
+
const parsedFields = parseFields(fields);
|
|
188
|
+
if (!parsedFields) {
|
|
189
|
+
return fields;
|
|
190
|
+
}
|
|
191
|
+
filterSelectionSetNode(parsedFields, removableFields, '');
|
|
192
|
+
const printed = stripIgnoredCharacters(print(parsedFields));
|
|
193
|
+
return printed.replace(/^\{/, '').replace(/\}$/, '');
|
|
194
|
+
}
|
|
195
|
+
function mergeKeyFieldsCollection(fieldsCollection) {
|
|
196
|
+
const fieldsSets = [];
|
|
197
|
+
for (const fields of fieldsCollection) {
|
|
198
|
+
const parsedFields = parseFields(fields);
|
|
199
|
+
if (!parsedFields) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
fieldsSets.push(createFieldsSet(parsedFields));
|
|
203
|
+
}
|
|
204
|
+
let commonFields;
|
|
205
|
+
for (const fieldsSet of fieldsSets) {
|
|
206
|
+
if (!commonFields) {
|
|
207
|
+
commonFields = fieldsSet;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
for (const field of commonFields) {
|
|
211
|
+
if (!fieldsSet.has(field)) {
|
|
212
|
+
commonFields.delete(field);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return commonFields ?? new Set();
|
|
217
|
+
}
|
|
218
|
+
return function visitTypeState(typeState) {
|
|
219
|
+
for (const [_, fieldState] of typeState.fields) {
|
|
220
|
+
for (const [graphId, fieldStateInGraph] of fieldState.byGraph) {
|
|
221
|
+
if (fieldStateInGraph.requires) {
|
|
222
|
+
const keyFields = mergeKeyFieldsCollection(typeState.byGraph.get(graphId).keys.map(key => key.fields));
|
|
223
|
+
const newRequires = transformFields(keyFields, fieldStateInGraph.requires);
|
|
224
|
+
fieldStateInGraph.requires = newRequires.trim().length === 0 ? null : newRequires;
|
|
225
|
+
}
|
|
226
|
+
if (fieldStateInGraph.provides) {
|
|
227
|
+
const referencedTypeName = fieldState.type.replace(/[!\[\]]+/g, '');
|
|
228
|
+
const referencedType = state.objectTypes.get(referencedTypeName) ??
|
|
229
|
+
state.interfaceTypes.get(referencedTypeName);
|
|
230
|
+
if (!referencedType) {
|
|
231
|
+
throw new Error('Referenced type not found: ' + referencedTypeName);
|
|
232
|
+
}
|
|
233
|
+
const referencedTypeInGraph = referencedType.byGraph.get(graphId);
|
|
234
|
+
const keyFields = referencedTypeInGraph.extension === true
|
|
235
|
+
?
|
|
236
|
+
mergeKeyFieldsCollection(referencedTypeInGraph.keys.map(key => key.fields))
|
|
237
|
+
:
|
|
238
|
+
new Set();
|
|
239
|
+
fieldStateInGraph.provides = transformFields(keyFields, fieldStateInGraph.provides);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return typeState;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function DefaultValueUsesInaccessibleRule(context, supergraph) {
|
|
3
|
+
return {
|
|
4
|
+
InputObjectTypeField(inputObjectState, fieldState) {
|
|
5
|
+
if (typeof fieldState.defaultValue !== 'string') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
detectInaccessibleDefaultValue(context, () => `${inputObjectState.name}.${fieldState.name}`, fieldState.type, fieldState.defaultValue, supergraph.enumTypes);
|
|
9
|
+
},
|
|
10
|
+
ObjectTypeFieldArg(objectState, fieldState, argState) {
|
|
11
|
+
if (typeof argState.defaultValue !== 'string') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
detectInaccessibleDefaultValue(context, () => `${objectState.name}.${fieldState.name}(${argState.name}:)`, argState.type, argState.defaultValue, supergraph.enumTypes);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function detectInaccessibleDefaultValue(context, schemaCoordinate, outputType, defaultValue, enumTypes) {
|
|
19
|
+
const outputTypeName = outputType.replace(/[\[\]\!]+/g, '');
|
|
20
|
+
const enumType = enumTypes.get(outputTypeName);
|
|
21
|
+
if (!enumType) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (enumType.inaccessible === true || enumType.values.get(defaultValue)?.inaccessible === true) {
|
|
25
|
+
context.reportError(new GraphQLError(`Enum value "${outputTypeName}.${defaultValue}" is @inaccessible but is used in the default value of "${schemaCoordinate()}", which is in the API schema.`, {
|
|
26
|
+
extensions: {
|
|
27
|
+
code: 'DEFAULT_VALUE_USES_INACCESSIBLE',
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function DirectiveCompositionRule(context, supergraph) {
|
|
3
|
+
const linkIdentityToMajorVersion = new Map();
|
|
4
|
+
const appliedDirectiveToGraphs = new Map();
|
|
5
|
+
const appliedDirectiveToLinkIdentities = new Map();
|
|
6
|
+
for (const link of supergraph.links) {
|
|
7
|
+
if (link.version) {
|
|
8
|
+
const major = parseInt(link.version.replace('v', '').split('.')[0]);
|
|
9
|
+
const existing = linkIdentityToMajorVersion.get(link.identity);
|
|
10
|
+
if (typeof existing === 'number' && existing !== major) {
|
|
11
|
+
context.reportError(new GraphQLError(`Core feature "${link.identity}" requested to be merged has major version mismatch across subgraphs`, {
|
|
12
|
+
extensions: {
|
|
13
|
+
code: 'DIRECTIVE_COMPOSITION_ERROR',
|
|
14
|
+
versions: [existing, major],
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
linkIdentityToMajorVersion.set(link.identity, major);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const im of link.imports) {
|
|
23
|
+
if (im.kind === 'directive') {
|
|
24
|
+
const appliedName = im.alias ?? im.name;
|
|
25
|
+
const originalName = im.name;
|
|
26
|
+
const appliedDirectiveToGraph = appliedDirectiveToGraphs.get(originalName);
|
|
27
|
+
if (appliedDirectiveToGraph) {
|
|
28
|
+
const graphs = appliedDirectiveToGraph.get(appliedName);
|
|
29
|
+
if (graphs) {
|
|
30
|
+
graphs.add(link.graph);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
appliedDirectiveToGraph.set(appliedName, new Set([link.graph]));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
appliedDirectiveToGraphs.set(originalName, new Map([[appliedName, new Set([link.graph])]]));
|
|
38
|
+
}
|
|
39
|
+
const appliedDirectiveToLinkIdentity = appliedDirectiveToLinkIdentities.get(appliedName);
|
|
40
|
+
if (appliedDirectiveToLinkIdentity) {
|
|
41
|
+
appliedDirectiveToLinkIdentity.add(link.identity);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
appliedDirectiveToLinkIdentities.set(appliedName, new Set([link.identity]));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [originalDirectiveName, appliedNames] of appliedDirectiveToGraphs) {
|
|
50
|
+
if (appliedNames.size > 1) {
|
|
51
|
+
const groups = Array.from(appliedNames.entries()).map(([appliedName, graphs]) => {
|
|
52
|
+
const plural = graphs.size > 1 ? 's' : '';
|
|
53
|
+
return `name "${appliedName}" in subgraph${plural} "${Array.from(graphs)
|
|
54
|
+
.map(context.graphIdToName)
|
|
55
|
+
.join('", "')}"`;
|
|
56
|
+
});
|
|
57
|
+
const [first, second, ...rest] = groups;
|
|
58
|
+
context.reportError(new GraphQLError(`Composed directive "${originalDirectiveName}" has incompatible name across subgraphs: it has ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}. Composed directive must have the same name across all subgraphs.`, {
|
|
59
|
+
extensions: {
|
|
60
|
+
code: 'DIRECTIVE_COMPOSITION_ERROR',
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const [directiveName, linkIdentities] of appliedDirectiveToLinkIdentities) {
|
|
66
|
+
if (linkIdentities.size > 1) {
|
|
67
|
+
context.reportError(new GraphQLError(`Composed directive "${directiveName}" is not linked by the same core feature in every subgraph`, {
|
|
68
|
+
extensions: {
|
|
69
|
+
code: 'DIRECTIVE_COMPOSITION_ERROR',
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
Directive(directiveState) {
|
|
76
|
+
if (directiveState.byGraph.size === 1) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const graphsSize = directiveState.byGraph.size;
|
|
80
|
+
const hasLocationDefinedInAllGraphs = Array.from(directiveState.locations).some(location => {
|
|
81
|
+
let count = 0;
|
|
82
|
+
for (const [_, graphState] of directiveState.byGraph) {
|
|
83
|
+
if (graphState.locations.has(location)) {
|
|
84
|
+
count++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return count === graphsSize;
|
|
88
|
+
});
|
|
89
|
+
if (!hasLocationDefinedInAllGraphs) {
|
|
90
|
+
context.reportError(new GraphQLError(`Directive "@${directiveState.name}" has no shared locations between subgraphs`));
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function EnumValuesRule(context) {
|
|
3
|
+
return {
|
|
4
|
+
EnumType(enumTypeState) {
|
|
5
|
+
if (enumTypeState.referencedByInputType && enumTypeState.referencedByOutputType) {
|
|
6
|
+
const missingValues = [];
|
|
7
|
+
const total = enumTypeState.byGraph.size;
|
|
8
|
+
for (const [valueName, valueState] of enumTypeState.values) {
|
|
9
|
+
if (valueState.byGraph.size !== total) {
|
|
10
|
+
missingValues.push(valueName);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (missingValues.length === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const exampleInputType = `(for example, as type of "${enumTypeState.inputTypeReferences.values().next().value}")`;
|
|
17
|
+
const exampleOutputType = `(for example, as type of "${enumTypeState.outputTypeReferences.values().next().value}")`;
|
|
18
|
+
for (const missingValue of missingValues) {
|
|
19
|
+
const valueState = enumTypeState.values.get(missingValue);
|
|
20
|
+
const definedIn = Array.from(valueState.byGraph.keys()).map(context.graphIdToName);
|
|
21
|
+
const notDefinedIn = Array.from(enumTypeState.byGraph.keys())
|
|
22
|
+
.filter(key => !valueState.byGraph.has(key))
|
|
23
|
+
.map(context.graphIdToName);
|
|
24
|
+
const msg = [
|
|
25
|
+
`Enum type "${enumTypeState.name}" is used as both input type ${exampleInputType} and output type ${exampleOutputType},`,
|
|
26
|
+
`but value "${missingValue}" is not defined in all the subgraphs defining "${enumTypeState.name}":`,
|
|
27
|
+
`"${missingValue}" is defined in subgraph${definedIn.length > 1 ? 's' : ''} "${definedIn.join('", "')}"`,
|
|
28
|
+
`but not in subgraph${notDefinedIn.length > 1 ? 's' : ''} "${notDefinedIn.join('", "')}"`,
|
|
29
|
+
].join(' ');
|
|
30
|
+
context.reportError(new GraphQLError(msg, {
|
|
31
|
+
extensions: {
|
|
32
|
+
code: 'ENUM_VALUE_MISMATCH',
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (enumTypeState.referencedByInputType) {
|
|
38
|
+
const valuesInCommon = [];
|
|
39
|
+
const total = enumTypeState.byGraph.size;
|
|
40
|
+
for (const [valueName, valueState] of enumTypeState.values) {
|
|
41
|
+
if (valueState.byGraph.size === total) {
|
|
42
|
+
valuesInCommon.push(valueName);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (valuesInCommon.length === 0) {
|
|
46
|
+
context.reportError(new GraphQLError(`None of the values of enum type "${enumTypeState.name}" are defined consistently in all the subgraphs defining that type. As only values common to all subgraphs are merged, this would result in an empty type.`, {
|
|
47
|
+
extensions: {
|
|
48
|
+
code: 'EMPTY_MERGED_ENUM_TYPE',
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function ExtensionWithBaseRule(context) {
|
|
3
|
+
return {
|
|
4
|
+
ObjectType(objectTypeState) {
|
|
5
|
+
if (objectTypeState.name === 'Query' ||
|
|
6
|
+
objectTypeState.name === 'Mutation' ||
|
|
7
|
+
objectTypeState.name === 'Subscription') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!objectTypeState.hasDefinition) {
|
|
11
|
+
if (objectTypeState.byGraph.size > 1 &&
|
|
12
|
+
Array.from(objectTypeState.byGraph).every(([graphId, meta]) => context.subgraphStates.get(graphId).version === 'v1.0'
|
|
13
|
+
? meta.extensionType === '@extends'
|
|
14
|
+
: false)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
objectTypeState.byGraph.forEach((_, graph) => {
|
|
18
|
+
context.reportError(new GraphQLError(`[${context.graphIdToName(graph)}] Type "${objectTypeState.name}" is an extension type, but there is no type definition for "${objectTypeState.name}" in any subgraph.`, {
|
|
19
|
+
extensions: {
|
|
20
|
+
code: 'EXTENSION_WITH_NO_BASE',
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function ExternalArgumentMissingRule(context) {
|
|
3
|
+
return {
|
|
4
|
+
ObjectTypeFieldArg(objectState, fieldState, argState) {
|
|
5
|
+
if (argState.type.endsWith('!')) {
|
|
6
|
+
if (argState.byGraph.size === 1 && fieldState.byGraph.size === argState.byGraph.size) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (fieldState.byGraph.size === argState.byGraph.size) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const graphsWithRequiredArg = Array.from(argState.byGraph)
|
|
13
|
+
.filter(([graph, arg]) => arg.type.endsWith('!') && fieldState.byGraph.get(graph)?.external !== true)
|
|
14
|
+
.map(([graph]) => graph);
|
|
15
|
+
const externalGraphsWithoutArg = Array.from(fieldState.byGraph.keys()).filter(graph => !argState.byGraph.has(graph) && fieldState.byGraph.get(graph)?.external === true);
|
|
16
|
+
const requiredIn = `subgraph${graphsWithRequiredArg.length > 1 ? 's' : ''} "${graphsWithRequiredArg.map(context.graphIdToName).join('", "')}"`;
|
|
17
|
+
const missingIn = `subgraph${externalGraphsWithoutArg.length > 1 ? 's' : ''} "${externalGraphsWithoutArg.map(context.graphIdToName).join('", "')}"`;
|
|
18
|
+
const fieldCoordinate = `${objectState.name}.${fieldState.name}`;
|
|
19
|
+
const argCoordinate = `${objectState.name}.${fieldState.name}(${argState.name}:)`;
|
|
20
|
+
context.reportError(new GraphQLError(`Field "${fieldCoordinate}" is missing argument "${argCoordinate}" in some subgraphs where it is marked @external: argument "${argCoordinate}" is declared in ${requiredIn} but not in ${missingIn} (where "${fieldCoordinate}" is @external)`, {
|
|
21
|
+
extensions: {
|
|
22
|
+
code: 'EXTERNAL_ARGUMENT_MISSING',
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { andList } from '../../../utils/format.js';
|
|
3
|
+
export function ExternalMissingOnBaseRule(context) {
|
|
4
|
+
return {
|
|
5
|
+
ObjectType(objectTypeState) {
|
|
6
|
+
if (Array.from(objectTypeState.byGraph).every(([_, stateInGraph]) => stateInGraph.external === true)) {
|
|
7
|
+
const subgraphs = objectTypeState.byGraph.size > 1 ? 'subgraphs' : 'subgraph';
|
|
8
|
+
context.reportError(new GraphQLError(`Type "${objectTypeState.name}" is marked @external on all the subgraphs in which it is listed (${subgraphs} ${(andList(Array.from(objectTypeState.byGraph.keys()).map(graphId => context.graphIdToName(graphId))),
|
|
9
|
+
true,
|
|
10
|
+
'"')}).`, {
|
|
11
|
+
extensions: {
|
|
12
|
+
code: 'EXTERNAL_MISSING_ON_BASE',
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
ObjectTypeField(objectState, fieldState) {
|
|
18
|
+
if (Array.from(fieldState.byGraph).every(([graphId, stateInGraph]) => {
|
|
19
|
+
const graphVersion = context.subgraphStates.get(graphId).version;
|
|
20
|
+
if (stateInGraph.usedAsKey) {
|
|
21
|
+
if (graphVersion === 'v1.0') {
|
|
22
|
+
return stateInGraph.external && !objectState.byGraph.get(graphId).extension;
|
|
23
|
+
}
|
|
24
|
+
return (stateInGraph.external === true &&
|
|
25
|
+
objectState.byGraph.get(graphId).extensionType !== '@extends');
|
|
26
|
+
}
|
|
27
|
+
if (graphVersion === 'v1.0') {
|
|
28
|
+
if (stateInGraph.external === true && stateInGraph.used) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return stateInGraph.external === true;
|
|
34
|
+
})) {
|
|
35
|
+
const subgraphs = fieldState.byGraph.size > 1 ? 'subgraphs' : 'subgraph';
|
|
36
|
+
context.reportError(new GraphQLError(`Field "${objectState.name}.${fieldState.name}" is marked @external on all the subgraphs in which it is listed (${subgraphs} ${andList(Array.from(fieldState.byGraph.keys()).map(context.graphIdToName), true, '"')}).`, {
|
|
37
|
+
extensions: {
|
|
38
|
+
code: 'EXTERNAL_MISSING_ON_BASE',
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { andList } from '../../../utils/format.js';
|
|
3
|
+
import { isRealExtension } from '../../composition/object-type.js';
|
|
4
|
+
export function ExternalTypeMismatchRule(context) {
|
|
5
|
+
return {
|
|
6
|
+
ObjectTypeField(objectTypeState, fieldState) {
|
|
7
|
+
if (fieldState.usedAsKey) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const groupByType = new Map();
|
|
11
|
+
const graphsWithEqualType = [];
|
|
12
|
+
for (const [graphId, field] of fieldState.byGraph) {
|
|
13
|
+
const graphVersion = context.subgraphStates.get(graphId).version;
|
|
14
|
+
const isExternal = graphVersion === 'v1.0'
|
|
15
|
+
? field.external && isRealExtension(objectTypeState.byGraph.get(graphId), graphVersion)
|
|
16
|
+
: field.external;
|
|
17
|
+
if (!isExternal) {
|
|
18
|
+
graphsWithEqualType.push(graphId);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (field.type === fieldState.type) {
|
|
22
|
+
graphsWithEqualType.push(graphId);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const existing = groupByType.get(field.type);
|
|
26
|
+
if (existing) {
|
|
27
|
+
existing.push(graphId);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
groupByType.set(field.type, [graphId]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (groupByType.size && graphsWithEqualType.length) {
|
|
34
|
+
const groups = Array.from(groupByType.entries()).map(([type, graphs]) => {
|
|
35
|
+
const plural = graphs.length > 1 ? 's' : '';
|
|
36
|
+
return `type "${type}" in subgraph${plural} ${andList(graphs.map(context.graphIdToName), true, '"')}`;
|
|
37
|
+
});
|
|
38
|
+
const [first, ...rest] = groups;
|
|
39
|
+
const nonExternal = `type "${fieldState.type}" in subgraph${graphsWithEqualType.length > 1 ? 's' : ''} ${andList(graphsWithEqualType.map(context.graphIdToName), true, '"')}`;
|
|
40
|
+
context.reportError(new GraphQLError(`Type of field "${objectTypeState.name}.${fieldState.name}" is incompatible across subgraphs (where marked @external): it has ${nonExternal} but ${first}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
|
|
41
|
+
extensions: {
|
|
42
|
+
code: 'EXTERNAL_TYPE_MISMATCH',
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function FieldArgumentDefaultMismatchRule(context) {
|
|
3
|
+
return {
|
|
4
|
+
ObjectTypeFieldArg(objectState, fieldState, argState) {
|
|
5
|
+
if (typeof argState.defaultValue !== 'string') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const defaultValueToGraphs = new Map();
|
|
9
|
+
argState.byGraph.forEach((arg, graphName) => {
|
|
10
|
+
if (typeof arg.defaultValue === 'string') {
|
|
11
|
+
const existing = defaultValueToGraphs.get(arg.defaultValue);
|
|
12
|
+
if (existing) {
|
|
13
|
+
existing.push(graphName);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
defaultValueToGraphs.set(arg.defaultValue, [graphName]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (defaultValueToGraphs.size > 1) {
|
|
21
|
+
const groups = Array.from(defaultValueToGraphs.entries()).map(([defaultValue, graphs]) => {
|
|
22
|
+
const plural = graphs.length > 1 ? 's' : '';
|
|
23
|
+
return `default value ${defaultValue} in subgraph${plural} "${graphs
|
|
24
|
+
.map(context.graphIdToName)
|
|
25
|
+
.join('", "')}"`;
|
|
26
|
+
});
|
|
27
|
+
const [first, second, ...rest] = groups;
|
|
28
|
+
context.reportError(new GraphQLError(`Argument "${objectState.name}.${fieldState.name}(${argState.name}:)" has incompatible default values across subgraphs: it has ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
|
|
29
|
+
extensions: {
|
|
30
|
+
code: 'FIELD_ARGUMENT_DEFAULT_MISMATCH',
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function FieldArgumentsOfTheSameTypeRule(context) {
|
|
3
|
+
return {
|
|
4
|
+
ObjectTypeFieldArg(objectTypeState, fieldState, argState) {
|
|
5
|
+
const typeToGraphs = new Map();
|
|
6
|
+
argState.byGraph.forEach((arg, graphName) => {
|
|
7
|
+
const isNonNullable = arg.type.endsWith('!');
|
|
8
|
+
const isNonNullableInSupergraph = argState.type.endsWith('!');
|
|
9
|
+
const isMatchingNonNullablePart = argState.type.replace(/!$/, '') === arg.type.replace(/!$/, '');
|
|
10
|
+
let normalizedOutputType;
|
|
11
|
+
if (isMatchingNonNullablePart) {
|
|
12
|
+
normalizedOutputType = isNonNullableInSupergraph
|
|
13
|
+
? isNonNullable
|
|
14
|
+
? arg.type
|
|
15
|
+
: arg.type + '!'
|
|
16
|
+
: arg.type;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
normalizedOutputType = arg.type;
|
|
20
|
+
}
|
|
21
|
+
const existing = typeToGraphs.get(normalizedOutputType);
|
|
22
|
+
if (existing) {
|
|
23
|
+
existing.push(graphName);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
typeToGraphs.set(normalizedOutputType, [graphName]);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (typeToGraphs.size > 1) {
|
|
30
|
+
const groups = Array.from(typeToGraphs.entries()).map(([outputType, graphs]) => {
|
|
31
|
+
const plural = graphs.length > 1 ? 's' : '';
|
|
32
|
+
return `type "${outputType}" in subgraph${plural} "${graphs
|
|
33
|
+
.map(context.graphIdToName)
|
|
34
|
+
.join('", "')}"`;
|
|
35
|
+
});
|
|
36
|
+
const [first, second, ...rest] = groups;
|
|
37
|
+
context.reportError(new GraphQLError(`Type of argument "${objectTypeState.name}.${fieldState.name}(${argState.name}:)" is incompatible across subgraphs: it has ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
|
|
38
|
+
extensions: {
|
|
39
|
+
code: 'FIELD_ARGUMENT_TYPE_MISMATCH',
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|