Skip to content

Commit dbd1118

Browse files
committed
subscribe: fix missing path on unknown field error
1 parent cfbc023 commit dbd1118

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/execution/__tests__/subscribe-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ describe('Subscription Initialization Phase', () => {
424424
{
425425
message: 'The subscription field "unknownField" is not defined.',
426426
locations: [{ line: 1, column: 16 }],
427+
path: ['unknownField'],
427428
},
428429
],
429430
});

src/execution/execute.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,27 +1127,29 @@ function executeSubscription(
11271127
rootType,
11281128
operation.selectionSet,
11291129
);
1130-
const [responseName, fieldNodes] = [...rootFields.entries()][0];
1131-
const fieldName = fieldNodes[0].name.value;
1132-
const fieldDef = schema.getField(rootType, fieldName);
1133-
1134-
if (!fieldDef) {
1135-
throw new GraphQLError(
1136-
`The subscription field "${fieldName}" is not defined.`,
1137-
{ nodes: fieldNodes },
1138-
);
1139-
}
11401130

1131+
const [responseName, fieldNodes] = [...rootFields.entries()][0];
11411132
const path = addPath(undefined, responseName, rootType.name);
1142-
const info = buildResolveInfo(
1143-
exeContext,
1144-
fieldDef,
1145-
fieldNodes,
1146-
rootType,
1147-
path,
1148-
);
11491133

11501134
try {
1135+
const fieldName = fieldNodes[0].name.value;
1136+
const fieldDef = schema.getField(rootType, fieldName);
1137+
1138+
if (!fieldDef) {
1139+
throw new GraphQLError(
1140+
`The subscription field "${fieldName}" is not defined.`,
1141+
{ nodes: fieldNodes },
1142+
);
1143+
}
1144+
1145+
const info = buildResolveInfo(
1146+
exeContext,
1147+
fieldDef,
1148+
fieldNodes,
1149+
rootType,
1150+
path,
1151+
);
1152+
11511153
// Implements the "ResolveFieldEventStream" algorithm from GraphQL specification.
11521154
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
11531155

0 commit comments

Comments
 (0)