@graphql-tools/wrap
Advanced tools
Comparing version 10.0.2 to 10.0.3-alpha-20240307135938-3e46cedb52372a41599dee22d230548292d18b8b
@@ -77,22 +77,15 @@ "use strict"; | ||
let newSelections = []; | ||
let typeNameExists = node.selections.some(selection => selection.kind === graphql_1.Kind.FIELD && selection.name.value === '__typename'); | ||
let isTypenameSelected = false; | ||
for (const selection of node.selections) { | ||
if (selection.kind !== graphql_1.Kind.FIELD || selection.name.value === '__typename') { | ||
if (selection.kind !== graphql_1.Kind.FIELD) { | ||
newSelections.push(selection); | ||
continue; | ||
} | ||
// The `__typename` selection should not be aliased | ||
// to be accessible with this name | ||
if (selection.name.value === '__typename' && | ||
(!selection.alias || selection.alias.value === '__typename')) { | ||
isTypenameSelected = true; | ||
} | ||
const newName = selection.name.value; | ||
// See https://github.com/ardatan/graphql-tools/issues/2282 | ||
if (!typeNameExists && | ||
(this.dataTransformer != null || this.errorsTransformer != null) && | ||
(this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) { | ||
newSelections.push({ | ||
kind: graphql_1.Kind.FIELD, | ||
name: { | ||
kind: graphql_1.Kind.NAME, | ||
value: '__typename', | ||
}, | ||
}); | ||
typeNameExists = true; | ||
} | ||
let transformedSelection; | ||
@@ -140,2 +133,14 @@ if (this.fieldNodeTransformer == null) { | ||
} | ||
// See https://github.com/ardatan/graphql-tools/issues/2282 | ||
if (!isTypenameSelected && | ||
(this.dataTransformer != null || this.errorsTransformer != null) && | ||
(this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) { | ||
newSelections.push({ | ||
kind: graphql_1.Kind.FIELD, | ||
name: { | ||
kind: graphql_1.Kind.NAME, | ||
value: '__typename', | ||
}, | ||
}); | ||
} | ||
return { | ||
@@ -142,0 +147,0 @@ ...node, |
@@ -75,22 +75,15 @@ import { Kind, TypeInfo, visit, visitWithTypeInfo, } from 'graphql'; | ||
let newSelections = []; | ||
let typeNameExists = node.selections.some(selection => selection.kind === Kind.FIELD && selection.name.value === '__typename'); | ||
let isTypenameSelected = false; | ||
for (const selection of node.selections) { | ||
if (selection.kind !== Kind.FIELD || selection.name.value === '__typename') { | ||
if (selection.kind !== Kind.FIELD) { | ||
newSelections.push(selection); | ||
continue; | ||
} | ||
// The `__typename` selection should not be aliased | ||
// to be accessible with this name | ||
if (selection.name.value === '__typename' && | ||
(!selection.alias || selection.alias.value === '__typename')) { | ||
isTypenameSelected = true; | ||
} | ||
const newName = selection.name.value; | ||
// See https://github.com/ardatan/graphql-tools/issues/2282 | ||
if (!typeNameExists && | ||
(this.dataTransformer != null || this.errorsTransformer != null) && | ||
(this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) { | ||
newSelections.push({ | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: '__typename', | ||
}, | ||
}); | ||
typeNameExists = true; | ||
} | ||
let transformedSelection; | ||
@@ -138,2 +131,14 @@ if (this.fieldNodeTransformer == null) { | ||
} | ||
// See https://github.com/ardatan/graphql-tools/issues/2282 | ||
if (!isTypenameSelected && | ||
(this.dataTransformer != null || this.errorsTransformer != null) && | ||
(this.subscriptionTypeName == null || parentTypeName !== this.subscriptionTypeName)) { | ||
newSelections.push({ | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: '__typename', | ||
}, | ||
}); | ||
} | ||
return { | ||
@@ -140,0 +145,0 @@ ...node, |
{ | ||
"name": "@graphql-tools/wrap", | ||
"version": "10.0.2", | ||
"version": "10.0.3-alpha-20240307135938-3e46cedb52372a41599dee22d230548292d18b8b", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
279105
4814
2