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

Allow skipping a resolver if required fields are not present in the root type. #8286

Open
jurchfield opened this issue Jan 16, 2025 · 0 comments

Comments

@jurchfield
Copy link

jurchfield commented Jan 16, 2025

Is your feature request related to a problem? Please describe.

Kind of. I need to be able to resolve a Shopper on an Order type, and I have defined this within my additionalTypeDefs:

 extend type Order {
      shopper: Shopper
        @resolveTo(
          sourceName: "Shopper"
          sourceTypeName: "Query"
          sourceFieldName: "shopperById"
          requiredSelectionSet: "{ driverId }"
          sourceArgs: { id: "{root.driverId}" }
        )
    }

It works great when there is a driver/shopper assigned to the order, but that's not always the case.

This seems like it will always run even though the driverId (required by the shopperById query) may not be present, causing 404 errors from the underlying API. At first I thought that requiredSelectionSet handled this validation, but that doesn't seem to be the case.

Describe the solution you'd like

Some way within the resolveTo return null for the Shopper type if the necessary args are not provided.

Describe alternatives you've considered

This is a non-starter for my usage if this isn't possible, as I am hoping to migrate a codebase where we have many nullable resolved objects/fields.

Additional context

I am using GraphQL Mesh for a BFF layer that depends on swagger docs of microservies that I do not manage, so changing the underlying APIs are not an option. I feel this is something that should be configurable.

@jurchfield jurchfield changed the title Allow skipping a resolver if required fields are not present in the type. Allow skipping a resolver if required fields are not present in the root type. Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant