@graphql-tools/wrap 9.2.10 → 9.2.11-alpha-20221107152054-d7ee37f7

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.
@@ -76,14 +76,16 @@ class TransformCompositeFields {
76
76
  }
77
77
  const parentTypeName = parentType.name;
78
78
  let newSelections = [];
79
+ let typeNameExists = node.selections.some(selection => selection.kind === graphql_1.Kind.FIELD && selection.name.value === '__typename');
79
80
  for (const selection of node.selections) {
80
- if (selection.kind !== graphql_1.Kind.FIELD) {
81
+ if (selection.kind !== graphql_1.Kind.FIELD || selection.name.value === '__typename') {
81
82
  newSelections.push(selection);
82
83
  continue;
83
84
  }
84
85
  const newName = selection.name.value;
85
86
  // See https://github.com/ardatan/graphql-tools/issues/2282
86
- if ((this.dataTransformer != null || this.errorsTransformer != null) &&
87
+ if (!typeNameExists &&
88
+ (this.dataTransformer != null || this.errorsTransformer != null) &&
87
89
  (this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) {
88
90
  newSelections.push({
89
91
  kind: graphql_1.Kind.FIELD,
@@ -92,6 +94,7 @@ class TransformCompositeFields {
92
94
  value: '__typename',
93
95
  },
94
96
  });
97
+ typeNameExists = true;
95
98
  }
96
99
  let transformedSelection;
97
100
  if (this.fieldNodeTransformer == null) {
@@ -74,14 +74,16 @@ export default class TransformCompositeFields {
74
74
  }
75
75
  const parentTypeName = parentType.name;
76
76
  let newSelections = [];
77
+ let typeNameExists = node.selections.some(selection => selection.kind === Kind.FIELD && selection.name.value === '__typename');
77
78
  for (const selection of node.selections) {
78
- if (selection.kind !== Kind.FIELD) {
79
+ if (selection.kind !== Kind.FIELD || selection.name.value === '__typename') {
79
80
  newSelections.push(selection);
80
81
  continue;
81
82
  }
82
83
  const newName = selection.name.value;
83
84
  // See https://github.com/ardatan/graphql-tools/issues/2282
84
- if ((this.dataTransformer != null || this.errorsTransformer != null) &&
85
+ if (!typeNameExists &&
86
+ (this.dataTransformer != null || this.errorsTransformer != null) &&
85
87
  (this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) {
86
88
  newSelections.push({
87
89
  kind: Kind.FIELD,
@@ -90,6 +92,7 @@ export default class TransformCompositeFields {
90
92
  value: '__typename',
91
93
  },
92
94
  });
95
+ typeNameExists = true;
93
96
  }
94
97
  let transformedSelection;
95
98
  if (this.fieldNodeTransformer == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/wrap",
3
- "version": "9.2.10",
3
+ "version": "9.2.11-alpha-20221107152054-d7ee37f7",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {