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

Support where Null value came from #183

Closed
pepsighan opened this issue May 16, 2018 · 3 comments · Fixed by #795
Closed

Support where Null value came from #183

pepsighan opened this issue May 16, 2018 · 3 comments · Fixed by #795

Comments

@pepsighan
Copy link
Contributor

pepsighan commented May 16, 2018

I wanted to do PATCH operation in GraphQL but came to know that I had to do a workaround like #108 which in my honest opinion makes me write more code for little effect which is no fun.

In that issue, it was stated along with the workaround that :

Lee Byron and friends (GraphQL designers and spec writers) recommend that you don't use null as a sentinel value for partial updates as most languages don't have the undefined/null distinction and because it limits implementors on how to treat values and objects/hashes.

I counter that with The GraphQL Spec which clearly dictates, though undefined is still not supported, an absence of null can be interpreted differently that explicit null.

For example, these two field calls are similar, but are not identical:

{
 field(arg: null)
 field
}

The first has explictly provided null to the argument “arg”, while the second has implicitly not provided a value to the argument “arg”.
These two forms may be interpreted differently. For example, a mutation representing deleting a field vs not altering a field, respectively.

So, even though only Null value is supported, it would be true to the spec if we would be given the source of the said value, whether it was explicit or implicit.
Like:

enum InputValue {
    Null(Null)
    ...
}

struct Null {
    explicit: bool
}

And may be a helper conversion to Option<Option<T>> where

None => unspecified
Some(None) => null
Some(Some(value)) => value
@mhallin
Copy link
Member

mhallin commented May 18, 2018

Yes, it seems as if the GraphQL spec and authors changed their stance on null vs. undefined since we last looked at this.

I think the easiest change would be to add a tri-state enum like this:

enum GraphQLOption<T> {
    Absent,
    None,
    Some(T),
}

This would let you continue to use Option<T> where you don't care about null vs. absent, or this enum in the cases you do. It does require some infrastructure support though, the difference between those two cases are removed pretty early in processing today, as far as I can remember.

@msdinit
Copy link
Contributor

msdinit commented Jul 2, 2020

Hey,
Looking into trying to implement this feature, was wondering if anybody else is actively working on this, and if GraphQLOption is still the preferred way to handle this case?

@ccbrown
Copy link
Contributor

ccbrown commented Oct 23, 2020

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 a pull request may close this issue.

4 participants