Skip to content

Declare fieldNodes always has at least 1 FieldNode #3504

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

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function collectFields(
variableValues: { [variable: string]: unknown },
runtimeType: GraphQLObjectType,
selectionSet: SelectionSetNode,
): Map<string, ReadonlyArray<FieldNode>> {
): Map<string, readonly [FieldNode, ...Array<FieldNode>]> {
const fields = new Map();
collectFieldsImpl(
schema,
Expand Down Expand Up @@ -65,8 +65,8 @@ export function collectSubfields(
fragments: ObjMap<FragmentDefinitionNode>,
variableValues: { [variable: string]: unknown },
returnType: GraphQLObjectType,
fieldNodes: ReadonlyArray<FieldNode>,
): Map<string, ReadonlyArray<FieldNode>> {
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
): Map<string, readonly [FieldNode, ...Array<FieldNode>]> {
const subFieldNodes = new Map();
const visitedFragmentNames = new Set<string>();
for (const node of fieldNodes) {
Expand Down
22 changes: 11 additions & 11 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const collectSubfields = memoize3(
(
exeContext: ExecutionContext,
returnType: GraphQLObjectType,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
) =>
_collectSubfields(
exeContext.schema,
Expand Down Expand Up @@ -402,7 +402,7 @@ function executeFieldsSerially(
parentType: GraphQLObjectType,
sourceValue: unknown,
path: Path | undefined,
fields: Map<string, ReadonlyArray<FieldNode>>,
fields: Map<string, readonly [FieldNode, ...Array<FieldNode>]>,
): PromiseOrValue<ObjMap<unknown>> {
return promiseReduce(
fields.entries(),
Expand Down Expand Up @@ -440,7 +440,7 @@ function executeFields(
parentType: GraphQLObjectType,
sourceValue: unknown,
path: Path | undefined,
fields: Map<string, ReadonlyArray<FieldNode>>,
fields: Map<string, readonly [FieldNode, ...Array<FieldNode>]>,
): PromiseOrValue<ObjMap<unknown>> {
const results = Object.create(null);
let containsPromise = false;
Expand Down Expand Up @@ -484,7 +484,7 @@ function executeField(
exeContext: ExecutionContext,
parentType: GraphQLObjectType,
source: unknown,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
path: Path,
): PromiseOrValue<unknown> {
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
Expand Down Expand Up @@ -558,7 +558,7 @@ function executeField(
export function buildResolveInfo(
exeContext: ExecutionContext,
fieldDef: GraphQLField<unknown, unknown>,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
parentType: GraphQLObjectType,
path: Path,
): GraphQLResolveInfo {
Expand Down Expand Up @@ -619,7 +619,7 @@ function handleFieldError(
function completeValue(
exeContext: ExecutionContext,
returnType: GraphQLOutputType,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
info: GraphQLResolveInfo,
path: Path,
result: unknown,
Expand Down Expand Up @@ -710,7 +710,7 @@ function completeValue(
function completeListValue(
exeContext: ExecutionContext,
returnType: GraphQLList<GraphQLOutputType>,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
info: GraphQLResolveInfo,
path: Path,
result: unknown,
Expand Down Expand Up @@ -801,7 +801,7 @@ function completeLeafValue(
function completeAbstractValue(
exeContext: ExecutionContext,
returnType: GraphQLAbstractType,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
info: GraphQLResolveInfo,
path: Path,
result: unknown,
Expand Down Expand Up @@ -851,7 +851,7 @@ function ensureValidRuntimeType(
runtimeTypeName: unknown,
exeContext: ExecutionContext,
returnType: GraphQLAbstractType,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
info: GraphQLResolveInfo,
result: unknown,
): GraphQLObjectType {
Expand Down Expand Up @@ -908,7 +908,7 @@ function ensureValidRuntimeType(
function completeObjectValue(
exeContext: ExecutionContext,
returnType: GraphQLObjectType,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
info: GraphQLResolveInfo,
path: Path,
result: unknown,
Expand Down Expand Up @@ -948,7 +948,7 @@ function completeObjectValue(
function invalidReturnTypeError(
returnType: GraphQLObjectType,
result: unknown,
fieldNodes: ReadonlyArray<FieldNode>,
fieldNodes: readonly [FieldNode, ...Array<FieldNode>],
): GraphQLError {
return new GraphQLError(
`Expected value of type "${returnType.name}" but got: ${inspect(result)}.`,
Expand Down
2 changes: 1 addition & 1 deletion src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ export type GraphQLFieldResolver<

export interface GraphQLResolveInfo {
readonly fieldName: string;
readonly fieldNodes: ReadonlyArray<FieldNode>;
readonly fieldNodes: readonly [FieldNode, ...Array<FieldNode>];
readonly returnType: GraphQLOutputType;
readonly parentType: GraphQLObjectType;
readonly path: Path;
Expand Down