@graphql-tools/delegate 10.2.2 → 10.2.3-rc-29e4be325ad314aa819751ffa22de30cd112a969

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @graphql-tools/delegate
2
2
 
3
+ ## 10.2.3-rc-29e4be325ad314aa819751ffa22de30cd112a969
4
+
5
+ ### Patch Changes
6
+
7
+ - [#231](https://github.com/graphql-hive/gateway/pull/231) [`7ca0ff3`](https://github.com/graphql-hive/gateway/commit/7ca0ff331e42c133c4218a8086bbf0a7607f45d0) Thanks [@ardatan](https://github.com/ardatan)! - Avoid extensions and use \`stitchingInfo\` for provided fields
8
+
3
9
  ## 10.2.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -549,7 +549,7 @@ function getDocumentMetadata(document) {
549
549
  };
550
550
  }
551
551
 
552
- function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases) {
552
+ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases, delegationContext) {
553
553
  let usedVariables = [];
554
554
  let usedFragments = [];
555
555
  const newOperations = [];
@@ -632,8 +632,8 @@ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlapp
632
632
  kind: graphql.Kind.DOCUMENT,
633
633
  definitions: [...newOperations, ...newFragments]
634
634
  };
635
- const typeNameFieldProvidedSelectionMap = targetSchema.extensions["typeNameFieldProvidedSelectionMap"];
636
- if (typeNameFieldProvidedSelectionMap) {
635
+ const stitchingInfo = delegationContext.info?.schema?.extensions?.["stitchingInfo"];
636
+ if (stitchingInfo != null) {
637
637
  const typeInfo = new graphql.TypeInfo(targetSchema);
638
638
  newDocument = graphql.visit(
639
639
  newDocument,
@@ -642,22 +642,25 @@ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlapp
642
642
  const parentType = typeInfo.getParentType();
643
643
  if (parentType) {
644
644
  const parentTypeName = parentType.name;
645
- const providedSelections = typeNameFieldProvidedSelectionMap.get(parentTypeName);
646
- if (providedSelections) {
647
- const providedSelection = providedSelections.get(
648
- fieldNode.name.value
645
+ const typeConfig = stitchingInfo?.mergedTypes?.[parentTypeName];
646
+ if (typeConfig) {
647
+ const providedSelectionsByField = typeConfig?.providedSelectionsByField?.get(
648
+ delegationContext.subschema
649
649
  );
650
- if (providedSelection) {
651
- return {
652
- ...fieldNode,
653
- selectionSet: {
654
- kind: graphql.Kind.SELECTION_SET,
655
- selections: [
656
- ...providedSelection.selections,
657
- ...fieldNode.selectionSet?.selections ?? []
658
- ]
659
- }
660
- };
650
+ if (providedSelectionsByField) {
651
+ const providedSelection = providedSelectionsByField[fieldNode.name.value];
652
+ if (providedSelection) {
653
+ return {
654
+ ...fieldNode,
655
+ selectionSet: {
656
+ kind: graphql.Kind.SELECTION_SET,
657
+ selections: [
658
+ ...providedSelection.selections,
659
+ ...fieldNode.selectionSet?.selections ?? []
660
+ ]
661
+ }
662
+ };
663
+ }
661
664
  }
662
665
  }
663
666
  }
@@ -692,7 +695,8 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
692
695
  targetSchema,
693
696
  fragments,
694
697
  operations,
695
- onOverlappingAliases
698
+ onOverlappingAliases,
699
+ delegationContext
696
700
  );
697
701
  const newVariables = {};
698
702
  if (variables != null) {
package/dist/index.d.cts CHANGED
@@ -80,6 +80,7 @@ interface MergedTypeInfo<TContext = Record<string, any>> {
80
80
  selectionSets: Map<Subschema<any, any, any, TContext>, SelectionSetNode>;
81
81
  fieldSelectionSets: Map<Subschema<any, any, any, TContext>, Record<string, SelectionSetNode>>;
82
82
  resolvers: Map<Subschema<any, any, any, TContext>, MergedTypeResolver<TContext>>;
83
+ providedSelectionsByField: Map<Subschema<any, any, any, TContext>, Record<string, SelectionSetNode>>;
83
84
  delegationPlanBuilder: DelegationPlanBuilder;
84
85
  nonMemoizedDelegationPlanBuilder: DelegationPlanBuilder;
85
86
  }
@@ -125,6 +126,7 @@ interface MergedFieldConfig {
125
126
  selectionSet?: string;
126
127
  computed?: boolean;
127
128
  canonical?: boolean;
129
+ provides?: SelectionSetNode;
128
130
  }
129
131
  type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema: Subschema<any, any, any, TContext>, selectionSet: SelectionSetNode, key: any | undefined, type: GraphQLOutputType) => any;
130
132
  interface StitchingInfo<TContext = Record<string, any>> {
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ interface MergedTypeInfo<TContext = Record<string, any>> {
80
80
  selectionSets: Map<Subschema<any, any, any, TContext>, SelectionSetNode>;
81
81
  fieldSelectionSets: Map<Subschema<any, any, any, TContext>, Record<string, SelectionSetNode>>;
82
82
  resolvers: Map<Subschema<any, any, any, TContext>, MergedTypeResolver<TContext>>;
83
+ providedSelectionsByField: Map<Subschema<any, any, any, TContext>, Record<string, SelectionSetNode>>;
83
84
  delegationPlanBuilder: DelegationPlanBuilder;
84
85
  nonMemoizedDelegationPlanBuilder: DelegationPlanBuilder;
85
86
  }
@@ -125,6 +126,7 @@ interface MergedFieldConfig {
125
126
  selectionSet?: string;
126
127
  computed?: boolean;
127
128
  canonical?: boolean;
129
+ provides?: SelectionSetNode;
128
130
  }
129
131
  type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema: Subschema<any, any, any, TContext>, selectionSet: SelectionSetNode, key: any | undefined, type: GraphQLOutputType) => any;
130
132
  interface StitchingInfo<TContext = Record<string, any>> {
package/dist/index.js CHANGED
@@ -548,7 +548,7 @@ function getDocumentMetadata(document) {
548
548
  };
549
549
  }
550
550
 
551
- function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases) {
551
+ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases, delegationContext) {
552
552
  let usedVariables = [];
553
553
  let usedFragments = [];
554
554
  const newOperations = [];
@@ -631,8 +631,8 @@ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlapp
631
631
  kind: Kind.DOCUMENT,
632
632
  definitions: [...newOperations, ...newFragments]
633
633
  };
634
- const typeNameFieldProvidedSelectionMap = targetSchema.extensions["typeNameFieldProvidedSelectionMap"];
635
- if (typeNameFieldProvidedSelectionMap) {
634
+ const stitchingInfo = delegationContext.info?.schema?.extensions?.["stitchingInfo"];
635
+ if (stitchingInfo != null) {
636
636
  const typeInfo = new TypeInfo(targetSchema);
637
637
  newDocument = visit(
638
638
  newDocument,
@@ -641,22 +641,25 @@ function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlapp
641
641
  const parentType = typeInfo.getParentType();
642
642
  if (parentType) {
643
643
  const parentTypeName = parentType.name;
644
- const providedSelections = typeNameFieldProvidedSelectionMap.get(parentTypeName);
645
- if (providedSelections) {
646
- const providedSelection = providedSelections.get(
647
- fieldNode.name.value
644
+ const typeConfig = stitchingInfo?.mergedTypes?.[parentTypeName];
645
+ if (typeConfig) {
646
+ const providedSelectionsByField = typeConfig?.providedSelectionsByField?.get(
647
+ delegationContext.subschema
648
648
  );
649
- if (providedSelection) {
650
- return {
651
- ...fieldNode,
652
- selectionSet: {
653
- kind: Kind.SELECTION_SET,
654
- selections: [
655
- ...providedSelection.selections,
656
- ...fieldNode.selectionSet?.selections ?? []
657
- ]
658
- }
659
- };
649
+ if (providedSelectionsByField) {
650
+ const providedSelection = providedSelectionsByField[fieldNode.name.value];
651
+ if (providedSelection) {
652
+ return {
653
+ ...fieldNode,
654
+ selectionSet: {
655
+ kind: Kind.SELECTION_SET,
656
+ selections: [
657
+ ...providedSelection.selections,
658
+ ...fieldNode.selectionSet?.selections ?? []
659
+ ]
660
+ }
661
+ };
662
+ }
660
663
  }
661
664
  }
662
665
  }
@@ -691,7 +694,8 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
691
694
  targetSchema,
692
695
  fragments,
693
696
  operations,
694
- onOverlappingAliases
697
+ onOverlappingAliases,
698
+ delegationContext
695
699
  );
696
700
  const newVariables = {};
697
701
  if (variables != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/delegate",
3
- "version": "10.2.2",
3
+ "version": "10.2.3-rc-29e4be325ad314aa819751ffa22de30cd112a969",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {