@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,862 @@
|
|
|
1
|
+
import { GraphQLError, Kind, OperationTypeNode, print, specifiedScalarTypes, } from 'graphql';
|
|
2
|
+
import { parseFields } from '../../../subgraph/helpers.js';
|
|
3
|
+
import { TypeKind } from '../../../subgraph/state.js';
|
|
4
|
+
import { DepGraph } from '../../../utils/dependency-graph.js';
|
|
5
|
+
import { isDefined } from '../../../utils/helpers.js';
|
|
6
|
+
import { isList, isNonNull, stripNonNull, stripTypeModifiers } from '../../../utils/state.js';
|
|
7
|
+
function canGraphMoveToGraph(supergraphState, objectTypeState, sourceGraphId, targetGraphId) {
|
|
8
|
+
const sourceGraphKeys = objectTypeState.byGraph.get(sourceGraphId).keys;
|
|
9
|
+
const targetGraphKeys = objectTypeState.byGraph.get(targetGraphId).keys;
|
|
10
|
+
if (sourceGraphKeys.length === 0 && targetGraphKeys.length === 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const fieldsOfSourceGraph = Array.from(objectTypeState.fields.values()).filter(f => f.byGraph.get(sourceGraphId));
|
|
14
|
+
const nonExternalFieldsOfSourceGraph = fieldsOfSourceGraph.filter(f => f.byGraph.get(sourceGraphId).external === false);
|
|
15
|
+
if (sourceGraphKeys.length === 0) {
|
|
16
|
+
return targetGraphKeys
|
|
17
|
+
.filter(k => k.resolvable === true)
|
|
18
|
+
.some(k => {
|
|
19
|
+
const targetKeyFields = resolveFieldsFromFieldSet(k.fields, objectTypeState.name, targetGraphId, supergraphState);
|
|
20
|
+
return Array.from(targetKeyFields.coordinates).every(fieldPath => {
|
|
21
|
+
const [typeName, fieldName] = fieldPath.split('.');
|
|
22
|
+
if (typeName === objectTypeState.name) {
|
|
23
|
+
const fieldState = objectTypeState.fields.get(fieldName);
|
|
24
|
+
if (!fieldState) {
|
|
25
|
+
throw new Error(`Field "${fieldPath}" not found in object type "${typeName}"`);
|
|
26
|
+
}
|
|
27
|
+
const fieldStateByGraph = fieldState.byGraph.get(targetGraphId);
|
|
28
|
+
if (!fieldStateByGraph) {
|
|
29
|
+
throw new Error(`Field "${fieldPath}" not found in object type "${typeName}" in graph "${targetGraphId}"`);
|
|
30
|
+
}
|
|
31
|
+
return fieldStateByGraph.external === false;
|
|
32
|
+
}
|
|
33
|
+
const currentTypeState = supergraphState.objectTypes.get(typeName) ??
|
|
34
|
+
supergraphState.interfaceTypes.get(typeName);
|
|
35
|
+
if (!currentTypeState) {
|
|
36
|
+
throw new Error(`Type "${typeName}" not found`);
|
|
37
|
+
}
|
|
38
|
+
const fieldState = currentTypeState.fields.get(fieldName);
|
|
39
|
+
if (!fieldState) {
|
|
40
|
+
throw new Error(`Field "${fieldPath}" not found in object type "${typeName}"`);
|
|
41
|
+
}
|
|
42
|
+
const fieldStateByGraph = fieldState.byGraph.get(targetGraphId);
|
|
43
|
+
if (!fieldStateByGraph) {
|
|
44
|
+
throw new Error(`Field "${fieldPath}" not found in object type "${typeName}" in graph "${targetGraphId}"`);
|
|
45
|
+
}
|
|
46
|
+
if ('external' in fieldStateByGraph) {
|
|
47
|
+
return fieldStateByGraph.external === false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return sourceGraphKeys.some(sourceGraphKey => {
|
|
54
|
+
const sourceKeyFields = resolveFieldsFromFieldSet(sourceGraphKey.fields, objectTypeState.name, sourceGraphId, supergraphState);
|
|
55
|
+
return (targetGraphKeys
|
|
56
|
+
.filter(k => k.resolvable === true)
|
|
57
|
+
.some(k => {
|
|
58
|
+
const targetKeyFields = resolveFieldsFromFieldSet(k.fields, objectTypeState.name, targetGraphId, supergraphState);
|
|
59
|
+
for (const fieldPath of targetKeyFields.paths) {
|
|
60
|
+
if (!sourceKeyFields.paths.has(fieldPath)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function canGraphResolveFieldDirectly(objectTypeSuperState, fieldSuperState, graphId, supergraphState) {
|
|
69
|
+
const objectTypeInGraph = objectTypeSuperState.byGraph.get(graphId);
|
|
70
|
+
if (!objectTypeInGraph) {
|
|
71
|
+
throw new Error(`Object type "${objectTypeSuperState.name}" not found in graph "${graphId}"`);
|
|
72
|
+
}
|
|
73
|
+
const fieldInGraph = fieldSuperState.byGraph.get(graphId);
|
|
74
|
+
if (!fieldInGraph) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if ((fieldInGraph.shareable === true ||
|
|
78
|
+
objectTypeSuperState.byGraph.get(graphId).shareable === true) &&
|
|
79
|
+
supergraphState.graphs.get(graphId).version !== 'v1.0') {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
if (fieldInGraph.external === true) {
|
|
83
|
+
if (fieldInGraph.usedAsKey === true) {
|
|
84
|
+
const graphHasAtLeastOneResolvableField = Array.from(objectTypeSuperState.fields.values()).some(f => {
|
|
85
|
+
if (f.name === fieldSuperState.name) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const fInGraph = f.byGraph.get(graphId);
|
|
89
|
+
if (!fInGraph) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (fInGraph.external === true) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (fInGraph.inaccessible === true) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (typeof fInGraph.override === 'string') {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
if (graphHasAtLeastOneResolvableField) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
function canGraphResolveField(objectTypeSuperState, fieldSuperState, graphId, supergraphState, movabilityGraph) {
|
|
112
|
+
const objectTypeInGraph = objectTypeSuperState.byGraph.get(graphId);
|
|
113
|
+
if (!objectTypeInGraph) {
|
|
114
|
+
throw new Error(`Object type "${objectTypeSuperState.name}" not found in graph "${graphId}"`);
|
|
115
|
+
}
|
|
116
|
+
const fieldInGraph = fieldSuperState.byGraph.get(graphId);
|
|
117
|
+
if (fieldInGraph &&
|
|
118
|
+
fieldInGraph.external === false &&
|
|
119
|
+
canGraphResolveFieldDirectly(objectTypeSuperState, fieldSuperState, graphId, supergraphState)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const graphsWithField = Array.from(fieldSuperState.byGraph).filter(([g, _]) => {
|
|
123
|
+
if (g === graphId) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const fieldInGraph = fieldSuperState.byGraph.get(g);
|
|
127
|
+
if (!fieldInGraph || fieldInGraph.external === true) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
const canMoveToGraphWithField = graphsWithField.some(([g, _]) => {
|
|
133
|
+
return canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, graphId, g);
|
|
134
|
+
});
|
|
135
|
+
return canMoveToGraphWithField;
|
|
136
|
+
}
|
|
137
|
+
function canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, sourceId, destinationId, visited = new Set()) {
|
|
138
|
+
const key = `${sourceId} => ${destinationId}`;
|
|
139
|
+
if (visited.has(key)) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
visited.add(key);
|
|
144
|
+
}
|
|
145
|
+
const deps = movabilityGraph.directDependenciesOf(sourceId);
|
|
146
|
+
if (deps.includes(destinationId)) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return deps.some(depId => canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, depId, destinationId, visited));
|
|
150
|
+
}
|
|
151
|
+
function findLeafs(movabilityGraph, sourceId, destinationId, leafs, visited = new Set()) {
|
|
152
|
+
const key = `${sourceId} => ${destinationId}`;
|
|
153
|
+
if (leafs === undefined) {
|
|
154
|
+
leafs = new Set();
|
|
155
|
+
}
|
|
156
|
+
const deps = movabilityGraph.directDependenciesOf(sourceId);
|
|
157
|
+
if (visited.has(key)) {
|
|
158
|
+
return Array.from(leafs);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
visited.add(key);
|
|
162
|
+
}
|
|
163
|
+
for (const depId of deps) {
|
|
164
|
+
if (!canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, depId, destinationId)) {
|
|
165
|
+
leafs.add(depId);
|
|
166
|
+
findLeafs(movabilityGraph, depId, destinationId, leafs, visited);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return Array.from(leafs);
|
|
170
|
+
}
|
|
171
|
+
export function SatisfiabilityRule(context, supergraphState) {
|
|
172
|
+
const typeDependencies = buildOutputTypesDependencies(supergraphState);
|
|
173
|
+
let currentMovabilityGraphType;
|
|
174
|
+
let movabilityGraph;
|
|
175
|
+
return {
|
|
176
|
+
ObjectType(objectState) {
|
|
177
|
+
currentMovabilityGraphType = objectState.name;
|
|
178
|
+
movabilityGraph = new DepGraph({
|
|
179
|
+
circular: true,
|
|
180
|
+
});
|
|
181
|
+
const graphIds = Array.from(objectState.byGraph.keys());
|
|
182
|
+
for (const sourceGraphId of objectState.byGraph.keys()) {
|
|
183
|
+
movabilityGraph.addNode(sourceGraphId);
|
|
184
|
+
}
|
|
185
|
+
for (const sourceGraphId of objectState.byGraph.keys()) {
|
|
186
|
+
const otherGraphIds = graphIds.filter(g => g !== sourceGraphId);
|
|
187
|
+
for (const destGraphId of otherGraphIds) {
|
|
188
|
+
if (canGraphMoveToGraph(supergraphState, objectState, sourceGraphId, destGraphId)) {
|
|
189
|
+
movabilityGraph.addDependency(sourceGraphId, destGraphId);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
ObjectTypeField(objectState, fieldState) {
|
|
195
|
+
if (currentMovabilityGraphType !== objectState.name) {
|
|
196
|
+
throw new Error('ObjectTypeField runs before ObjectType! This should not happen.');
|
|
197
|
+
}
|
|
198
|
+
if (objectState.name === 'Query' ||
|
|
199
|
+
objectState.name === 'Mutation' ||
|
|
200
|
+
objectState.name === 'Subscription') {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (objectState.byGraph.size === 1) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const dependenciesOfObjectType = typeDependencies.dependentsOf(objectState.name);
|
|
207
|
+
const isReachableByRootType = {
|
|
208
|
+
query: dependenciesOfObjectType.includes('Query'),
|
|
209
|
+
mutation: dependenciesOfObjectType.includes('Mutation'),
|
|
210
|
+
subscription: dependenciesOfObjectType.includes('Subscription'),
|
|
211
|
+
};
|
|
212
|
+
const isReachable = isReachableByRootType.query ||
|
|
213
|
+
isReachableByRootType.mutation ||
|
|
214
|
+
isReachableByRootType.subscription;
|
|
215
|
+
if (!isReachable) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const objectStateGraphPairs = Array.from(objectState.byGraph);
|
|
219
|
+
const fieldStateGraphPairs = Array.from(fieldState.byGraph);
|
|
220
|
+
if (objectStateGraphPairs.some(([_, objectTypeStateInGraph]) => objectTypeStateInGraph.inaccessible === true) ||
|
|
221
|
+
fieldStateGraphPairs.some(([_, fieldStateInGraph]) => fieldStateInGraph.inaccessible === true)) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const isFieldShareableInAllSubgraphs = Array.from(fieldState.byGraph).every(([graphId, fieldStateInGraph]) => {
|
|
225
|
+
const fieldShareable = fieldStateInGraph.shareable &&
|
|
226
|
+
context.subgraphStates.get(graphId).version !== 'v1.0';
|
|
227
|
+
const typeShareable = objectState.byGraph.get(graphId).shareable === true;
|
|
228
|
+
return fieldShareable || typeShareable;
|
|
229
|
+
});
|
|
230
|
+
if (isFieldShareableInAllSubgraphs) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (fieldState.byGraph.size === objectState.byGraph.size &&
|
|
234
|
+
fieldStateGraphPairs.every(([_, f]) => f.usedAsKey === true && f.external === false && !f.override)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const keysInAllGraphs = objectStateGraphPairs.every(([_, o]) => o.keys.length > 0);
|
|
238
|
+
const uniqueKeyFieldsSet = new Set(objectStateGraphPairs
|
|
239
|
+
.map(([_, o]) => o.keys.map(k => k.fields))
|
|
240
|
+
.flat(1));
|
|
241
|
+
if (keysInAllGraphs && uniqueKeyFieldsSet.size === 1) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const aggregatedErrorByRootType = {
|
|
245
|
+
Query: {
|
|
246
|
+
query: null,
|
|
247
|
+
reasons: [],
|
|
248
|
+
},
|
|
249
|
+
Mutation: {
|
|
250
|
+
query: null,
|
|
251
|
+
reasons: [],
|
|
252
|
+
},
|
|
253
|
+
Subscription: {
|
|
254
|
+
query: null,
|
|
255
|
+
reasons: [],
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
if (uniqueKeyFieldsSet.size > 0) {
|
|
259
|
+
for (const graphId of objectState.byGraph.keys()) {
|
|
260
|
+
if (canGraphResolveField(objectState, fieldState, graphId, supergraphState, movabilityGraph)) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const fieldStateInGraph = fieldState.byGraph.get(graphId);
|
|
264
|
+
if (fieldStateInGraph?.external === true) {
|
|
265
|
+
const objectStateInGraph = objectState.byGraph.get(graphId);
|
|
266
|
+
if (objectStateInGraph.extension === true) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (fieldStateInGraph.required) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (fieldStateInGraph.provided) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const subgraphState = context.subgraphStates.get(graphId);
|
|
277
|
+
const schemaDefinitionOfGraph = subgraphState.schema;
|
|
278
|
+
const rootTypes = [
|
|
279
|
+
schemaDefinitionOfGraph.queryType
|
|
280
|
+
? [
|
|
281
|
+
'Query',
|
|
282
|
+
subgraphState.types.get(schemaDefinitionOfGraph.queryType),
|
|
283
|
+
]
|
|
284
|
+
: undefined,
|
|
285
|
+
schemaDefinitionOfGraph.mutationType
|
|
286
|
+
? [
|
|
287
|
+
'Mutation',
|
|
288
|
+
subgraphState.types.get(schemaDefinitionOfGraph.mutationType),
|
|
289
|
+
]
|
|
290
|
+
: undefined,
|
|
291
|
+
schemaDefinitionOfGraph.subscriptionType
|
|
292
|
+
? [
|
|
293
|
+
'Subscription',
|
|
294
|
+
subgraphState.types.get(schemaDefinitionOfGraph.subscriptionType),
|
|
295
|
+
]
|
|
296
|
+
: undefined,
|
|
297
|
+
].filter(isDefined);
|
|
298
|
+
if (rootTypes.length === 0) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const otherGraphIds = objectStateGraphPairs
|
|
302
|
+
.filter(([g, _]) => g !== graphId)
|
|
303
|
+
.map(([g, _]) => g);
|
|
304
|
+
const graphsWithField = fieldStateGraphPairs
|
|
305
|
+
.filter(([g, _]) => canGraphResolveFieldDirectly(objectState, fieldState, g, supergraphState))
|
|
306
|
+
.map(([g, _]) => g);
|
|
307
|
+
const leafs = graphsWithField.map(g => findLeafs(movabilityGraph, graphId, g)).flat(1);
|
|
308
|
+
if (leafs.length === 0 && movabilityGraph.directDependenciesOf(graphId).length > 0) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
for (const [normalizedName, rootType] of rootTypes) {
|
|
312
|
+
const query = printExampleQuery(supergraphState, normalizedName, Array.from(rootType.fields.keys()), objectState.name, fieldState.name, dependenciesOfObjectType);
|
|
313
|
+
const reasons = [];
|
|
314
|
+
const canBeIndirectlyResolved = leafs.length > 0;
|
|
315
|
+
const cannotMoveToList = (sourceGraphId) => canBeIndirectlyResolved
|
|
316
|
+
? graphsWithField
|
|
317
|
+
.map(gid => {
|
|
318
|
+
const keys = objectState.byGraph.get(gid).keys.map(k => k.fields);
|
|
319
|
+
if (keys.length > 0) {
|
|
320
|
+
return objectState.byGraph
|
|
321
|
+
.get(gid)
|
|
322
|
+
.keys.map(k => k.fields)
|
|
323
|
+
.map(fields => `cannot move to subgraph "${context.graphIdToName(gid)}" using @key(fields: "${fields}") of "${objectState.name}", the key field(s) cannot be resolved from subgraph "${context.graphIdToName(sourceGraphId)}".`);
|
|
324
|
+
}
|
|
325
|
+
return `cannot move to subgraph "${context.graphIdToName(gid)}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${context.graphIdToName(gid)}".`;
|
|
326
|
+
})
|
|
327
|
+
.flat(1)
|
|
328
|
+
: otherGraphIds
|
|
329
|
+
.filter(g => !movabilityGraph.directDependenciesOf(graphId).includes(g))
|
|
330
|
+
.map(gid => {
|
|
331
|
+
const keys = objectState.byGraph.get(gid).keys.map(k => k.fields);
|
|
332
|
+
if (keys.length > 0) {
|
|
333
|
+
return objectState.byGraph
|
|
334
|
+
.get(gid)
|
|
335
|
+
.keys.map(k => k.fields)
|
|
336
|
+
.map(fields => `cannot move to subgraph "${context.graphIdToName(gid)}" using @key(fields: "${fields}") of "${objectState.name}", the key field(s) cannot be resolved from subgraph "${context.graphIdToName(sourceGraphId)}".`);
|
|
337
|
+
}
|
|
338
|
+
return `cannot move to subgraph "${context.graphIdToName(gid)}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${context.graphIdToName(gid)}".`;
|
|
339
|
+
})
|
|
340
|
+
.flat(1);
|
|
341
|
+
const fromSubgraphs = [graphId].concat(leafs);
|
|
342
|
+
if (!fieldStateInGraph) {
|
|
343
|
+
fromSubgraphs.forEach(gid => {
|
|
344
|
+
reasons.push([
|
|
345
|
+
gid,
|
|
346
|
+
[`cannot find field "${objectState.name}.${fieldState.name}".`].concat(cannotMoveToList(gid)),
|
|
347
|
+
]);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
else if (fieldStateInGraph.external) {
|
|
351
|
+
fromSubgraphs.forEach(gid => {
|
|
352
|
+
reasons.push([
|
|
353
|
+
gid,
|
|
354
|
+
[
|
|
355
|
+
`field "${objectState.name}.${fieldState.name}" is not resolvable because marked @external.`,
|
|
356
|
+
].concat(cannotMoveToList(gid)),
|
|
357
|
+
]);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
console.log('can NOT resolve field', fieldState.name, 'in graph', graphId, 'reason: unknown');
|
|
362
|
+
}
|
|
363
|
+
if (!query || reasons.length === 0) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
context.reportError(new GraphQLError([
|
|
367
|
+
'The following supergraph API query:',
|
|
368
|
+
query,
|
|
369
|
+
'cannot be satisfied by the subgraphs because:',
|
|
370
|
+
...reasons.map(([gid, reasons]) => {
|
|
371
|
+
return (`- from subgraph "${context.graphIdToName(gid)}":\n` +
|
|
372
|
+
reasons.map(r => ` - ${r}`).join('\n'));
|
|
373
|
+
}),
|
|
374
|
+
].join('\n'), {
|
|
375
|
+
extensions: {
|
|
376
|
+
code: 'SATISFIABILITY_ERROR',
|
|
377
|
+
},
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const graphsWithoutField = objectStateGraphPairs.filter(([graphId]) => !fieldState.byGraph.has(graphId));
|
|
384
|
+
const graphsWithField = fieldStateGraphPairs.map(([graphId]) => graphId);
|
|
385
|
+
for (const [graphId] of graphsWithoutField) {
|
|
386
|
+
const subgraphState = context.subgraphStates.get(graphId);
|
|
387
|
+
const isShareableWithOtherGraphs = Array.from(subgraphState.types.values())
|
|
388
|
+
.filter(t => dependenciesOfObjectType.includes(t.name))
|
|
389
|
+
.every(t => {
|
|
390
|
+
if (t.kind === TypeKind.OBJECT) {
|
|
391
|
+
if (t.shareable &&
|
|
392
|
+
subgraphState.version !== 'v1.0') {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
const fields = Array.from(t.fields.values());
|
|
396
|
+
if (fields
|
|
397
|
+
.filter(f => stripTypeModifiers(f.type) === objectState.name)
|
|
398
|
+
.every(f => f.shareable === true &&
|
|
399
|
+
subgraphState.version !== 'v1.0')) {
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return false;
|
|
404
|
+
});
|
|
405
|
+
if (isShareableWithOtherGraphs) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const graphHasAtLeastOneResolvableField = Array.from(objectState.fields.values()).some(f => {
|
|
409
|
+
const fieldInGraph = f.byGraph.get(graphId);
|
|
410
|
+
if (!fieldInGraph) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
if (fieldInGraph.inaccessible === true) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
});
|
|
418
|
+
if (!graphHasAtLeastOneResolvableField) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const schemaDefinitionOfGraph = subgraphState.schema;
|
|
422
|
+
const rootTypes = [
|
|
423
|
+
schemaDefinitionOfGraph.queryType
|
|
424
|
+
? [
|
|
425
|
+
'Query',
|
|
426
|
+
subgraphState.types.get(schemaDefinitionOfGraph.queryType),
|
|
427
|
+
]
|
|
428
|
+
: undefined,
|
|
429
|
+
schemaDefinitionOfGraph.mutationType
|
|
430
|
+
? [
|
|
431
|
+
'Mutation',
|
|
432
|
+
subgraphState.types.get(schemaDefinitionOfGraph.mutationType),
|
|
433
|
+
]
|
|
434
|
+
: undefined,
|
|
435
|
+
schemaDefinitionOfGraph.subscriptionType
|
|
436
|
+
? [
|
|
437
|
+
'Subscription',
|
|
438
|
+
subgraphState.types.get(schemaDefinitionOfGraph.subscriptionType),
|
|
439
|
+
]
|
|
440
|
+
: undefined,
|
|
441
|
+
].filter(isDefined);
|
|
442
|
+
if (rootTypes.length === 0) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
for (const [normalizedName, rootType] of rootTypes) {
|
|
446
|
+
const rootTypeFields = Array.from(rootType.fields.keys()).filter(f => f !== '_entities' && f !== '_service');
|
|
447
|
+
if (rootTypeFields.length === 0) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const supergraphRootType = supergraphState.objectTypes.get(normalizedName);
|
|
451
|
+
const rootFieldsReferencingObjectType = Array.from(supergraphRootType.fields.values()).filter(f => {
|
|
452
|
+
const fieldOutputTypeName = stripTypeModifiers(f.type);
|
|
453
|
+
return (fieldOutputTypeName === objectState.name ||
|
|
454
|
+
dependenciesOfObjectType.includes(fieldOutputTypeName));
|
|
455
|
+
});
|
|
456
|
+
if (rootFieldsReferencingObjectType.length === 0) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const graphIdsImplementingObjectType = Array.from(objectState.byGraph.keys());
|
|
460
|
+
if (rootFieldsReferencingObjectType.every(field => graphIdsImplementingObjectType.every(g => field.byGraph.has(g)))) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const areRootFieldsShared = graphsWithField.every(g => {
|
|
464
|
+
const localVersion = context.subgraphStates.get(g).version;
|
|
465
|
+
if (localVersion !== 'v1.0') {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
const localSubgraph = context.subgraphStates.get(g);
|
|
469
|
+
const localSchemaDefinition = localSubgraph.schema;
|
|
470
|
+
const localRootTypeName = normalizedName === 'Query'
|
|
471
|
+
? localSchemaDefinition.queryType
|
|
472
|
+
: normalizedName === 'Mutation'
|
|
473
|
+
? localSchemaDefinition.mutationType
|
|
474
|
+
: normalizedName === 'Subscription'
|
|
475
|
+
? localSchemaDefinition.subscriptionType
|
|
476
|
+
: undefined;
|
|
477
|
+
if (!localRootTypeName) {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
const localRootType = localSubgraph.types.get(localRootTypeName);
|
|
481
|
+
const localRootFields = Array.from(localRootType.fields.keys());
|
|
482
|
+
return rootFieldsReferencingObjectType.every(f => localRootFields.includes(f.name));
|
|
483
|
+
});
|
|
484
|
+
if (areRootFieldsShared) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (!aggregatedErrorByRootType[normalizedName].query) {
|
|
488
|
+
aggregatedErrorByRootType[normalizedName].query = printExampleQuery(supergraphState, normalizedName, rootTypeFields, objectState.name, fieldState.name, dependenciesOfObjectType);
|
|
489
|
+
}
|
|
490
|
+
const firstFieldImplementingGraph = graphsWithField[0];
|
|
491
|
+
const graphNameOwningField = context.graphIdToName(firstFieldImplementingGraph);
|
|
492
|
+
aggregatedErrorByRootType[normalizedName].reasons.push([
|
|
493
|
+
graphId,
|
|
494
|
+
[
|
|
495
|
+
`cannot find field "${objectState.name}.${fieldState.name}".`,
|
|
496
|
+
`cannot move to subgraph "${graphNameOwningField}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${graphNameOwningField}".`,
|
|
497
|
+
],
|
|
498
|
+
]);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
for (const rootTypeName in aggregatedErrorByRootType) {
|
|
503
|
+
const details = aggregatedErrorByRootType[rootTypeName];
|
|
504
|
+
if (!details.query || details.reasons.length === 0) {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
context.reportError(new GraphQLError([
|
|
508
|
+
'The following supergraph API query:',
|
|
509
|
+
details.query,
|
|
510
|
+
'cannot be satisfied by the subgraphs because:',
|
|
511
|
+
...details.reasons.map(([graphId, reasons]) => {
|
|
512
|
+
return (`- from subgraph "${context.graphIdToName(graphId)}":\n` +
|
|
513
|
+
reasons.map(r => ` - ${r}`).join('\n'));
|
|
514
|
+
}),
|
|
515
|
+
].join('\n'), {
|
|
516
|
+
extensions: {
|
|
517
|
+
code: 'SATISFIABILITY_ERROR',
|
|
518
|
+
},
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function buildOutputTypesDependencies(supergraphState) {
|
|
525
|
+
const graph = new DepGraph({
|
|
526
|
+
circular: true,
|
|
527
|
+
});
|
|
528
|
+
for (const [typeName, typeState] of supergraphState.objectTypes) {
|
|
529
|
+
if (typeName === '_Service') {
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
graph.addNode(typeName);
|
|
533
|
+
for (const [_, fieldState] of typeState.fields) {
|
|
534
|
+
const referencedTypeName = stripTypeModifiers(fieldState.type);
|
|
535
|
+
if (!graph.hasNode(referencedTypeName)) {
|
|
536
|
+
graph.addNode(referencedTypeName);
|
|
537
|
+
}
|
|
538
|
+
graph.addDependency(typeName, referencedTypeName);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
for (const [typeName, typeState] of supergraphState.unionTypes) {
|
|
542
|
+
if (typeName === '_Entity') {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
graph.addNode(typeName);
|
|
546
|
+
for (const memberType of typeState.members) {
|
|
547
|
+
const referencedTypeName = memberType;
|
|
548
|
+
if (!graph.hasNode(referencedTypeName)) {
|
|
549
|
+
graph.addNode(referencedTypeName);
|
|
550
|
+
}
|
|
551
|
+
graph.addDependency(typeName, referencedTypeName);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return graph;
|
|
555
|
+
}
|
|
556
|
+
function printExampleQuery(supergraphState, rootTypeName, rootTypeFieldsToStartWith, leafTypeName, leafFieldName, typesInBetweenRootAndLeaf = []) {
|
|
557
|
+
const rootType = supergraphState.objectTypes.get(rootTypeName);
|
|
558
|
+
function visitType(typeState, descendants, visitedTypes) {
|
|
559
|
+
if (visitedTypes.includes(typeState.name)) {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
if ('members' in typeState) {
|
|
563
|
+
for (const member of typeState.members) {
|
|
564
|
+
const result = member === leafTypeName
|
|
565
|
+
? visitLeafType(supergraphState.objectTypes.get(member), descendants.concat([
|
|
566
|
+
{
|
|
567
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
568
|
+
typeCondition: {
|
|
569
|
+
kind: Kind.NAMED_TYPE,
|
|
570
|
+
name: {
|
|
571
|
+
kind: Kind.NAME,
|
|
572
|
+
value: member,
|
|
573
|
+
},
|
|
574
|
+
},
|
|
575
|
+
selectionSet: {
|
|
576
|
+
kind: Kind.SELECTION_SET,
|
|
577
|
+
selections: [],
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
]))
|
|
581
|
+
: visitType(supergraphState.objectTypes.get(member), descendants.concat([
|
|
582
|
+
{
|
|
583
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
584
|
+
typeCondition: {
|
|
585
|
+
kind: Kind.NAMED_TYPE,
|
|
586
|
+
name: {
|
|
587
|
+
kind: Kind.NAME,
|
|
588
|
+
value: member,
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
selectionSet: {
|
|
592
|
+
kind: Kind.SELECTION_SET,
|
|
593
|
+
selections: [],
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
]), visitedTypes.concat(typeState.name));
|
|
597
|
+
if (result) {
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
for (const [fieldName, fieldState] of Array.from(typeState.fields.entries()).reverse()) {
|
|
604
|
+
if (typeState.name === rootTypeName && !rootTypeFieldsToStartWith.includes(fieldName)) {
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
const fieldOutputTypeName = stripTypeModifiers(fieldState.type);
|
|
608
|
+
if (fieldOutputTypeName === leafTypeName) {
|
|
609
|
+
return visitLeafType(supergraphState.objectTypes.get(fieldOutputTypeName), descendants.concat([
|
|
610
|
+
{
|
|
611
|
+
kind: Kind.FIELD,
|
|
612
|
+
name: {
|
|
613
|
+
kind: Kind.NAME,
|
|
614
|
+
value: fieldName,
|
|
615
|
+
},
|
|
616
|
+
arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
|
|
617
|
+
kind: Kind.ARGUMENT,
|
|
618
|
+
name: {
|
|
619
|
+
kind: Kind.NAME,
|
|
620
|
+
value: argName,
|
|
621
|
+
},
|
|
622
|
+
value: createEmptyValueNode(argState.type, supergraphState),
|
|
623
|
+
})),
|
|
624
|
+
},
|
|
625
|
+
]));
|
|
626
|
+
}
|
|
627
|
+
else if (typesInBetweenRootAndLeaf.includes(fieldOutputTypeName) &&
|
|
628
|
+
!visitedTypes.includes(fieldOutputTypeName)) {
|
|
629
|
+
const referencedType = supergraphState.objectTypes.get(fieldOutputTypeName) ??
|
|
630
|
+
supergraphState.unionTypes.get(fieldOutputTypeName);
|
|
631
|
+
return visitType(referencedType, descendants.concat([
|
|
632
|
+
{
|
|
633
|
+
kind: Kind.FIELD,
|
|
634
|
+
name: {
|
|
635
|
+
kind: Kind.NAME,
|
|
636
|
+
value: fieldName,
|
|
637
|
+
},
|
|
638
|
+
arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
|
|
639
|
+
kind: Kind.ARGUMENT,
|
|
640
|
+
name: {
|
|
641
|
+
kind: Kind.NAME,
|
|
642
|
+
value: argName,
|
|
643
|
+
},
|
|
644
|
+
value: createEmptyValueNode(argState.type, supergraphState),
|
|
645
|
+
})),
|
|
646
|
+
},
|
|
647
|
+
]), visitedTypes.concat(typeState.name));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
function visitLeafType(objectTypeState, descendants) {
|
|
653
|
+
for (const [fieldName, fieldState] of objectTypeState.fields) {
|
|
654
|
+
if (fieldName !== leafFieldName) {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const fieldOutputTypeName = stripTypeModifiers(fieldState.type);
|
|
658
|
+
const isObjectSpreadCapable = supergraphState.objectTypes.has(fieldOutputTypeName) ||
|
|
659
|
+
supergraphState.interfaceTypes.has(fieldOutputTypeName) ||
|
|
660
|
+
supergraphState.unionTypes.has(fieldOutputTypeName);
|
|
661
|
+
return descendants.concat([
|
|
662
|
+
{
|
|
663
|
+
kind: Kind.FIELD,
|
|
664
|
+
name: {
|
|
665
|
+
kind: Kind.NAME,
|
|
666
|
+
value: fieldName,
|
|
667
|
+
},
|
|
668
|
+
arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
|
|
669
|
+
kind: Kind.ARGUMENT,
|
|
670
|
+
name: {
|
|
671
|
+
kind: Kind.NAME,
|
|
672
|
+
value: argName,
|
|
673
|
+
},
|
|
674
|
+
value: createEmptyValueNode(argState.type, supergraphState),
|
|
675
|
+
})),
|
|
676
|
+
selectionSet: isObjectSpreadCapable
|
|
677
|
+
?
|
|
678
|
+
{
|
|
679
|
+
kind: Kind.SELECTION_SET,
|
|
680
|
+
selections: [
|
|
681
|
+
{
|
|
682
|
+
kind: Kind.FRAGMENT_SPREAD,
|
|
683
|
+
name: {
|
|
684
|
+
kind: Kind.NAME,
|
|
685
|
+
value: '',
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
}
|
|
690
|
+
: undefined,
|
|
691
|
+
},
|
|
692
|
+
]);
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
const tree = visitType(rootType, [], []);
|
|
697
|
+
let currentField = null;
|
|
698
|
+
if (!tree) {
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
tree.reverse();
|
|
702
|
+
for (const field of tree) {
|
|
703
|
+
if (!currentField) {
|
|
704
|
+
currentField = {
|
|
705
|
+
...field,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
currentField = {
|
|
710
|
+
...field,
|
|
711
|
+
selectionSet: {
|
|
712
|
+
kind: Kind.SELECTION_SET,
|
|
713
|
+
selections: [currentField],
|
|
714
|
+
},
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const query = {
|
|
719
|
+
kind: Kind.DOCUMENT,
|
|
720
|
+
definitions: [
|
|
721
|
+
{
|
|
722
|
+
kind: Kind.OPERATION_DEFINITION,
|
|
723
|
+
operation: rootTypeName === 'Query'
|
|
724
|
+
? OperationTypeNode.QUERY
|
|
725
|
+
: rootTypeName === 'Mutation'
|
|
726
|
+
? OperationTypeNode.MUTATION
|
|
727
|
+
: OperationTypeNode.SUBSCRIPTION,
|
|
728
|
+
selectionSet: {
|
|
729
|
+
kind: Kind.SELECTION_SET,
|
|
730
|
+
selections: [currentField],
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
};
|
|
735
|
+
return print(query);
|
|
736
|
+
}
|
|
737
|
+
function createEmptyValueNode(fullType, supergraphState) {
|
|
738
|
+
if (isList(fullType)) {
|
|
739
|
+
return {
|
|
740
|
+
kind: Kind.LIST,
|
|
741
|
+
values: [],
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
if (isNonNull(fullType)) {
|
|
745
|
+
const innerType = stripNonNull(fullType);
|
|
746
|
+
return createEmptyValueNode(innerType, supergraphState);
|
|
747
|
+
}
|
|
748
|
+
if (supergraphState.enumTypes.has(fullType)) {
|
|
749
|
+
const enumState = supergraphState.enumTypes.get(fullType);
|
|
750
|
+
return {
|
|
751
|
+
kind: Kind.ENUM,
|
|
752
|
+
value: Array.from(enumState.values.keys())[0],
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
if (supergraphState.scalarTypes.has(fullType)) {
|
|
756
|
+
return {
|
|
757
|
+
kind: Kind.STRING,
|
|
758
|
+
value: 'A string value',
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
if (supergraphState.inputObjectTypes.has(fullType)) {
|
|
762
|
+
const inputObjectTypeState = supergraphState.inputObjectTypes.get(fullType);
|
|
763
|
+
return {
|
|
764
|
+
kind: Kind.OBJECT,
|
|
765
|
+
fields: Array.from(inputObjectTypeState.fields)
|
|
766
|
+
.filter(([_, fieldState]) => isNonNull(fieldState.type))
|
|
767
|
+
.map(([fieldName, fieldState]) => ({
|
|
768
|
+
kind: Kind.OBJECT_FIELD,
|
|
769
|
+
name: {
|
|
770
|
+
kind: Kind.NAME,
|
|
771
|
+
value: fieldName,
|
|
772
|
+
},
|
|
773
|
+
value: createEmptyValueNode(fieldState.type, supergraphState),
|
|
774
|
+
})),
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
const specifiedScalar = specifiedScalarTypes.find(s => s.name === fullType);
|
|
778
|
+
if (!specifiedScalar) {
|
|
779
|
+
throw new Error(`Type "${fullType}" is not defined.`);
|
|
780
|
+
}
|
|
781
|
+
if (specifiedScalar.name === 'String') {
|
|
782
|
+
return {
|
|
783
|
+
kind: Kind.STRING,
|
|
784
|
+
value: 'A string value',
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
if (specifiedScalar.name === 'Int' || specifiedScalar.name === 'Float') {
|
|
788
|
+
return {
|
|
789
|
+
kind: Kind.INT,
|
|
790
|
+
value: '0',
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
if (specifiedScalar.name === 'Boolean') {
|
|
794
|
+
return {
|
|
795
|
+
kind: Kind.BOOLEAN,
|
|
796
|
+
value: true,
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
if (specifiedScalar.name === 'ID') {
|
|
800
|
+
return {
|
|
801
|
+
kind: Kind.STRING,
|
|
802
|
+
value: '<any id>',
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
throw new Error(`Type "${fullType}" is not supported.`);
|
|
806
|
+
}
|
|
807
|
+
function resolveFieldsFromFieldSet(fields, typeName, graphId, supergraphState) {
|
|
808
|
+
const paths = new Set();
|
|
809
|
+
const coordinates = new Set();
|
|
810
|
+
const selectionSet = parseFields(fields);
|
|
811
|
+
if (!selectionSet) {
|
|
812
|
+
return {
|
|
813
|
+
coordinates,
|
|
814
|
+
paths,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
findFieldPathsFromSelectionSet(paths, coordinates, typeName, selectionSet, typeName, graphId, supergraphState);
|
|
818
|
+
return {
|
|
819
|
+
coordinates,
|
|
820
|
+
paths,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
function findFieldPathsFromSelectionSet(fieldPaths, coordinates, typeName, selectionSet, currentPath, graphId, supergraphState) {
|
|
824
|
+
for (const selection of selectionSet.selections) {
|
|
825
|
+
if (selection.kind === Kind.FIELD) {
|
|
826
|
+
const innerPath = `${currentPath}.${selection.name.value}`;
|
|
827
|
+
fieldPaths.add(innerPath);
|
|
828
|
+
if (Array.isArray(typeName)) {
|
|
829
|
+
for (const t of typeName) {
|
|
830
|
+
coordinates.add(`${t}.${selection.name.value}`);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
coordinates.add(`${typeName}.${selection.name.value}`);
|
|
835
|
+
}
|
|
836
|
+
if (selection.selectionSet) {
|
|
837
|
+
const types = (Array.isArray(typeName) ? typeName : [typeName]).map(tName => {
|
|
838
|
+
const outputType = supergraphState.objectTypes.get(tName) ?? supergraphState.interfaceTypes.get(tName);
|
|
839
|
+
if (!outputType) {
|
|
840
|
+
throw new Error(`Type "${tName}" is not defined.`);
|
|
841
|
+
}
|
|
842
|
+
return outputType;
|
|
843
|
+
});
|
|
844
|
+
const typesWithField = types.filter(t => t.fields.has(selection.name.value));
|
|
845
|
+
if (typesWithField.length === 0) {
|
|
846
|
+
throw new Error(`Type "${typeName.toString()}" does not have field "${selection.name.value}".`);
|
|
847
|
+
}
|
|
848
|
+
const outputTypes = typesWithField.map(t => stripTypeModifiers(t.fields.get(selection.name.value).type));
|
|
849
|
+
findFieldPathsFromSelectionSet(fieldPaths, coordinates, outputTypes, selection.selectionSet, innerPath, graphId, supergraphState);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
else if (selection.kind === Kind.INLINE_FRAGMENT) {
|
|
853
|
+
if (!selection.typeCondition) {
|
|
854
|
+
throw new Error(`Inline fragment without type condition is not supported.`);
|
|
855
|
+
}
|
|
856
|
+
findFieldPathsFromSelectionSet(fieldPaths, coordinates, selection.typeCondition.name.value, selection.selectionSet, `${currentPath}.(${selection.typeCondition.name.value})`, graphId, supergraphState);
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
throw new Error(`Fragment spread is not supported.`);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|