returning null for a custom scalar's serialize
There is an old issue #1057 for that.
It has been fixed in #1104. But It does not work for now (v16.3.0).
https://github.com/graphql/graphql-js/blob/b38429f4d46b17f23d15406a2ca0d1eb201864b6/src/execution/execute.ts#L783-L795
@leebyron Is it a mistake or as expected?
Hi @IvanGoncharov,
Since this issue is unresponsive for a long time. I noticed that you are a recent committer for this project. May I ask what you think about this issue?
Due to this problem. I cannot returns a null value manually for a resolver. And the void scalar like this doesn't work.
I really hope this can be fixed if it's not intentional.
@cnwangjie Spec says: https://spec.graphql.org/draft/#sel-IANRLHHCDCECCGBke
This internal method must return a valid value for the type and not null.
"internal method" is serialize in graphql-js API.
So it's intentional.
All fields in GraphQL are nullable by default which makes it impossible to distinguish between null as GraphQL null and null produced by a scalar.
And for input types, it is even worse.
Hey @IvanGoncharov, what's the recommended workaround for this?
@Yifeng-Sigma did you find a workaround for this?
@Yifeng-Sigma did you find a workaround for this?
No, probably I shouldn't use scalar if it's nullable.
I just ran into this in production after upgrading to graphql 16.x and it appears to be a regression to me.
We absolutely want our custom Scalar to decide whether to return null or not – if it's a nullable field that should be valid.
This is a bit of an unexpected and very annoying behavior, even if it's intentional, as it means you can't really use custom Scalars on nullable fields.
The best workaround seems to be to return an empty string, but it is of my opinion that such behavior should be reavaliated.