responseReducer returns entire payload when leaf is not truthy
madshall opened this issue · comments
Package
graphql-hooks
Environment
graphql-hooks
version: latest
Description
In this code responseReducer applies only if it returns a truthy value:
data:
// enrich data with responseReducer if defined
(typeof options.responseReducer === 'function' &&
options.responseReducer(data, response)) ||
data,
Consider a use case when we query a single leaf:
query something {
haslevels {
and {
we {
only {
need {
this
}
}
}
}
}
}
My responseReducer will look like this:
responseReducer: (data) => data?.haslevels?.and?.we?.only?.need?.this;
Let's say false
or ''
is a valid value in this use case. We won't receive it, we'll get the entire data object back.
How to reproduce
Create a responseReducer that points to a single field in the response. Make that field being cast to false
.
Suggested solution (optional)
Do not check for the function value to be truthy?