Skip to content

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

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

Closed
yaacovCR opened this issue Oct 10, 2021 · 2 comments

Comments

@yaacovCR
Copy link
Contributor

yaacovCR commented Oct 10, 2021

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?

@yaacovCR yaacovCR changed the title Add refine method to object types that have the collected fields Feature Request: add refine method to object types that have the collected fields Oct 10, 2021
@yaacovCR yaacovCR changed the title Feature Request: add refine method to object types that have the collected fields Feature Request: add refine method to object types with access to the collected fields Oct 10, 2021
@yaacovCR
Copy link
Contributor Author

Edited above.

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Oct 6, 2024

Closing this for now — can always reopen at some point if there is more interest

@yaacovCR yaacovCR closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant