Closed melounek closed 4 years ago
hi @melounek, it seems to me correct to foresee the same result for skip and for the fetchPolicy "store-only". the fix is quite simple https://github.com/relay-tools/relay-hooks/blob/master/src/QueryFetcher.ts#L108
As for typing, I wonder if this change is also necessary for official useLazyLoadQuery: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-relay/lib/relay-experimental/useLazyLoadQuery.d.ts#L13
@renanmav, what do you think about it?
typing the QueryRenderer https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-relay/index.d.ts#L117 also provides null.
so, the behavior that @melounek suggests:
null
when is loading and undefined
for skip or not found in store
I find it correct :)
Hmm, I don’t think this should be done by us.
If your query returns empty results, relay-compiler-language-typescript
will detect that (based on your schema) and this would be reflected by T['response']
.
I don’t know If I was clear...
@renanmav that's something else. If the schema returns null the props
will contain something like
{ queryName: null }
and this null is provided by the T['response']
, but during the loading time when we are waiting for the result, the props
contains just null
and this should be explicitly defined in the QueryFetcher.ts
Got it
I have just released version 3.3.0 https://github.com/relay-tools/relay-hooks/releases/tag/v3.3.0
Feel free to open new issues if you find problems :)
There are some TS clashes, when useQuery returns empty results.
props
will return{}
when the new optionskip
is settrue
undefined
when fetchPolicy is set for example tostore-only
and store doesn't contain the resultnull
during the query is loadingI feel like these two options should be unified into
undefined
/null
(null
when is loading andundefined
for skip or not found in store)And in any case, the empty result should be handled by Typescript. So instead of
there should be