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

Fine-grained support for null values. #2184

Open
alexdupre opened this issue Apr 11, 2024 · 4 comments
Open

Fine-grained support for null values. #2184

alexdupre opened this issue Apr 11, 2024 · 4 comments
Labels
client GraphQL Client module enhancement New feature or request good first issue Good for newcomers

Comments

@alexdupre
Copy link
Contributor

At the moment when a GraphQL query is generated it's possible to decide how to handle None values with the dropNullInputValues parameter, but this applies to all fields.

Unfortunately there are services that have semantic differences between a null value and a missing value, and requires a mix of both options in the same mutation. Shopify is one of this services, and currently it's impossible to use caliban to perform some operations because there isn't a fine grained control over it.

Honestly I don't know what might be the best approach to fix this issue.

@ghostdogpr ghostdogpr added the client GraphQL Client module label Apr 11, 2024
@ghostdogpr
Copy link
Owner

There's an alternative way which is using a custom ArgEncoder, see the example here: #1272 (comment)

Would that work for you?

@alexdupre
Copy link
Contributor Author

Thanks. If I'm understanding it correctly, it can work only with dropNullInputValues = false and by explicitely removing the null values for the encoding, not in the oppose way (default drop, with just a few specified), is it right?
Not super convenient, but it might work.

As an alternative I was thinking to add a new codegen parameter useNullableInputs to replace the binary Option with a ternary (or quaternary) Nullable type (accepting Null/Missing/Value(T) and Undefined) in the generated code. Would it make sense and something that you might want to merge?

@ghostdogpr
Copy link
Owner

I like the idea! What's Undefined for?

@alexdupre
Copy link
Contributor Author

I confirm that setting dropNullInputValues = false and creating an ArgEncoder with a limited set of fields solved the issue. Thanks.

Undefined could be a 4th option to follow the dropNullInputValues behavior:

  • Null enforces null
  • Missing enforces dropping the field entirely
  • Value(T) sets the field
  • (Optional) Undefined uses the dropNullInputValues to determine the behavior

@ghostdogpr ghostdogpr added enhancement New feature or request good first issue Good for newcomers labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client GraphQL Client module enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants