Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFieldDef: accept FieldNode instead of field name #3084

Merged
merged 1 commit into from May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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