@wundergraph/composition 0.48.4 → 0.48.5

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.
@@ -1106,20 +1106,51 @@ class NormalizationFactory {
1106
1106
  }
1107
1107
  const fieldData = (0, utils_5.getOrThrowError)(parentData.fieldDataByName, fieldName, `${parentTypeName}.fieldDataByFieldName`);
1108
1108
  const fieldNamedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(fieldData.node.type);
1109
+ const fieldCoords = `${parentTypeName}.${fieldName}`;
1110
+ if (constants_1.BASE_SCALARS.has(fieldNamedTypeName)) {
1111
+ return {
1112
+ errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)({
1113
+ fieldCoords,
1114
+ responseType: fieldNamedTypeName,
1115
+ subgraphName: this.subgraphName,
1116
+ }),
1117
+ };
1118
+ }
1109
1119
  const namedTypeData = this.parentDefinitionDataByTypeName.get(fieldNamedTypeName);
1110
1120
  // This error should never happen
1111
1121
  if (!namedTypeData) {
1112
1122
  return {
1113
- errorString: (0, errors_1.unknownNamedTypeErrorMessage)(`${parentTypeName}.${fieldName}`, fieldNamedTypeName),
1123
+ errorString: (0, errors_1.unknownNamedTypeErrorMessage)(fieldCoords, fieldNamedTypeName),
1114
1124
  };
1115
1125
  }
1126
+ // @TODO handle abstract types and fragments
1116
1127
  if (namedTypeData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION && namedTypeData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
1117
1128
  return {
1118
- errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)(`${parentTypeName}.${fieldName}`, fieldNamedTypeName),
1129
+ errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)({
1130
+ fieldCoords,
1131
+ responseType: fieldNamedTypeName,
1132
+ subgraphName: this.subgraphName,
1133
+ }),
1119
1134
  };
1120
1135
  }
1121
1136
  return { fieldSetParentData: namedTypeData };
1122
1137
  }
1138
+ #handleNonExternalConditionalField({ currentFieldCoords, directiveCoords, directiveName, fieldSet, }) {
1139
+ if (this.isSubgraphVersionTwo) {
1140
+ this.errors.push((0, errors_1.nonExternalConditionalFieldError)({
1141
+ directiveCoords,
1142
+ directiveName,
1143
+ fieldSet,
1144
+ subgraphName: this.subgraphName,
1145
+ targetCoords: currentFieldCoords,
1146
+ }));
1147
+ return;
1148
+ }
1149
+ /* In V1, @requires and @provides do not need to declare any part of the field set @external.
1150
+ * It would appear that any such non-external fields are treated as if they are non-conditionally provided.
1151
+ * */
1152
+ this.warnings.push((0, warnings_1.nonExternalConditionalFieldWarning)(directiveCoords, this.subgraphName, currentFieldCoords, fieldSet, directiveName));
1153
+ }
1123
1154
  validateConditionalFieldSet(selectionSetParentData, fieldSet, directiveFieldName, isProvides, directiveParentTypeName) {
1124
1155
  // Create a new selection set so that the value can be parsed as a new DocumentNode
1125
1156
  const { error, documentNode } = (0, utils_1.safeParse)('{' + fieldSet + '}');
@@ -1164,6 +1195,21 @@ class NormalizationFactory {
1164
1195
  fieldCoordsPath.push(currentFieldCoords);
1165
1196
  fieldPath.push(fieldName);
1166
1197
  lastFieldName = fieldName;
1198
+ if (fieldName === string_constants_1.TYPENAME) {
1199
+ if (isProvides) {
1200
+ errorMessages.push((0, errors_1.typeNameAlreadyProvidedErrorMessage)(currentFieldCoords, nf.subgraphName));
1201
+ return graphql_1.BREAK;
1202
+ }
1203
+ if (externalAncestors.size < 1) {
1204
+ nf.#handleNonExternalConditionalField({
1205
+ currentFieldCoords,
1206
+ directiveCoords,
1207
+ directiveName,
1208
+ fieldSet,
1209
+ });
1210
+ }
1211
+ return;
1212
+ }
1167
1213
  const fieldData = parentData.fieldDataByName.get(fieldName);
1168
1214
  // undefined if the field does not exist on the parent
1169
1215
  if (!fieldData) {
@@ -1188,14 +1234,12 @@ class NormalizationFactory {
1188
1234
  namedTypeData?.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION ||
1189
1235
  namedTypeData?.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
1190
1236
  if (externalAncestors.size < 1 && !isDefinedExternal) {
1191
- if (nf.isSubgraphVersionTwo) {
1192
- nf.errors.push((0, errors_1.nonExternalConditionalFieldError)(directiveCoords, nf.subgraphName, currentFieldCoords, fieldSet, directiveName));
1193
- return;
1194
- }
1195
- /* In V1, @requires and @provides do not need to declare any part of the field set @external.
1196
- * It would appear that any such non-external fields are treated as if they are non-conditionally provided.
1197
- * */
1198
- nf.warnings.push((0, warnings_1.nonExternalConditionalFieldWarning)(directiveCoords, nf.subgraphName, currentFieldCoords, fieldSet, directiveName));
1237
+ nf.#handleNonExternalConditionalField({
1238
+ currentFieldCoords,
1239
+ directiveCoords,
1240
+ directiveName,
1241
+ fieldSet,
1242
+ });
1199
1243
  return;
1200
1244
  }
1201
1245
  if (externalAncestors.size < 1 && isUnconditionallyProvided) {
@@ -1315,6 +1359,10 @@ class NormalizationFactory {
1315
1359
  errorMessages.push((0, errors_1.unparsableFieldSetSelectionErrorMessage)(fieldSet, lastFieldName));
1316
1360
  return graphql_1.BREAK;
1317
1361
  }
1362
+ if (lastFieldName === string_constants_1.TYPENAME) {
1363
+ errorMessages.push((0, errors_1.invalidSelectionSetDefinitionErrorMessage)(fieldSet, fieldCoordsPath, string_constants_1.STRING_SCALAR, (0, utils_5.kindToNodeType)(graphql_1.Kind.SCALAR_TYPE_DEFINITION)));
1364
+ return graphql_1.BREAK;
1365
+ }
1318
1366
  const fieldData = parentData.fieldDataByName.get(lastFieldName);
1319
1367
  if (!fieldData) {
1320
1368
  errorMessages.push((0, errors_1.undefinedFieldInFieldSetErrorMessage)(fieldSet, parentData.name, lastFieldName));