ardatan / ardatan/graphql-mesh

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

Open
#8,286 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.5k
Forks
363
Avg merge
6h 10m
Merged PRs (30d)
19

Description

**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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how resolveTo combines requiredSelectionSet and sourceArgs for the Shopper field in the additionalTypeDefs example. Reproduce the Order case with driverId absent, then verify that the Shopper resolves to null without invoking shopperById or producing a 404 when the change is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.