Skip to content

Feature Request: add refine method to object types with access to the collected fields #3303

Closed as not planned
@yaacovCR

Description

@yaacovCR

Right now, we provide the fieldNodes as part of the info parameter for resolvers, but the fields are not collected, because the type is not yet known until the resolver returns. Since the type resolver logic may be known, resolvers can include that logic and collect fields manually based on that known type, and then perform whatever logic necessary => but that means that fields are collected twice, once by the framework, and once by the resolver. It would be great if there was a hook that could provide access to the collected fields and allow modification of the result.

The proposal: add a refine method to GraphQLObjectTypes with signature:

export type GraphQLFieldRefiner<
  TSource,
  TContext,
  TArgs = { [argument: string]: any },
  TInitialResult = unknown,
  TFinalResult = unknown,
> = (
  source: TSource,
  args: TArgs,
  context: TContext,
  info: GraphQLResolveInfo,
  initialResult: TInitialResult,
  collectedFields: Map<string, ReadonlyArray<FieldNode>>,
) => TFinalResult;

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions