Skip to content

Commit 6fd5607

Browse files
getFieldDef: accept FieldNode instead of field name (#3084)
1 parent 266f9fa commit 6fd5607

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/execution/execute.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,7 @@ function resolveField(
589589
fieldNodes: $ReadOnlyArray<FieldNode>,
590590
path: Path,
591591
): PromiseOrValue<mixed> {
592-
const fieldNode = fieldNodes[0];
593-
const fieldName = fieldNode.name.value;
594-
595-
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);
592+
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
596593
if (!fieldDef) {
597594
return;
598595
}
@@ -1171,8 +1168,10 @@ export const defaultFieldResolver: GraphQLFieldResolver<
11711168
export function getFieldDef(
11721169
schema: GraphQLSchema,
11731170
parentType: GraphQLObjectType,
1174-
fieldName: string,
1171+
fieldNode: FieldNode,
11751172
): ?GraphQLField<mixed, mixed> {
1173+
const fieldName = fieldNode.name.value;
1174+
11761175
if (
11771176
fieldName === SchemaMetaFieldDef.name &&
11781177
schema.getQueryType() === parentType

src/subscription/subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ async function executeSubscription(
199199
new Set(),
200200
);
201201
const [responseName, fieldNodes] = [...fields.entries()][0];
202-
const fieldName = fieldNodes[0].name.value;
203-
const fieldDef = getFieldDef(schema, type, fieldName);
202+
const fieldDef = getFieldDef(schema, type, fieldNodes[0]);
204203

205204
if (!fieldDef) {
205+
const fieldName = fieldNodes[0].name.value;
206206
throw new GraphQLError(
207207
`The subscription field "${fieldName}" is not defined.`,
208208
fieldNodes,

0 commit comments

Comments
 (0)