Closed Emilios1995 closed 2 years ago
GraphQL does not understand undefined
. You want resolve: ({minPrice}) => minPrice ?? null
I get that its a little inconvenient though. I actually suggest you changing the type definition of SearchCriteria
to use number | null
GraphQL does not understand
undefined
. You wantresolve: ({minPrice}) => minPrice ?? null
I get that its a little inconvenient though. I actually suggest you changing the type definition of
SearchCriteria
to usenumber | null
Thanks for answering. I understand that absent fields have to be represented as null
rather than undefined
because otherwise they would be missing from the serialized JSON, but I was under the impression that graphql-js
will just convert undefined
values to null
—isn't that the case?
@Emilios1995 Actually you are right: https://stackblitz.com/edit/graphql-pkmsvz?file=index.js
Mhmm good catch - maybe we should do this
PR to fix this in https://github.com/sikanhe/gqtx/pull/65
@Emilios1995 the version gqtx@0.8.2-4c93b62b.0
contains this change is on npm, let me know if you can try it out
In master
Thanks a lot!
In the following code,
The compiler throws an error if I don't provide the
resolve
function. The reason is thatt.Int
is of typeScalar<number | null>
, while mySearchCriteria.minPrice
is of typenumber | undefined
, so the later doesn't extend the former.It would be great if the built in scalars (if they're not non-nullable) supported the
undefined
value too, like soInt: Scalar<number | null | undefined>
.