@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,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSubgraph = exports.validateSubgraphCore = exports.assertUniqueSubgraphNames = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const type_node_info_js_1 = require("../../graphql/type-node-info.js");
|
|
6
|
+
const federation_js_1 = require("../../specifications/federation.js");
|
|
7
|
+
const link_js_1 = require("../../specifications/link.js");
|
|
8
|
+
const compose_directive_js_1 = require("./rules/elements/compose-directive.js");
|
|
9
|
+
const extends_js_1 = require("./rules/elements/extends.js");
|
|
10
|
+
const external_js_1 = require("./rules/elements/external.js");
|
|
11
|
+
const field_set_js_1 = require("./rules/elements/field-set.js");
|
|
12
|
+
const inaccessible_js_1 = require("./rules/elements/inaccessible.js");
|
|
13
|
+
const key_js_1 = require("./rules/elements/key.js");
|
|
14
|
+
const override_js_1 = require("./rules/elements/override.js");
|
|
15
|
+
const provides_js_1 = require("./rules/elements/provides.js");
|
|
16
|
+
const requires_js_1 = require("./rules/elements/requires.js");
|
|
17
|
+
const shareable_js_1 = require("./rules/elements/shareable.js");
|
|
18
|
+
const tag_js_1 = require("./rules/elements/tag.js");
|
|
19
|
+
const known_argument_names_on_directives_rule_js_1 = require("./rules/known-argument-names-on-directives-rule.js");
|
|
20
|
+
const known_directives_rule_js_1 = require("./rules/known-directives-rule.js");
|
|
21
|
+
const known_federation_directive_rule_js_1 = require("./rules/known-federation-directive-rule.js");
|
|
22
|
+
const known_root_type_rule_js_1 = require("./rules/known-root-type-rule.js");
|
|
23
|
+
const known_type_names_rule_js_1 = require("./rules/known-type-names-rule.js");
|
|
24
|
+
const lone_schema_definition_rule_js_1 = require("./rules/lone-schema-definition-rule.js");
|
|
25
|
+
const provided_arguments_on_directives_rule_js_1 = require("./rules/provided-arguments-on-directives-rule.js");
|
|
26
|
+
const provided_required_arguments_on_directives_rule_js_1 = require("./rules/provided-required-arguments-on-directives-rule.js");
|
|
27
|
+
const query_root_type_inaccessible_rule_js_1 = require("./rules/query-root-type-inaccessible-rule.js");
|
|
28
|
+
const reserved_subgraph_name_rule_js_1 = require("./rules/reserved-subgraph-name-rule.js");
|
|
29
|
+
const root_type_used_rule_js_1 = require("./rules/root-type-used-rule.js");
|
|
30
|
+
const unique_argument_definition_names_rule_js_1 = require("./rules/unique-argument-definition-names-rule.js");
|
|
31
|
+
const unique_argument_names_rule_js_1 = require("./rules/unique-argument-names-rule.js");
|
|
32
|
+
const unique_directive_names_rule_js_1 = require("./rules/unique-directive-names-rule.js");
|
|
33
|
+
const unique_directives_per_location_rule_js_1 = require("./rules/unique-directives-per-location-rule.js");
|
|
34
|
+
const unique_enum_value_names_rule_js_1 = require("./rules/unique-enum-value-names-rule.js");
|
|
35
|
+
const unique_field_definition_names_rule_js_1 = require("./rules/unique-field-definition-names-rule.js");
|
|
36
|
+
const unique_input_field_names_rule_js_1 = require("./rules/unique-input-field-names-rule.js");
|
|
37
|
+
const unique_operation_types_rule_js_1 = require("./rules/unique-operation-types-rule.js");
|
|
38
|
+
const unique_type_names_rule_js_1 = require("./rules/unique-type-names-rule.js");
|
|
39
|
+
const validate_state_js_1 = require("./validate-state.js");
|
|
40
|
+
const validation_context_js_1 = require("./validation-context.js");
|
|
41
|
+
function assertUniqueSubgraphNames(subgraphs) {
|
|
42
|
+
const names = new Set();
|
|
43
|
+
for (const subgraph of subgraphs) {
|
|
44
|
+
if (names.has(subgraph.name)) {
|
|
45
|
+
throw new Error(`A subgraph named ${subgraph.name} already exists`);
|
|
46
|
+
}
|
|
47
|
+
names.add(subgraph.name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.assertUniqueSubgraphNames = assertUniqueSubgraphNames;
|
|
51
|
+
function validateSubgraphCore(subgraph) {
|
|
52
|
+
const extractedLinks = extractLinks(subgraph);
|
|
53
|
+
if (extractedLinks.errors) {
|
|
54
|
+
extractedLinks.errors.forEach(error => enrichErrorWithSubgraphName(error, subgraph.name));
|
|
55
|
+
}
|
|
56
|
+
return extractedLinks;
|
|
57
|
+
}
|
|
58
|
+
exports.validateSubgraphCore = validateSubgraphCore;
|
|
59
|
+
function validateSubgraph(subgraph, stateBuilder, federation, __internal) {
|
|
60
|
+
subgraph.typeDefs = cleanSubgraphTypeDefsFromSubgraphSpec(subgraph.typeDefs);
|
|
61
|
+
const rulesToSkip = __internal?.disableValidationRules ?? [];
|
|
62
|
+
const typeNodeInfo = new type_node_info_js_1.TypeNodeInfo();
|
|
63
|
+
const validationContext = (0, validation_context_js_1.createSubgraphValidationContext)(subgraph, federation, typeNodeInfo, stateBuilder);
|
|
64
|
+
const federationRules = [
|
|
65
|
+
reserved_subgraph_name_rule_js_1.ReservedSubgraphNameRule,
|
|
66
|
+
known_federation_directive_rule_js_1.KnownFederationDirectivesRule,
|
|
67
|
+
field_set_js_1.FieldSetRules,
|
|
68
|
+
inaccessible_js_1.InaccessibleRules,
|
|
69
|
+
override_js_1.OverrideRules,
|
|
70
|
+
extends_js_1.ExtendsRules,
|
|
71
|
+
query_root_type_inaccessible_rule_js_1.QueryRootTypeInaccessibleRule,
|
|
72
|
+
known_type_names_rule_js_1.KnownTypeNamesRule,
|
|
73
|
+
known_root_type_rule_js_1.KnownRootTypeRule,
|
|
74
|
+
root_type_used_rule_js_1.RootTypeUsedRule,
|
|
75
|
+
shareable_js_1.ShareableRules,
|
|
76
|
+
key_js_1.KeyRules,
|
|
77
|
+
provides_js_1.ProvidesRules,
|
|
78
|
+
requires_js_1.RequiresRules,
|
|
79
|
+
external_js_1.ExternalRules,
|
|
80
|
+
tag_js_1.TagRules,
|
|
81
|
+
compose_directive_js_1.ComposeDirectiveRules,
|
|
82
|
+
];
|
|
83
|
+
const graphqlRules = [
|
|
84
|
+
lone_schema_definition_rule_js_1.LoneSchemaDefinitionRule,
|
|
85
|
+
unique_operation_types_rule_js_1.UniqueOperationTypesRule,
|
|
86
|
+
unique_type_names_rule_js_1.UniqueTypeNamesRule,
|
|
87
|
+
unique_enum_value_names_rule_js_1.UniqueEnumValueNamesRule,
|
|
88
|
+
unique_field_definition_names_rule_js_1.UniqueFieldDefinitionNamesRule,
|
|
89
|
+
unique_argument_definition_names_rule_js_1.UniqueArgumentDefinitionNamesRule,
|
|
90
|
+
known_directives_rule_js_1.KnownDirectivesRule,
|
|
91
|
+
unique_directives_per_location_rule_js_1.UniqueDirectivesPerLocationRule,
|
|
92
|
+
known_argument_names_on_directives_rule_js_1.KnownArgumentNamesOnDirectivesRule,
|
|
93
|
+
unique_argument_names_rule_js_1.UniqueArgumentNamesRule,
|
|
94
|
+
unique_input_field_names_rule_js_1.UniqueInputFieldNamesRule,
|
|
95
|
+
unique_directive_names_rule_js_1.UniqueDirectiveNamesRule,
|
|
96
|
+
provided_required_arguments_on_directives_rule_js_1.ProvidedRequiredArgumentsOnDirectivesRule,
|
|
97
|
+
provided_arguments_on_directives_rule_js_1.ProvidedArgumentsOnDirectivesRule,
|
|
98
|
+
];
|
|
99
|
+
(0, graphql_1.visit)(subgraph.typeDefs, (0, type_node_info_js_1.visitWithTypeNodeInfo)(typeNodeInfo, (0, graphql_1.visitInParallel)([stateBuilder.visitor(typeNodeInfo)].concat(federationRules.map(rule => {
|
|
100
|
+
if (rulesToSkip.includes(rule.name)) {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
return rule(validationContext);
|
|
104
|
+
})))));
|
|
105
|
+
const federationDefinitionReplacements = validationContext.collectFederationDefinitionReplacements();
|
|
106
|
+
const fullTypeDefs = (0, graphql_1.concatAST)([
|
|
107
|
+
{
|
|
108
|
+
kind: graphql_1.Kind.DOCUMENT,
|
|
109
|
+
definitions: validationContext
|
|
110
|
+
.getAvailableFederationTypeAndDirectiveDefinitions()
|
|
111
|
+
.filter(def => !federationDefinitionReplacements.has(def.name.value)),
|
|
112
|
+
},
|
|
113
|
+
validationContext.satisfiesVersionRange('> v1.0') && !stateBuilder.state.specs.link
|
|
114
|
+
?
|
|
115
|
+
(0, graphql_1.parse)(`
|
|
116
|
+
scalar Import
|
|
117
|
+
enum Purpose {
|
|
118
|
+
EXECUTION
|
|
119
|
+
SECURITY
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
directive @link(
|
|
123
|
+
url: String
|
|
124
|
+
as: String
|
|
125
|
+
for: link__Purpose
|
|
126
|
+
import: [link__Import]
|
|
127
|
+
) repeatable on SCHEMA
|
|
128
|
+
|
|
129
|
+
scalar link__Import
|
|
130
|
+
|
|
131
|
+
enum link__Purpose {
|
|
132
|
+
"""
|
|
133
|
+
\`SECURITY\` features provide metadata necessary to securely resolve fields.
|
|
134
|
+
"""
|
|
135
|
+
SECURITY
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
\`EXECUTION\` features provide metadata necessary for operation execution.
|
|
139
|
+
"""
|
|
140
|
+
EXECUTION
|
|
141
|
+
}
|
|
142
|
+
`)
|
|
143
|
+
: null,
|
|
144
|
+
subgraph.typeDefs,
|
|
145
|
+
].filter(onlyDocumentNode));
|
|
146
|
+
const subgraphStateErrors = (0, validate_state_js_1.validateSubgraphState)(stateBuilder.state);
|
|
147
|
+
const simpleValidationContext = (0, validation_context_js_1.createSimpleValidationContext)(fullTypeDefs, typeNodeInfo);
|
|
148
|
+
(0, graphql_1.visit)(fullTypeDefs, (0, graphql_1.visitInParallel)(graphqlRules.map(rule => {
|
|
149
|
+
if (rulesToSkip.includes(rule.name)) {
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
return rule(simpleValidationContext);
|
|
153
|
+
})));
|
|
154
|
+
return validationContext
|
|
155
|
+
.collectReportedErrors()
|
|
156
|
+
.concat(validationContext.collectUnusedExternal().map(coordinate => enrichErrorWithSubgraphName(new graphql_1.GraphQLError(`Field "${coordinate}" is marked @external but is not used in any federation directive (@key, @provides, @requires) or to satisfy an interface; the field declaration has no use and should be removed (or the field should not be @external).`, {
|
|
157
|
+
extensions: {
|
|
158
|
+
code: 'EXTERNAL_UNUSED',
|
|
159
|
+
},
|
|
160
|
+
}), subgraph.name)))
|
|
161
|
+
.concat(simpleValidationContext.collectReportedErrors())
|
|
162
|
+
.concat(subgraphStateErrors)
|
|
163
|
+
.map(error => enrichErrorWithSubgraphName(error, subgraph.name));
|
|
164
|
+
}
|
|
165
|
+
exports.validateSubgraph = validateSubgraph;
|
|
166
|
+
function enrichErrorWithSubgraphName(error, subgraphName) {
|
|
167
|
+
if (error.extensions.subgraphName) {
|
|
168
|
+
return error;
|
|
169
|
+
}
|
|
170
|
+
error.message = `[${subgraphName}] ${error.message}`;
|
|
171
|
+
error.extensions.subgraphName = subgraphName;
|
|
172
|
+
return error;
|
|
173
|
+
}
|
|
174
|
+
const availableFeatures = {
|
|
175
|
+
link: ['v1.0'],
|
|
176
|
+
tag: ['v0.1', 'v0.2'],
|
|
177
|
+
kotlin_labs: ['v0.1', 'v0.2'],
|
|
178
|
+
join: ['v0.1', 'v0.2', 'v0.3'],
|
|
179
|
+
inaccessible: ['v0.1', 'v0.2'],
|
|
180
|
+
core: ['v0.1', 'v0.2'],
|
|
181
|
+
};
|
|
182
|
+
function extractLinks(subgraph) {
|
|
183
|
+
const schemaNodes = subgraph.typeDefs.definitions.filter(isSchemaDefinitionOrExtensionNode);
|
|
184
|
+
if (schemaNodes.length === 0) {
|
|
185
|
+
return {
|
|
186
|
+
links: [],
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const linkDirectives = [];
|
|
190
|
+
for (const schemaNode of schemaNodes) {
|
|
191
|
+
if (schemaNode.directives?.length) {
|
|
192
|
+
for (const directiveNode of schemaNode.directives) {
|
|
193
|
+
if (directiveNode.name.value === 'link') {
|
|
194
|
+
linkDirectives.push(directiveNode);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (!linkDirectives) {
|
|
200
|
+
return {
|
|
201
|
+
links: [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const errors = [];
|
|
205
|
+
const links = [];
|
|
206
|
+
const identities = new Set();
|
|
207
|
+
const reportedAsDuplicate = new Set();
|
|
208
|
+
for (let i = 0; i < linkDirectives.length; i++) {
|
|
209
|
+
const linkDirective = linkDirectives[i];
|
|
210
|
+
try {
|
|
211
|
+
const link = (0, link_js_1.parseLinkDirective)(linkDirective);
|
|
212
|
+
if (!link) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (identities.has(link.identity) && !reportedAsDuplicate.has(link.identity)) {
|
|
216
|
+
errors.push(new graphql_1.GraphQLError(`Duplicate inclusion of feature ${link.identity}`, {
|
|
217
|
+
extensions: {
|
|
218
|
+
code: 'INVALID_LINK_DIRECTIVE_USAGE',
|
|
219
|
+
},
|
|
220
|
+
}));
|
|
221
|
+
reportedAsDuplicate.add(link.identity);
|
|
222
|
+
}
|
|
223
|
+
identities.add(link.identity);
|
|
224
|
+
if (link.version && !/^v\d+\.\d+/.test(link.version)) {
|
|
225
|
+
errors.push(new graphql_1.GraphQLError(`Expected a version string (of the form v1.2), got ${link.version}`, {
|
|
226
|
+
extensions: {
|
|
227
|
+
code: 'INVALID_LINK_IDENTIFIER',
|
|
228
|
+
},
|
|
229
|
+
}));
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (!link.name) {
|
|
233
|
+
errors.push(new graphql_1.GraphQLError(`Missing path in feature url '${link.identity}'`, {
|
|
234
|
+
extensions: {
|
|
235
|
+
code: 'INVALID_LINK_IDENTIFIER',
|
|
236
|
+
},
|
|
237
|
+
}));
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (link.identity.startsWith('https://specs.apollo.dev/')) {
|
|
241
|
+
if (link.name === 'federation') {
|
|
242
|
+
if (!link.version) {
|
|
243
|
+
errors.push(new graphql_1.GraphQLError(`Missing version in feature url '${link.identity}'`, {
|
|
244
|
+
extensions: {
|
|
245
|
+
code: 'TODO',
|
|
246
|
+
},
|
|
247
|
+
}));
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const spec = (0, federation_js_1.createSpecSchema)(link.version);
|
|
251
|
+
const availableElements = new Set(spec.directives.map(d => d.name.value).concat(spec.types.map(t => t.name.value)));
|
|
252
|
+
let pushedError = false;
|
|
253
|
+
for (const im of link.imports) {
|
|
254
|
+
if (!availableElements.has(im.name.replace(/^@/, ''))) {
|
|
255
|
+
pushedError = true;
|
|
256
|
+
errors.push(new graphql_1.GraphQLError(`Cannot import unknown element "${im.name}".`, {
|
|
257
|
+
extensions: {
|
|
258
|
+
code: 'INVALID_LINK_DIRECTIVE_USAGE',
|
|
259
|
+
},
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (pushedError) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else if (link.version && availableFeatures[link.name]) {
|
|
268
|
+
if (!availableFeatures[link.name].includes(link.version)) {
|
|
269
|
+
errors.push(new graphql_1.GraphQLError(`Schema uses unknown version ${link.version} of the ${link.name} spec`, {
|
|
270
|
+
extensions: {
|
|
271
|
+
code: 'UNKNOWN_LINK_VERSION',
|
|
272
|
+
},
|
|
273
|
+
}));
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
links.push(link);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
errors.push(error instanceof graphql_1.GraphQLError ? error : new graphql_1.GraphQLError(String(error)));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (errors.length > 0) {
|
|
285
|
+
return {
|
|
286
|
+
errors,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
links,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function isSchemaDefinitionOrExtensionNode(node) {
|
|
294
|
+
return (node.kind === graphql_1.Kind.SCHEMA_DEFINITION || node.kind === graphql_1.Kind.SCHEMA_EXTENSION);
|
|
295
|
+
}
|
|
296
|
+
function onlyDocumentNode(item) {
|
|
297
|
+
return item != null;
|
|
298
|
+
}
|
|
299
|
+
function cleanSubgraphTypeDefsFromSubgraphSpec(typeDefs) {
|
|
300
|
+
let queryTypes = [];
|
|
301
|
+
typeDefs.definitions = typeDefs.definitions.filter(def => {
|
|
302
|
+
if (def.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION && def.name.value === '_Any') {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
if (def.kind === graphql_1.Kind.UNION_TYPE_DEFINITION && def.name.value === '_Entity') {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
if (def.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION && def.name.value === '_Service') {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
if ((def.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION || def.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION) &&
|
|
312
|
+
def.name.value === 'Query') {
|
|
313
|
+
queryTypes.push(def);
|
|
314
|
+
}
|
|
315
|
+
return true;
|
|
316
|
+
});
|
|
317
|
+
if (queryTypes.length > 0) {
|
|
318
|
+
for (const queryType of queryTypes) {
|
|
319
|
+
queryType.fields =
|
|
320
|
+
queryType.fields?.filter(field => {
|
|
321
|
+
if (field.name.value === '_service' || field.name.value === '_entities') {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}) ?? [];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return typeDefs;
|
|
329
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSubgraphValidationContext = exports.createSimpleValidationContext = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const federation_js_1 = require("../../specifications/federation.js");
|
|
6
|
+
const state_js_1 = require("../../utils/state.js");
|
|
7
|
+
const state_js_2 = require("../state.js");
|
|
8
|
+
function createSimpleValidationContext(typeDefs, typeNodeInfo) {
|
|
9
|
+
let reportedErrors = [];
|
|
10
|
+
const directiveDefinitionMap = new Map();
|
|
11
|
+
const typeDefinitionMap = new Map();
|
|
12
|
+
for (const definition of typeDefs.definitions) {
|
|
13
|
+
if (definition.kind === graphql_1.Kind.DIRECTIVE_DEFINITION) {
|
|
14
|
+
directiveDefinitionMap.set(definition.name.value, definition);
|
|
15
|
+
}
|
|
16
|
+
else if ('name' in definition && definition.name && definition.name.kind === graphql_1.Kind.NAME) {
|
|
17
|
+
typeDefinitionMap.set(definition.name.value, {
|
|
18
|
+
name: definition.name,
|
|
19
|
+
kind: definition.kind,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
getDocument() {
|
|
25
|
+
return typeDefs;
|
|
26
|
+
},
|
|
27
|
+
getKnownDirectiveDefinition(name) {
|
|
28
|
+
return directiveDefinitionMap.get(name);
|
|
29
|
+
},
|
|
30
|
+
getKnownTypeDefinition(name) {
|
|
31
|
+
return typeDefinitionMap.get(name);
|
|
32
|
+
},
|
|
33
|
+
getSchemaCoordinate(ancestors) {
|
|
34
|
+
let coordinate = '';
|
|
35
|
+
for (let i = 0; i < ancestors.length; i++) {
|
|
36
|
+
const ancestor = ancestors[i];
|
|
37
|
+
if ('kind' in ancestor && ancestor.kind !== graphql_1.Kind.DOCUMENT) {
|
|
38
|
+
const name = ancestor.kind === graphql_1.Kind.SCHEMA_DEFINITION || ancestor.kind === graphql_1.Kind.SCHEMA_EXTENSION
|
|
39
|
+
? 'schema'
|
|
40
|
+
: 'name' in ancestor && ancestor.name
|
|
41
|
+
? ancestor.name.value
|
|
42
|
+
: '';
|
|
43
|
+
if (coordinate.length > 0) {
|
|
44
|
+
coordinate = coordinate + '.' + name;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
coordinate = name;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return coordinate;
|
|
52
|
+
},
|
|
53
|
+
reportError(error) {
|
|
54
|
+
reportedErrors.push(error);
|
|
55
|
+
},
|
|
56
|
+
collectReportedErrors() {
|
|
57
|
+
const errors = reportedErrors;
|
|
58
|
+
reportedErrors = [];
|
|
59
|
+
return errors;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.createSimpleValidationContext = createSimpleValidationContext;
|
|
64
|
+
function createSubgraphValidationContext(subgraph, federation, typeNodeInfo, stateBuilder) {
|
|
65
|
+
const { version, imports } = federation;
|
|
66
|
+
const availableSpec = (0, federation_js_1.createSpecSchema)(version, imports);
|
|
67
|
+
const knownSpec = (0, federation_js_1.createSpecSchema)(version);
|
|
68
|
+
const knownSubgraphEntities = new Map(subgraph.typeDefs.definitions.filter(def => def.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION ||
|
|
69
|
+
def.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION ||
|
|
70
|
+
def.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION ||
|
|
71
|
+
def.kind === graphql_1.Kind.INTERFACE_TYPE_EXTENSION).map(def => [def.name.value, def]));
|
|
72
|
+
const knownSubgraphDirectiveDefinitions = new Map(subgraph.typeDefs.definitions.filter(def => def.kind === graphql_1.Kind.DIRECTIVE_DEFINITION).map(def => [def.name.value, def]));
|
|
73
|
+
const leafTypeNames = new Set(graphql_1.specifiedScalarTypes.map(type => type.name));
|
|
74
|
+
for (const def of subgraph.typeDefs.definitions) {
|
|
75
|
+
if (def.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION ||
|
|
76
|
+
def.kind === graphql_1.Kind.SCALAR_TYPE_EXTENSION ||
|
|
77
|
+
def.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION ||
|
|
78
|
+
def.kind === graphql_1.Kind.ENUM_TYPE_EXTENSION) {
|
|
79
|
+
leafTypeNames.add(def.name.value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let reportedErrors = [];
|
|
83
|
+
const markedAsExternal = new Set();
|
|
84
|
+
const markedAsUsed = new Set();
|
|
85
|
+
const markedAsKeyField = new Set();
|
|
86
|
+
const overwrittenFederationDefinitionNames = new Set();
|
|
87
|
+
const directiveAlternativeNamesMap = new Map();
|
|
88
|
+
for (const specDirective of availableSpec.directives) {
|
|
89
|
+
const isFederationPrefixed = specDirective.name.value.startsWith('federation__');
|
|
90
|
+
if (isFederationPrefixed) {
|
|
91
|
+
const normalizedName = specDirective.name.value.replace('federation__', '');
|
|
92
|
+
const setOfNames = directiveAlternativeNamesMap.get(normalizedName);
|
|
93
|
+
if (!setOfNames) {
|
|
94
|
+
directiveAlternativeNamesMap.set(normalizedName, new Set([specDirective.name.value]));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const { alias } = imports.find(i => i.name.replace(/^@/, '') === specDirective.name.value) ?? {
|
|
99
|
+
alias: undefined,
|
|
100
|
+
};
|
|
101
|
+
let setOfNames = directiveAlternativeNamesMap.get(specDirective.name.value);
|
|
102
|
+
if (!setOfNames) {
|
|
103
|
+
directiveAlternativeNamesMap.set(specDirective.name.value, new Set());
|
|
104
|
+
setOfNames = directiveAlternativeNamesMap.get(specDirective.name.value);
|
|
105
|
+
}
|
|
106
|
+
setOfNames.add(alias ? alias.replace(/^@/, '') : specDirective.name.value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const typeAlternativeNamesMap = new Map();
|
|
110
|
+
for (const specType of availableSpec.types) {
|
|
111
|
+
const isFederationPrefixed = specType.name.value.startsWith('federation__');
|
|
112
|
+
if (isFederationPrefixed) {
|
|
113
|
+
const normalizedName = specType.name.value.replace('federation__', '');
|
|
114
|
+
const setOfNames = typeAlternativeNamesMap.get(normalizedName);
|
|
115
|
+
if (!setOfNames) {
|
|
116
|
+
typeAlternativeNamesMap.set(normalizedName, new Set([specType.name.value]));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const { alias } = imports.find(i => i.name === specType.name.value) ?? {
|
|
121
|
+
alias: undefined,
|
|
122
|
+
};
|
|
123
|
+
let setOfNames = typeAlternativeNamesMap.get(specType.name.value);
|
|
124
|
+
if (!setOfNames) {
|
|
125
|
+
typeAlternativeNamesMap.set(specType.name.value, new Set());
|
|
126
|
+
setOfNames = typeAlternativeNamesMap.get(specType.name.value);
|
|
127
|
+
}
|
|
128
|
+
setOfNames.add(alias ? alias : specType.name.value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const importedTypesSet = new Set(availableSpec.types.map(t => t.name.value));
|
|
132
|
+
if (importedTypesSet.size) {
|
|
133
|
+
subgraph.typeDefs.definitions.forEach(def => {
|
|
134
|
+
if ('name' in def && def.name && importedTypesSet.has(def.name.value)) {
|
|
135
|
+
overwrittenFederationDefinitionNames.add(def.name.value);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
stateBuilder,
|
|
141
|
+
isAvailableFederationType(name) {
|
|
142
|
+
const alternativeNames = typeAlternativeNamesMap.get(name);
|
|
143
|
+
if (alternativeNames) {
|
|
144
|
+
return alternativeNames.has(name);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
},
|
|
148
|
+
isAvailableFederationDirective(specDirectiveName, directiveNode) {
|
|
149
|
+
const alternativeNames = directiveAlternativeNamesMap.get(specDirectiveName);
|
|
150
|
+
if (alternativeNames) {
|
|
151
|
+
return alternativeNames.has(typeof directiveNode.name === 'string' ? directiveNode.name : directiveNode.name.value);
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
},
|
|
155
|
+
satisfiesVersionRange(range) {
|
|
156
|
+
const [sign, ver] = range.split(' ');
|
|
157
|
+
const versionInRange = parseFloat(ver.replace('v', ''));
|
|
158
|
+
const detectedVersion = parseFloat(version.replace('v', ''));
|
|
159
|
+
if (sign === '<') {
|
|
160
|
+
return detectedVersion < versionInRange;
|
|
161
|
+
}
|
|
162
|
+
if (sign === '>') {
|
|
163
|
+
return detectedVersion > versionInRange;
|
|
164
|
+
}
|
|
165
|
+
return detectedVersion >= versionInRange;
|
|
166
|
+
},
|
|
167
|
+
getKnownFederationDirectives() {
|
|
168
|
+
return knownSpec.directives;
|
|
169
|
+
},
|
|
170
|
+
getAvailableFederationDirectives() {
|
|
171
|
+
return availableSpec.directives;
|
|
172
|
+
},
|
|
173
|
+
isLeafType(typeName) {
|
|
174
|
+
return leafTypeNames.has(typeName);
|
|
175
|
+
},
|
|
176
|
+
getSubgraphObjectOrInterfaceTypes() {
|
|
177
|
+
return knownSubgraphEntities;
|
|
178
|
+
},
|
|
179
|
+
getSubgraphDirectiveDefinitions() {
|
|
180
|
+
return knownSubgraphDirectiveDefinitions;
|
|
181
|
+
},
|
|
182
|
+
getAvailableFederationTypeAndDirectiveDefinitions() {
|
|
183
|
+
return [].concat(availableSpec.directives.map(d => {
|
|
184
|
+
const alias = imports.find(i => i.name.replace(/^@/, '') === d.name.value)?.alias;
|
|
185
|
+
if (alias) {
|
|
186
|
+
d.name.value = alias.replace(/^@/, '');
|
|
187
|
+
}
|
|
188
|
+
return d;
|
|
189
|
+
}), availableSpec.types.map(t => {
|
|
190
|
+
const alias = imports.find(i => i.name === t.name.value)?.alias;
|
|
191
|
+
if (alias) {
|
|
192
|
+
t.name.value = alias;
|
|
193
|
+
}
|
|
194
|
+
return t;
|
|
195
|
+
}));
|
|
196
|
+
},
|
|
197
|
+
typeNodeInfo,
|
|
198
|
+
getDocument() {
|
|
199
|
+
return subgraph.typeDefs;
|
|
200
|
+
},
|
|
201
|
+
getSubgraphName() {
|
|
202
|
+
return subgraph.name;
|
|
203
|
+
},
|
|
204
|
+
getSubgraphId() {
|
|
205
|
+
return subgraph.id;
|
|
206
|
+
},
|
|
207
|
+
markAsExternal(coordinate) {
|
|
208
|
+
markedAsExternal.add(coordinate);
|
|
209
|
+
},
|
|
210
|
+
markAsUsed(reason, kind, typeName, fieldName) {
|
|
211
|
+
if (!fieldName.startsWith('__') && !typeName.startsWith('__') && reason === 'fields') {
|
|
212
|
+
switch (kind) {
|
|
213
|
+
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
214
|
+
case graphql_1.Kind.OBJECT_TYPE_EXTENSION: {
|
|
215
|
+
stateBuilder.objectType.field.setUsed(typeName, fieldName);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
219
|
+
case graphql_1.Kind.INTERFACE_TYPE_EXTENSION: {
|
|
220
|
+
stateBuilder.interfaceType.field.setUsed(typeName, fieldName);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
markedAsUsed.add(`${typeName}.${fieldName}`);
|
|
226
|
+
},
|
|
227
|
+
markAsKeyField(coordinate) {
|
|
228
|
+
markedAsKeyField.add(coordinate);
|
|
229
|
+
},
|
|
230
|
+
markAsFederationDefinitionReplacement(name) {
|
|
231
|
+
overwrittenFederationDefinitionNames.add(name);
|
|
232
|
+
},
|
|
233
|
+
collectFederationDefinitionReplacements() {
|
|
234
|
+
return overwrittenFederationDefinitionNames;
|
|
235
|
+
},
|
|
236
|
+
collectUnusedExternal() {
|
|
237
|
+
if (version === 'v1.0') {
|
|
238
|
+
return Array.from(markedAsExternal).filter(c => !markedAsUsed.has(c) && markedAsKeyField.has(c));
|
|
239
|
+
}
|
|
240
|
+
const unused = Array.from(markedAsExternal).filter(c => !markedAsUsed.has(c));
|
|
241
|
+
return unused.filter(coordinate => {
|
|
242
|
+
const [typeName, fieldName] = coordinate.split('.');
|
|
243
|
+
const typeDef = stateBuilder.state.types.get(typeName);
|
|
244
|
+
if (typeDef && typeDef.kind === state_js_2.TypeKind.OBJECT) {
|
|
245
|
+
const fieldDef = typeDef.fields.get(fieldName);
|
|
246
|
+
if (fieldDef) {
|
|
247
|
+
const outputTypeName = (0, state_js_1.stripTypeModifiers)(fieldDef.type);
|
|
248
|
+
const outputType = stateBuilder.state.types.get(outputTypeName);
|
|
249
|
+
if (outputType?.kind === state_js_2.TypeKind.OBJECT && outputType.shareable) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
reportError(error) {
|
|
258
|
+
reportedErrors.push(error);
|
|
259
|
+
},
|
|
260
|
+
collectReportedErrors() {
|
|
261
|
+
const errors = reportedErrors;
|
|
262
|
+
reportedErrors = [];
|
|
263
|
+
return errors;
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
exports.createSubgraphValidationContext = createSubgraphValidationContext;
|