diff --git a/src/execution/execute.js b/src/execution/execute.js index 664bc13308..6f193c14c0 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -589,10 +589,7 @@ function resolveField( fieldNodes: $ReadOnlyArray, path: Path, ): PromiseOrValue { - 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; } @@ -1171,8 +1168,10 @@ export const defaultFieldResolver: GraphQLFieldResolver< export function getFieldDef( schema: GraphQLSchema, parentType: GraphQLObjectType, - fieldName: string, + fieldNode: FieldNode, ): ?GraphQLField { + const fieldName = fieldNode.name.value; + if ( fieldName === SchemaMetaFieldDef.name && schema.getQueryType() === parentType diff --git a/src/subscription/subscribe.js b/src/subscription/subscribe.js index 7b41f7e466..559b1a6ccc 100644 --- a/src/subscription/subscribe.js +++ b/src/subscription/subscribe.js @@ -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,