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

fix: make results nullable again if root level errors are enabled #114

Merged

Conversation

rbino
Copy link
Contributor

@rbino rbino commented Feb 9, 2024

Building upon #110, this restores the old behaviour of the result being nullable when root level errors are present.

While the result is guaranteed to not be nullable in standard conditions (since either result or errors are always present), when errors are moved to the root level it could become null, so declaring it non-nullable propagates the null up to the data field.

This actually causes compatibility problems with some client libraries (e.g. Relay) that expect the inner result to be null, not data, if there's an error.

This also adds dedicated RootLevelErrors versions of the Api and the Schema since the configuration is accessed at compile time now, so put_env was not enough to test them correctly.

Contributor checklist

  • Bug fixes include regression tests

@@ -38,7 +36,7 @@ defmodule AshGraphql.ErrorsTest do

assert {:ok, result} = resp

assert %{data: nil, errors: [%{message: message}]} = result
assert %{data: %{"createPost" => nil}, errors: [%{message: message}]} = result
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change returns the behaviour to the one pre #110, so it's not breaking (there was no release between the two)

Building upon ash-project#110, this restores the old behaviour of the result being nullable
when root level errors are present.

While the result is guaranteed to not be nullable in standard conditions (since
either result or errors are always present), when errors are moved to the root
level it could become null, so declaring it non-nullable propagates the null up
to the data field.

This actually causes compatibility problems with some client libraries (e.g.
Relay) that expect the inner result to be null, _not_ data, if there's an error.

This also adds dedicated RootLevelErrors versions of the Api and the Schema
since the configuration is accessed at compile time now, so put_env was not
enough to test them correctly.
@rbino rbino force-pushed the nullable-result-with-root-level-errors branch from c9d9e48 to 988ba62 Compare February 9, 2024 11:32
@zachdaniel zachdaniel merged commit 70eae5f into ash-project:main Feb 9, 2024
13 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

rbino added a commit to rbino/edgehog that referenced this pull request Feb 9, 2024
Makes results nullable when using root level errors (see
ash-project/ash_graphql#114)

Signed-off-by: Riccardo Binetti <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants