@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,14 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function SubgraphNameRule(context) {
|
|
3
|
+
for (const [_, subgraph] of context.subgraphStates) {
|
|
4
|
+
const id = subgraph.graph.id;
|
|
5
|
+
if (id.startsWith('__')) {
|
|
6
|
+
context.reportError(new GraphQLError(`Name "${id}" must not begin with "__", which is reserved by GraphQL introspection.`, {
|
|
7
|
+
extensions: {
|
|
8
|
+
code: 'INVALID_GRAPHQL',
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { TypeKind } from '../../../subgraph/state.js';
|
|
3
|
+
const mapIRKindToString = {
|
|
4
|
+
[TypeKind.OBJECT]: 'Object',
|
|
5
|
+
[TypeKind.INTERFACE]: 'Interface',
|
|
6
|
+
[TypeKind.UNION]: 'Union',
|
|
7
|
+
[TypeKind.ENUM]: 'Enum',
|
|
8
|
+
[TypeKind.INPUT_OBJECT]: 'InputObject',
|
|
9
|
+
[TypeKind.SCALAR]: 'Scalar',
|
|
10
|
+
[TypeKind.DIRECTIVE]: 'Directive',
|
|
11
|
+
};
|
|
12
|
+
export function TypesOfTheSameKindRule(context) {
|
|
13
|
+
const typeToKindWithGraphs = new Map();
|
|
14
|
+
const typesWithConflict = new Set();
|
|
15
|
+
for (const [graph, state] of context.subgraphStates) {
|
|
16
|
+
state.types.forEach(type => {
|
|
17
|
+
const kindToGraphs = typeToKindWithGraphs.get(type.name);
|
|
18
|
+
if (kindToGraphs) {
|
|
19
|
+
const graphs = kindToGraphs.get(type.kind);
|
|
20
|
+
if (graphs) {
|
|
21
|
+
graphs.add(graph);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
kindToGraphs.set(type.kind, new Set([graph]));
|
|
25
|
+
}
|
|
26
|
+
if (kindToGraphs.size > 1) {
|
|
27
|
+
typesWithConflict.add(type.name);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
typeToKindWithGraphs.set(type.name, new Map([[type.kind, new Set([graph])]]));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
for (const typeName of typesWithConflict) {
|
|
36
|
+
const kindToGraphs = typeToKindWithGraphs.get(typeName);
|
|
37
|
+
const groups = Array.from(kindToGraphs.entries()).map(([kind, graphs]) => {
|
|
38
|
+
const plural = graphs.size > 1 ? 's' : '';
|
|
39
|
+
return `${mapIRKindToString[kind]} Type in subgraph${plural} "${Array.from(graphs)
|
|
40
|
+
.map(context.graphIdToName)
|
|
41
|
+
.join('", "')}"`;
|
|
42
|
+
});
|
|
43
|
+
const [first, second, ...rest] = groups;
|
|
44
|
+
context.reportError(new GraphQLError(`Type "${typeName}" has mismatched kind: it is defined as ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
|
|
45
|
+
extensions: {
|
|
46
|
+
code: 'TYPE_KIND_MISMATCH',
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { visitSupergraphState } from '../composition/visitor.js';
|
|
2
|
+
import { DefaultValueUsesInaccessibleRule } from './rules/default-value-uses-inaccessible-rule.js';
|
|
3
|
+
import { DirectiveCompositionRule } from './rules/directive-composition-rule.js';
|
|
4
|
+
import { EnumValuesRule } from './rules/enum-values-rule.js';
|
|
5
|
+
import { ExtensionWithBaseRule } from './rules/extension-with-base.js';
|
|
6
|
+
import { ExternalArgumentMissingRule } from './rules/external-argument-missing-rule.js';
|
|
7
|
+
import { ExternalMissingOnBaseRule } from './rules/external-missing-on-base-rule.js';
|
|
8
|
+
import { ExternalTypeMismatchRule } from './rules/external-type-mismatch-rule.js';
|
|
9
|
+
import { FieldArgumentDefaultMismatchRule } from './rules/field-argument-default-mismatch-rule.js';
|
|
10
|
+
import { FieldArgumentsOfTheSameTypeRule } from './rules/field-arguments-of-the-same-type-rule.js';
|
|
11
|
+
import { FieldsOfTheSameTypeRule } from './rules/fields-of-the-same-type-rule.js';
|
|
12
|
+
import { InputFieldDefaultMismatchRule } from './rules/input-field-default-mismatch-rule.js';
|
|
13
|
+
import { InputObjectValuesRule } from './rules/input-object-values-rule.js';
|
|
14
|
+
import { InterfaceKeyMissingImplementationTypeRule } from './rules/interface-key-missing-implementation-type.js';
|
|
15
|
+
import { InvalidFieldSharingRule } from './rules/invalid-field-sharing-rule.js';
|
|
16
|
+
import { OnlyInaccessibleChildrenRule } from './rules/only-inaccessible-children-rule.js';
|
|
17
|
+
import { OverrideSourceHasOverrideRule } from './rules/override-source-has-override.js';
|
|
18
|
+
import { ReferencedInaccessibleRule } from './rules/referenced-inaccessible-rule.js';
|
|
19
|
+
import { RequiredArgumentMissingInSomeSubgraph } from './rules/required-argument-missing-in-some-subgraph-rule.js';
|
|
20
|
+
import { RequiredInputFieldMissingInSomeSubgraphRule } from './rules/required-input-field-missing-in-some-subgraph-rule.js';
|
|
21
|
+
import { RequiredQueryRule } from './rules/required-query-rule.js';
|
|
22
|
+
import { SatisfiabilityRule } from './rules/satisfiablity-rule.js';
|
|
23
|
+
import { SubgraphNameRule } from './rules/subgraph-name-rule.js';
|
|
24
|
+
import { TypesOfTheSameKindRule } from './rules/types-of-the-same-kind-rule.js';
|
|
25
|
+
import { createSupergraphValidationContext } from './validation-context.js';
|
|
26
|
+
export function validateSupergraph(subgraphStates, state, __internal) {
|
|
27
|
+
const context = createSupergraphValidationContext(subgraphStates);
|
|
28
|
+
for (const subgraphState of subgraphStates.values()) {
|
|
29
|
+
state.addGraph(subgraphState.graph);
|
|
30
|
+
}
|
|
31
|
+
const preSupergraphRules = [RequiredQueryRule, TypesOfTheSameKindRule];
|
|
32
|
+
const rulesToSkip = __internal?.disableValidationRules ?? [];
|
|
33
|
+
for (const rule of preSupergraphRules) {
|
|
34
|
+
if (rulesToSkip.includes(rule.name)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
rule(context);
|
|
38
|
+
}
|
|
39
|
+
for (const subgraphState of subgraphStates.values()) {
|
|
40
|
+
state.visitSubgraphState(subgraphState);
|
|
41
|
+
}
|
|
42
|
+
const postSupergraphRules = [
|
|
43
|
+
ExtensionWithBaseRule,
|
|
44
|
+
FieldsOfTheSameTypeRule,
|
|
45
|
+
FieldArgumentsOfTheSameTypeRule,
|
|
46
|
+
EnumValuesRule,
|
|
47
|
+
OverrideSourceHasOverrideRule,
|
|
48
|
+
ExternalMissingOnBaseRule,
|
|
49
|
+
InputObjectValuesRule,
|
|
50
|
+
RequiredArgumentMissingInSomeSubgraph,
|
|
51
|
+
RequiredInputFieldMissingInSomeSubgraphRule,
|
|
52
|
+
ExternalArgumentMissingRule,
|
|
53
|
+
InputFieldDefaultMismatchRule,
|
|
54
|
+
FieldArgumentDefaultMismatchRule,
|
|
55
|
+
DefaultValueUsesInaccessibleRule,
|
|
56
|
+
OnlyInaccessibleChildrenRule,
|
|
57
|
+
ReferencedInaccessibleRule,
|
|
58
|
+
DirectiveCompositionRule,
|
|
59
|
+
InterfaceKeyMissingImplementationTypeRule,
|
|
60
|
+
ExternalTypeMismatchRule,
|
|
61
|
+
InvalidFieldSharingRule,
|
|
62
|
+
SatisfiabilityRule,
|
|
63
|
+
SubgraphNameRule,
|
|
64
|
+
];
|
|
65
|
+
const supergraph = state.getSupergraphState();
|
|
66
|
+
visitSupergraphState(supergraph, postSupergraphRules.map(rule => {
|
|
67
|
+
if (rulesToSkip.includes(rule.name)) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
return rule(context, supergraph);
|
|
71
|
+
}));
|
|
72
|
+
return context.collectReportedErrors();
|
|
73
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function createSupergraphValidationContext(subgraphStates) {
|
|
2
|
+
let reportedErrors = [];
|
|
3
|
+
return {
|
|
4
|
+
subgraphStates,
|
|
5
|
+
graphIdToName(id) {
|
|
6
|
+
const found = subgraphStates.get(id);
|
|
7
|
+
if (!found) {
|
|
8
|
+
throw new Error(`Could not find subgraph with id ${id}`);
|
|
9
|
+
}
|
|
10
|
+
return found.graph.name;
|
|
11
|
+
},
|
|
12
|
+
reportError(error) {
|
|
13
|
+
reportedErrors.push(error);
|
|
14
|
+
},
|
|
15
|
+
collectReportedErrors() {
|
|
16
|
+
const errors = reportedErrors;
|
|
17
|
+
reportedErrors = [];
|
|
18
|
+
return errors;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
package/esm/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
function createDFS(edges, leavesOnly, result, circular) {
|
|
2
|
+
const visited = {};
|
|
3
|
+
return function (start) {
|
|
4
|
+
if (visited[start]) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const inCurrentPath = {};
|
|
8
|
+
const currentPath = [];
|
|
9
|
+
const todo = [];
|
|
10
|
+
todo.push({ node: start, processed: false });
|
|
11
|
+
while (todo.length > 0) {
|
|
12
|
+
const current = todo[todo.length - 1];
|
|
13
|
+
const processed = current.processed;
|
|
14
|
+
const node = current.node;
|
|
15
|
+
if (!processed) {
|
|
16
|
+
if (visited[node]) {
|
|
17
|
+
todo.pop();
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
else if (inCurrentPath[node]) {
|
|
21
|
+
if (circular) {
|
|
22
|
+
todo.pop();
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
currentPath.push(node);
|
|
26
|
+
throw new DepGraphCycleError(currentPath);
|
|
27
|
+
}
|
|
28
|
+
inCurrentPath[node] = true;
|
|
29
|
+
currentPath.push(node);
|
|
30
|
+
const nodeEdges = edges[node];
|
|
31
|
+
for (let i = nodeEdges.length - 1; i >= 0; i--) {
|
|
32
|
+
todo.push({ node: nodeEdges[i], processed: false });
|
|
33
|
+
}
|
|
34
|
+
current.processed = true;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
todo.pop();
|
|
38
|
+
currentPath.pop();
|
|
39
|
+
inCurrentPath[node] = false;
|
|
40
|
+
visited[node] = true;
|
|
41
|
+
if (!leavesOnly || edges[node].length === 0) {
|
|
42
|
+
result.push(node);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export class DepGraph {
|
|
49
|
+
nodes = {};
|
|
50
|
+
outgoingEdges = {};
|
|
51
|
+
incomingEdges = {};
|
|
52
|
+
circular;
|
|
53
|
+
constructor(opts) {
|
|
54
|
+
this.circular = opts?.circular ?? false;
|
|
55
|
+
}
|
|
56
|
+
size() {
|
|
57
|
+
return Object.keys(this.nodes).length;
|
|
58
|
+
}
|
|
59
|
+
addNode(name, data) {
|
|
60
|
+
if (!this.hasNode(name)) {
|
|
61
|
+
if (arguments.length === 2) {
|
|
62
|
+
this.nodes[name] = data;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.nodes[name] = name;
|
|
66
|
+
}
|
|
67
|
+
this.outgoingEdges[name] = [];
|
|
68
|
+
this.incomingEdges[name] = [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
removeNode(name) {
|
|
72
|
+
if (this.hasNode(name)) {
|
|
73
|
+
delete this.nodes[name];
|
|
74
|
+
delete this.outgoingEdges[name];
|
|
75
|
+
delete this.incomingEdges[name];
|
|
76
|
+
[this.incomingEdges, this.outgoingEdges].forEach(edgeList => {
|
|
77
|
+
Object.keys(edgeList).forEach(key => {
|
|
78
|
+
const idx = edgeList[key].indexOf(name);
|
|
79
|
+
if (idx >= 0) {
|
|
80
|
+
edgeList[key].splice(idx, 1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
hasNode(name) {
|
|
87
|
+
return this.nodes.hasOwnProperty(name);
|
|
88
|
+
}
|
|
89
|
+
getNodeData(name) {
|
|
90
|
+
if (this.hasNode(name)) {
|
|
91
|
+
return this.nodes[name];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error('Node does not exist: ' + name);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
setNodeData(name, data) {
|
|
98
|
+
if (this.hasNode(name)) {
|
|
99
|
+
this.nodes[name] = data;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new Error('Node does not exist: ' + name);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
addDependency(from, to) {
|
|
106
|
+
if (!this.hasNode(from)) {
|
|
107
|
+
throw new Error('Node does not exist: ' + from);
|
|
108
|
+
}
|
|
109
|
+
if (!this.hasNode(to)) {
|
|
110
|
+
throw new Error('Node does not exist: ' + to);
|
|
111
|
+
}
|
|
112
|
+
if (this.outgoingEdges[from].indexOf(to) === -1) {
|
|
113
|
+
this.outgoingEdges[from].push(to);
|
|
114
|
+
}
|
|
115
|
+
if (this.incomingEdges[to].indexOf(from) === -1) {
|
|
116
|
+
this.incomingEdges[to].push(from);
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
removeDependency(from, to) {
|
|
121
|
+
let idx;
|
|
122
|
+
if (this.hasNode(from)) {
|
|
123
|
+
idx = this.outgoingEdges[from].indexOf(to);
|
|
124
|
+
if (idx >= 0) {
|
|
125
|
+
this.outgoingEdges[from].splice(idx, 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this.hasNode(to)) {
|
|
129
|
+
idx = this.incomingEdges[to].indexOf(from);
|
|
130
|
+
if (idx >= 0) {
|
|
131
|
+
this.incomingEdges[to].splice(idx, 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
directDependenciesOf(name) {
|
|
136
|
+
if (this.hasNode(name)) {
|
|
137
|
+
return this.outgoingEdges[name].slice(0);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw new Error('Node does not exist: ' + name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
directDependantsOf(name) {
|
|
144
|
+
if (this.hasNode(name)) {
|
|
145
|
+
return this.incomingEdges[name].slice(0);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error('Node does not exist: ' + name);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
dependenciesOf(name, leavesOnly) {
|
|
152
|
+
if (this.hasNode(name)) {
|
|
153
|
+
const result = [];
|
|
154
|
+
const DFS = createDFS(this.outgoingEdges, leavesOnly, result, this.circular);
|
|
155
|
+
DFS(name);
|
|
156
|
+
const idx = result.indexOf(name);
|
|
157
|
+
if (idx >= 0) {
|
|
158
|
+
result.splice(idx, 1);
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
throw new Error('Node does not exist: ' + name);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
dependantsOf(name, leavesOnly) {
|
|
167
|
+
if (this.hasNode(name)) {
|
|
168
|
+
const result = [];
|
|
169
|
+
const DFS = createDFS(this.incomingEdges, leavesOnly, result, this.circular);
|
|
170
|
+
DFS(name);
|
|
171
|
+
const idx = result.indexOf(name);
|
|
172
|
+
if (idx >= 0) {
|
|
173
|
+
result.splice(idx, 1);
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
throw new Error('Node does not exist: ' + name);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
overallOrder(leavesOnly) {
|
|
182
|
+
const result = [];
|
|
183
|
+
const keys = Object.keys(this.nodes);
|
|
184
|
+
if (keys.length === 0) {
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if (!this.circular) {
|
|
189
|
+
const CycleDFS = createDFS(this.outgoingEdges, false, [], this.circular);
|
|
190
|
+
keys.forEach(function (n) {
|
|
191
|
+
CycleDFS(n);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const DFS = createDFS(this.outgoingEdges, leavesOnly, result, this.circular);
|
|
195
|
+
keys
|
|
196
|
+
.filter(node => this.incomingEdges[node].length === 0)
|
|
197
|
+
.forEach(n => {
|
|
198
|
+
DFS(n);
|
|
199
|
+
});
|
|
200
|
+
if (this.circular) {
|
|
201
|
+
keys
|
|
202
|
+
.filter(node => result.indexOf(node) === -1)
|
|
203
|
+
.forEach(function (n) {
|
|
204
|
+
DFS(n);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
entryNodes() {
|
|
211
|
+
return Object.keys(this.nodes).filter(node => this.incomingEdges[node].length === 0);
|
|
212
|
+
}
|
|
213
|
+
directDependentsOf = this.directDependantsOf;
|
|
214
|
+
dependentsOf = this.dependantsOf;
|
|
215
|
+
}
|
|
216
|
+
export class DepGraphCycleError extends Error {
|
|
217
|
+
cyclePath;
|
|
218
|
+
constructor(cyclePath) {
|
|
219
|
+
super('Dependency Cycle Found: ' + cyclePath.join(' -> '));
|
|
220
|
+
this.cyclePath = cyclePath;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function andList(items, commaBeforeConjunction = true, wrapper) {
|
|
2
|
+
return formatList('and', items, commaBeforeConjunction, wrapper);
|
|
3
|
+
}
|
|
4
|
+
function formatList(conjunction, items, commaBeforeConjunction = true, wrapper) {
|
|
5
|
+
if (items.length === 0) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
switch (items.length) {
|
|
9
|
+
case 1:
|
|
10
|
+
return withWrapper(items[0], wrapper);
|
|
11
|
+
case 2:
|
|
12
|
+
return (withWrapper(items[0], wrapper) + ' ' + conjunction + ' ' + withWrapper(items[1], wrapper));
|
|
13
|
+
}
|
|
14
|
+
const allButLast = items.slice(0, -1).map(item => withWrapper(item, wrapper));
|
|
15
|
+
const lastItem = withWrapper(items.at(-1), wrapper);
|
|
16
|
+
return (allButLast.join(', ') + (commaBeforeConjunction ? ', ' : ' ') + conjunction + ' ' + lastItem);
|
|
17
|
+
}
|
|
18
|
+
function withWrapper(text, wrapper) {
|
|
19
|
+
if (!wrapper) {
|
|
20
|
+
return text;
|
|
21
|
+
}
|
|
22
|
+
return wrapper + text + wrapper;
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function stripTypeModifiers(type) {
|
|
2
|
+
return type.replaceAll('!', '').replaceAll('[', '').replaceAll(']', '');
|
|
3
|
+
}
|
|
4
|
+
export function stripNonNull(type) {
|
|
5
|
+
return type.replace(/\!$/, '');
|
|
6
|
+
}
|
|
7
|
+
export function stripList(type) {
|
|
8
|
+
return type.replace(/^\[/, '').replace(/\]$/, '');
|
|
9
|
+
}
|
|
10
|
+
export function isNonNull(type) {
|
|
11
|
+
return type.endsWith('!');
|
|
12
|
+
}
|
|
13
|
+
export function isList(type) {
|
|
14
|
+
return type.endsWith(']');
|
|
15
|
+
}
|
package/esm/validate.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { constantCase } from 'constant-case';
|
|
2
|
+
import { detectFederationVersion } from './specifications/federation.js';
|
|
3
|
+
import { cleanSubgraphStateFromFederationSpec, cleanSubgraphStateFromLinkSpec, createSubgraphStateBuilder, } from './subgraph/state.js';
|
|
4
|
+
import { validateSubgraph, validateSubgraphCore } from './subgraph/validation/validate-subgraph.js';
|
|
5
|
+
import { createSupergraphStateBuilder } from './supergraph/state.js';
|
|
6
|
+
import { validateSupergraph } from './supergraph/validation/validate-supergraph.js';
|
|
7
|
+
const numberAtStartRegex = /^\d/;
|
|
8
|
+
function startsWithNumber(value) {
|
|
9
|
+
return numberAtStartRegex.test(value);
|
|
10
|
+
}
|
|
11
|
+
function buildGraphList(subgraphs) {
|
|
12
|
+
const errors = [];
|
|
13
|
+
const graphs = [];
|
|
14
|
+
const names = new Set();
|
|
15
|
+
const idCounter = new Map();
|
|
16
|
+
for (const subgraph of subgraphs) {
|
|
17
|
+
const name = String(subgraph.name);
|
|
18
|
+
const nameStartsWithNumber = startsWithNumber(name);
|
|
19
|
+
if (names.has(name)) {
|
|
20
|
+
throw new Error(`A subgraph named ${name} already exists`);
|
|
21
|
+
}
|
|
22
|
+
const { url, typeDefs } = subgraph;
|
|
23
|
+
names.add(name);
|
|
24
|
+
let proposedId = constantCase(name.replace(/[^A-Z0-9]/gi, '_'), {
|
|
25
|
+
stripRegexp: /[^A-Z0-9_]+/gi,
|
|
26
|
+
});
|
|
27
|
+
if (nameStartsWithNumber) {
|
|
28
|
+
proposedId = '_' + proposedId + '_';
|
|
29
|
+
}
|
|
30
|
+
let count = idCounter.get(proposedId);
|
|
31
|
+
if (typeof count === 'number') {
|
|
32
|
+
if (count === 1) {
|
|
33
|
+
graphs.find(g => g.id === proposedId).id += '_1';
|
|
34
|
+
}
|
|
35
|
+
graphs.push({
|
|
36
|
+
name,
|
|
37
|
+
id: proposedId + '_' + (count + 1),
|
|
38
|
+
url,
|
|
39
|
+
typeDefs,
|
|
40
|
+
});
|
|
41
|
+
idCounter.set(proposedId, count + 1);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
idCounter.set(proposedId, 1);
|
|
45
|
+
graphs.push({
|
|
46
|
+
name,
|
|
47
|
+
id: proposedId,
|
|
48
|
+
url,
|
|
49
|
+
typeDefs,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (errors.length > 0) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
errors,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
graphs.sort((a, b) => a.id.localeCompare(b.id));
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
graphs,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function validate(subgraphs, __internal) {
|
|
66
|
+
const graphList = buildGraphList(subgraphs);
|
|
67
|
+
if (!graphList.success) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
errors: graphList.errors,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const corePerSubgraph = graphList.graphs.map(subgraph => validateSubgraphCore(subgraph));
|
|
74
|
+
const coreErrors = corePerSubgraph.map(core => core.errors ?? []).flat(1);
|
|
75
|
+
if (coreErrors.length > 0) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
errors: coreErrors,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const detectedFederationSpec = new Map(graphList.graphs.map(graph => [graph.id, detectFederationVersion(graph.typeDefs)]));
|
|
82
|
+
const subgraphStateBuilders = new Map(graphList.graphs.map((graph, i) => [
|
|
83
|
+
graph.id,
|
|
84
|
+
createSubgraphStateBuilder(graph, graph.typeDefs, detectedFederationSpec.get(graph.id).version, corePerSubgraph[i].links ?? []),
|
|
85
|
+
]));
|
|
86
|
+
const subgraphErrors = graphList.graphs
|
|
87
|
+
.map(graph => validateSubgraph(graph, subgraphStateBuilders.get(graph.id), detectedFederationSpec.get(graph.id), __internal))
|
|
88
|
+
.flat(1);
|
|
89
|
+
if (subgraphErrors.length > 0) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
errors: subgraphErrors,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const state = createSupergraphStateBuilder();
|
|
96
|
+
const supergraphErrors = validateSupergraph(new Map(Array.from(subgraphStateBuilders.entries()).map(([id, builder]) => [
|
|
97
|
+
id,
|
|
98
|
+
cleanSubgraphStateFromFederationSpec(cleanSubgraphStateFromLinkSpec(builder.state)),
|
|
99
|
+
])), state, __internal);
|
|
100
|
+
if (supergraphErrors.length > 0) {
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
errors: supergraphErrors,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const nodes = state.build();
|
|
107
|
+
return {
|
|
108
|
+
success: true,
|
|
109
|
+
supergraph: nodes,
|
|
110
|
+
links: state.links(),
|
|
111
|
+
specs: state.getSupergraphState().specs,
|
|
112
|
+
};
|
|
113
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theguild/federation-composition",
|
|
3
|
+
"version": "0.0.0-alpha-20230916192321-bb37b43",
|
|
4
|
+
"description": "",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "^16.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"constant-case": "^3.0.0",
|
|
10
|
+
"json5": "^2.2.0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": {
|
|
14
|
+
"email": "contact@the-guild.dev",
|
|
15
|
+
"name": "The Guild",
|
|
16
|
+
"url": "https://the-guild.dev"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"main": "cjs/index.js",
|
|
23
|
+
"module": "esm/index.js",
|
|
24
|
+
"typings": "typings/index.d.ts",
|
|
25
|
+
"typescript": {
|
|
26
|
+
"definition": "typings/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./typings/index.d.cts",
|
|
33
|
+
"default": "./cjs/index.js"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./typings/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": {
|
|
40
|
+
"types": "./typings/index.d.ts",
|
|
41
|
+
"default": "./esm/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { ServiceDefinition } from './types.cjs';
|
|
3
|
+
export declare function composeServices(services: ServiceDefinition[], __internal?: {
|
|
4
|
+
disableValidationRules?: string[];
|
|
5
|
+
}): CompositionResult;
|
|
6
|
+
export type CompositionResult = CompositionFailure | CompositionSuccess;
|
|
7
|
+
export interface CompositionFailure {
|
|
8
|
+
errors: GraphQLError[];
|
|
9
|
+
}
|
|
10
|
+
export interface CompositionSuccess {
|
|
11
|
+
supergraphSdl: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function assertCompositionSuccess(compositionResult: CompositionResult, message?: string): asserts compositionResult is CompositionSuccess;
|
|
14
|
+
export declare function assertCompositionFailure(compositionResult: CompositionResult, message?: string): asserts compositionResult is CompositionFailure;
|
|
15
|
+
export declare function compositionHasErrors(compositionResult: CompositionResult): compositionResult is CompositionFailure;
|
|
16
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { ServiceDefinition } from './types.js';
|
|
3
|
+
export declare function composeServices(services: ServiceDefinition[], __internal?: {
|
|
4
|
+
disableValidationRules?: string[];
|
|
5
|
+
}): CompositionResult;
|
|
6
|
+
export type CompositionResult = CompositionFailure | CompositionSuccess;
|
|
7
|
+
export interface CompositionFailure {
|
|
8
|
+
errors: GraphQLError[];
|
|
9
|
+
}
|
|
10
|
+
export interface CompositionSuccess {
|
|
11
|
+
supergraphSdl: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function assertCompositionSuccess(compositionResult: CompositionResult, message?: string): asserts compositionResult is CompositionSuccess;
|
|
14
|
+
export declare function assertCompositionFailure(compositionResult: CompositionResult, message?: string): asserts compositionResult is CompositionFailure;
|
|
15
|
+
export declare function compositionHasErrors(compositionResult: CompositionResult): compositionResult is CompositionFailure;
|
|
16
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DefinitionNode, DirectiveDefinitionNode, DocumentNode } from 'graphql';
|
|
2
|
+
export declare function isDirectiveDefinition(node: DefinitionNode): node is DirectiveDefinitionNode;
|
|
3
|
+
export declare function stripFederationFromSupergraph(supergraph: DocumentNode): DocumentNode;
|
|
4
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DefinitionNode, DirectiveDefinitionNode, DocumentNode } from 'graphql';
|
|
2
|
+
export declare function isDirectiveDefinition(node: DefinitionNode): node is DirectiveDefinitionNode;
|
|
3
|
+
export declare function stripFederationFromSupergraph(supergraph: DocumentNode): DocumentNode;
|
|
4
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ASTNode, ASTVisitor, DirectiveDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, TypeDefinitionNode, TypeExtensionNode } from 'graphql';
|
|
2
|
+
type Maybe<T> = T | null | undefined;
|
|
3
|
+
export declare class TypeNodeInfo {
|
|
4
|
+
private _type;
|
|
5
|
+
private _field;
|
|
6
|
+
private _arg;
|
|
7
|
+
private _value;
|
|
8
|
+
constructor();
|
|
9
|
+
get [Symbol.toStringTag](): string;
|
|
10
|
+
getTypeDef(): Maybe<DirectiveDefinitionNode | TypeDefinitionNode | TypeExtensionNode>;
|
|
11
|
+
getFieldDef(): Maybe<FieldDefinitionNode | InputValueDefinitionNode>;
|
|
12
|
+
getArgumentDef(): Maybe<InputValueDefinitionNode>;
|
|
13
|
+
getValueDef(): Maybe<EnumValueDefinitionNode>;
|
|
14
|
+
enter(node: ASTNode): void;
|
|
15
|
+
leave(node: ASTNode): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function visitWithTypeNodeInfo(typeInfo: TypeNodeInfo, visitor: ASTVisitor): ASTVisitor;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=type-node-info.d.ts.map
|