@graphql-tools/delegate 10.2.20 → 10.2.21-alpha-9e19c4c2d6d51beeb30dcbd905fc776b8e5042e4
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 +8 -0
- package/dist/index.cjs +94 -34
- package/dist/index.js +94 -34
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @graphql-tools/delegate
|
|
2
2
|
|
|
3
|
+
## 10.2.21-alpha-9e19c4c2d6d51beeb30dcbd905fc776b8e5042e4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1301](https://github.com/graphql-hive/gateway/pull/1301) [`bd1a66a`](https://github.com/graphql-hive/gateway/commit/bd1a66aad2b10351d831f781977cdd2d586c56fd) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Filter selection sets recursively when finalizing gateway requests
|
|
8
|
+
|
|
9
|
+
Because abstract types can be nested.
|
|
10
|
+
|
|
3
11
|
## 10.2.20
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -945,7 +945,36 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
945
945
|
const typeInfo = getTypeInfoWithType(schema, type);
|
|
946
946
|
const seenNonNullableMap = /* @__PURE__ */ new WeakMap();
|
|
947
947
|
const seenNullableMap = /* @__PURE__ */ new WeakMap();
|
|
948
|
-
const filteredSelectionSet =
|
|
948
|
+
const filteredSelectionSet = filterSelectionSet(
|
|
949
|
+
schema,
|
|
950
|
+
typeInfo,
|
|
951
|
+
validFragments,
|
|
952
|
+
selectionSet,
|
|
953
|
+
onOverlappingAliases,
|
|
954
|
+
usedFragments,
|
|
955
|
+
seenNonNullableMap,
|
|
956
|
+
seenNullableMap
|
|
957
|
+
);
|
|
958
|
+
graphql.visit(
|
|
959
|
+
filteredSelectionSet,
|
|
960
|
+
{
|
|
961
|
+
[graphql.Kind.VARIABLE]: (variableNode) => {
|
|
962
|
+
usedVariables.push(variableNode.name.value);
|
|
963
|
+
}
|
|
964
|
+
},
|
|
965
|
+
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
966
|
+
// empty keys cannot be removed only because of typescript errors
|
|
967
|
+
// will hopefully be fixed in future version of graphql-js to be optional
|
|
968
|
+
variablesVisitorKeys
|
|
969
|
+
);
|
|
970
|
+
return {
|
|
971
|
+
selectionSet: filteredSelectionSet,
|
|
972
|
+
usedFragments,
|
|
973
|
+
usedVariables
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function filterSelectionSet(schema, typeInfo, validFragments, selectionSet, onOverlappingAliases, usedFragments, seenNonNullableMap, seenNullableMap) {
|
|
977
|
+
return graphql.visit(
|
|
949
978
|
selectionSet,
|
|
950
979
|
graphql.visitWithTypeInfo(typeInfo, {
|
|
951
980
|
[graphql.Kind.FIELD]: {
|
|
@@ -994,30 +1023,78 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
994
1023
|
}
|
|
995
1024
|
}
|
|
996
1025
|
if (possibleTypeNames.length > 0) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1026
|
+
const spreads = possibleTypeNames.map((possibleTypeName) => {
|
|
1027
|
+
if (!node.selectionSet?.selections) {
|
|
1028
|
+
return {
|
|
1029
|
+
kind: graphql.Kind.INLINE_FRAGMENT,
|
|
1030
|
+
typeCondition: {
|
|
1031
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
1032
|
+
name: {
|
|
1033
|
+
kind: graphql.Kind.NAME,
|
|
1034
|
+
value: possibleTypeName
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
1037
|
+
selectionSet: {
|
|
1038
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
1039
|
+
selections: [node]
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
const possibleType = schema.getType(
|
|
1044
|
+
possibleTypeName
|
|
1045
|
+
);
|
|
1046
|
+
const possibleField = possibleType.getFields()[node.name.value];
|
|
1047
|
+
if (!possibleField) {
|
|
1048
|
+
return void 0;
|
|
1049
|
+
}
|
|
1050
|
+
const fieldFilteredSelectionSet = filterSelectionSet(
|
|
1051
|
+
schema,
|
|
1052
|
+
getTypeInfoWithType(schema, possibleField.type),
|
|
1053
|
+
validFragments,
|
|
1054
|
+
node.selectionSet,
|
|
1055
|
+
onOverlappingAliases,
|
|
1056
|
+
usedFragments,
|
|
1057
|
+
seenNonNullableMap,
|
|
1058
|
+
seenNullableMap
|
|
1059
|
+
);
|
|
1060
|
+
if (!fieldFilteredSelectionSet.selections.length) {
|
|
1061
|
+
return void 0;
|
|
1009
1062
|
}
|
|
1010
|
-
|
|
1063
|
+
return {
|
|
1064
|
+
kind: graphql.Kind.INLINE_FRAGMENT,
|
|
1065
|
+
typeCondition: {
|
|
1066
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
1067
|
+
name: {
|
|
1068
|
+
kind: graphql.Kind.NAME,
|
|
1069
|
+
value: possibleTypeName
|
|
1070
|
+
}
|
|
1071
|
+
},
|
|
1072
|
+
selectionSet: {
|
|
1073
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
1074
|
+
selections: [
|
|
1075
|
+
{
|
|
1076
|
+
...node,
|
|
1077
|
+
selectionSet: fieldFilteredSelectionSet
|
|
1078
|
+
}
|
|
1079
|
+
]
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
});
|
|
1083
|
+
const nonEmptySpreads = spreads.filter(Boolean);
|
|
1084
|
+
if (!nonEmptySpreads.length) {
|
|
1085
|
+
return void 0;
|
|
1086
|
+
}
|
|
1087
|
+
return nonEmptySpreads;
|
|
1011
1088
|
}
|
|
1012
1089
|
}
|
|
1013
1090
|
return void 0;
|
|
1014
1091
|
},
|
|
1015
1092
|
leave: (node) => {
|
|
1016
|
-
const
|
|
1017
|
-
if (
|
|
1093
|
+
const type = typeInfo.getType();
|
|
1094
|
+
if (type == null) {
|
|
1018
1095
|
return null;
|
|
1019
1096
|
}
|
|
1020
|
-
const namedType = graphql.getNamedType(
|
|
1097
|
+
const namedType = graphql.getNamedType(type);
|
|
1021
1098
|
if (schema.getType(namedType.name) == null) {
|
|
1022
1099
|
return null;
|
|
1023
1100
|
}
|
|
@@ -1164,23 +1241,6 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
1164
1241
|
// will hopefully be fixed in future version of graphql-js to be optional
|
|
1165
1242
|
filteredSelectionSetVisitorKeys
|
|
1166
1243
|
);
|
|
1167
|
-
graphql.visit(
|
|
1168
|
-
filteredSelectionSet,
|
|
1169
|
-
{
|
|
1170
|
-
[graphql.Kind.VARIABLE]: (variableNode) => {
|
|
1171
|
-
usedVariables.push(variableNode.name.value);
|
|
1172
|
-
}
|
|
1173
|
-
},
|
|
1174
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
1175
|
-
// empty keys cannot be removed only because of typescript errors
|
|
1176
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
1177
|
-
variablesVisitorKeys
|
|
1178
|
-
);
|
|
1179
|
-
return {
|
|
1180
|
-
selectionSet: filteredSelectionSet,
|
|
1181
|
-
usedFragments,
|
|
1182
|
-
usedVariables
|
|
1183
|
-
};
|
|
1184
1244
|
}
|
|
1185
1245
|
function union(...arrays) {
|
|
1186
1246
|
const cache = /* @__PURE__ */ Object.create(null);
|
package/dist/index.js
CHANGED
|
@@ -945,7 +945,36 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
945
945
|
const typeInfo = getTypeInfoWithType(schema, type);
|
|
946
946
|
const seenNonNullableMap = /* @__PURE__ */ new WeakMap();
|
|
947
947
|
const seenNullableMap = /* @__PURE__ */ new WeakMap();
|
|
948
|
-
const filteredSelectionSet =
|
|
948
|
+
const filteredSelectionSet = filterSelectionSet(
|
|
949
|
+
schema,
|
|
950
|
+
typeInfo,
|
|
951
|
+
validFragments,
|
|
952
|
+
selectionSet,
|
|
953
|
+
onOverlappingAliases,
|
|
954
|
+
usedFragments,
|
|
955
|
+
seenNonNullableMap,
|
|
956
|
+
seenNullableMap
|
|
957
|
+
);
|
|
958
|
+
visit(
|
|
959
|
+
filteredSelectionSet,
|
|
960
|
+
{
|
|
961
|
+
[Kind.VARIABLE]: (variableNode) => {
|
|
962
|
+
usedVariables.push(variableNode.name.value);
|
|
963
|
+
}
|
|
964
|
+
},
|
|
965
|
+
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
966
|
+
// empty keys cannot be removed only because of typescript errors
|
|
967
|
+
// will hopefully be fixed in future version of graphql-js to be optional
|
|
968
|
+
variablesVisitorKeys
|
|
969
|
+
);
|
|
970
|
+
return {
|
|
971
|
+
selectionSet: filteredSelectionSet,
|
|
972
|
+
usedFragments,
|
|
973
|
+
usedVariables
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function filterSelectionSet(schema, typeInfo, validFragments, selectionSet, onOverlappingAliases, usedFragments, seenNonNullableMap, seenNullableMap) {
|
|
977
|
+
return visit(
|
|
949
978
|
selectionSet,
|
|
950
979
|
visitWithTypeInfo(typeInfo, {
|
|
951
980
|
[Kind.FIELD]: {
|
|
@@ -994,30 +1023,78 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
994
1023
|
}
|
|
995
1024
|
}
|
|
996
1025
|
if (possibleTypeNames.length > 0) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1026
|
+
const spreads = possibleTypeNames.map((possibleTypeName) => {
|
|
1027
|
+
if (!node.selectionSet?.selections) {
|
|
1028
|
+
return {
|
|
1029
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
1030
|
+
typeCondition: {
|
|
1031
|
+
kind: Kind.NAMED_TYPE,
|
|
1032
|
+
name: {
|
|
1033
|
+
kind: Kind.NAME,
|
|
1034
|
+
value: possibleTypeName
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
1037
|
+
selectionSet: {
|
|
1038
|
+
kind: Kind.SELECTION_SET,
|
|
1039
|
+
selections: [node]
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
const possibleType = schema.getType(
|
|
1044
|
+
possibleTypeName
|
|
1045
|
+
);
|
|
1046
|
+
const possibleField = possibleType.getFields()[node.name.value];
|
|
1047
|
+
if (!possibleField) {
|
|
1048
|
+
return void 0;
|
|
1049
|
+
}
|
|
1050
|
+
const fieldFilteredSelectionSet = filterSelectionSet(
|
|
1051
|
+
schema,
|
|
1052
|
+
getTypeInfoWithType(schema, possibleField.type),
|
|
1053
|
+
validFragments,
|
|
1054
|
+
node.selectionSet,
|
|
1055
|
+
onOverlappingAliases,
|
|
1056
|
+
usedFragments,
|
|
1057
|
+
seenNonNullableMap,
|
|
1058
|
+
seenNullableMap
|
|
1059
|
+
);
|
|
1060
|
+
if (!fieldFilteredSelectionSet.selections.length) {
|
|
1061
|
+
return void 0;
|
|
1009
1062
|
}
|
|
1010
|
-
|
|
1063
|
+
return {
|
|
1064
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
1065
|
+
typeCondition: {
|
|
1066
|
+
kind: Kind.NAMED_TYPE,
|
|
1067
|
+
name: {
|
|
1068
|
+
kind: Kind.NAME,
|
|
1069
|
+
value: possibleTypeName
|
|
1070
|
+
}
|
|
1071
|
+
},
|
|
1072
|
+
selectionSet: {
|
|
1073
|
+
kind: Kind.SELECTION_SET,
|
|
1074
|
+
selections: [
|
|
1075
|
+
{
|
|
1076
|
+
...node,
|
|
1077
|
+
selectionSet: fieldFilteredSelectionSet
|
|
1078
|
+
}
|
|
1079
|
+
]
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
});
|
|
1083
|
+
const nonEmptySpreads = spreads.filter(Boolean);
|
|
1084
|
+
if (!nonEmptySpreads.length) {
|
|
1085
|
+
return void 0;
|
|
1086
|
+
}
|
|
1087
|
+
return nonEmptySpreads;
|
|
1011
1088
|
}
|
|
1012
1089
|
}
|
|
1013
1090
|
return void 0;
|
|
1014
1091
|
},
|
|
1015
1092
|
leave: (node) => {
|
|
1016
|
-
const
|
|
1017
|
-
if (
|
|
1093
|
+
const type = typeInfo.getType();
|
|
1094
|
+
if (type == null) {
|
|
1018
1095
|
return null;
|
|
1019
1096
|
}
|
|
1020
|
-
const namedType = getNamedType(
|
|
1097
|
+
const namedType = getNamedType(type);
|
|
1021
1098
|
if (schema.getType(namedType.name) == null) {
|
|
1022
1099
|
return null;
|
|
1023
1100
|
}
|
|
@@ -1164,23 +1241,6 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
|
|
|
1164
1241
|
// will hopefully be fixed in future version of graphql-js to be optional
|
|
1165
1242
|
filteredSelectionSetVisitorKeys
|
|
1166
1243
|
);
|
|
1167
|
-
visit(
|
|
1168
|
-
filteredSelectionSet,
|
|
1169
|
-
{
|
|
1170
|
-
[Kind.VARIABLE]: (variableNode) => {
|
|
1171
|
-
usedVariables.push(variableNode.name.value);
|
|
1172
|
-
}
|
|
1173
|
-
},
|
|
1174
|
-
// visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
|
|
1175
|
-
// empty keys cannot be removed only because of typescript errors
|
|
1176
|
-
// will hopefully be fixed in future version of graphql-js to be optional
|
|
1177
|
-
variablesVisitorKeys
|
|
1178
|
-
);
|
|
1179
|
-
return {
|
|
1180
|
-
selectionSet: filteredSelectionSet,
|
|
1181
|
-
usedFragments,
|
|
1182
|
-
usedVariables
|
|
1183
|
-
};
|
|
1184
1244
|
}
|
|
1185
1245
|
function union(...arrays) {
|
|
1186
1246
|
const cache = /* @__PURE__ */ Object.create(null);
|
package/package.json
CHANGED