Skip to content

Commit

Permalink
getFieldDef: accept FieldNode instead of field name (#3084)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 13, 2021
1 parent 266f9fa commit 6fd5607
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/execution/execute.js
Expand Up @@ -589,10 +589,7 @@ function resolveField(
fieldNodes: $ReadOnlyArray<FieldNode>,
path: Path,
): PromiseOrValue<mixed> {
const fieldNode = fieldNodes[0];
const fieldName = fieldNode.name.value;

const fieldDef = getFieldDef(exeContext.schema, parentType, fieldName);
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
if (!fieldDef) {
return;
}
Expand Down Expand Up @@ -1171,8 +1168,10 @@ export const defaultFieldResolver: GraphQLFieldResolver<
export function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLObjectType,
fieldName: string,
fieldNode: FieldNode,
): ?GraphQLField<mixed, mixed> {
const fieldName = fieldNode.name.value;

if (
fieldName === SchemaMetaFieldDef.name &&
schema.getQueryType() === parentType
Expand Down
4 changes: 2 additions & 2 deletions src/subscription/subscribe.js
Expand Up @@ -199,10 +199,10 @@ async function executeSubscription(
new Set(),
);
const [responseName, fieldNodes] = [...fields.entries()][0];
const fieldName = fieldNodes[0].name.value;
const fieldDef = getFieldDef(schema, type, fieldName);
const fieldDef = getFieldDef(schema, type, fieldNodes[0]);

if (!fieldDef) {
const fieldName = fieldNodes[0].name.value;
throw new GraphQLError(
`The subscription field "${fieldName}" is not defined.`,
fieldNodes,
Expand Down

0 comments on commit 6fd5607

Please sign in to comment.