You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just spent two days trying all sorts of things to debug why my pagination wasn't working. The good news is, I now have an intimate understanding of the Urql relayPagination inner workings and its test
(and I see some robustness changes in the tests I'd be happy to make separately)
Cursor nullability
The test seem to indicate that there's a relationship between hasNextPage being false and endCursor being null as well as hasPreviousPage being false and startCursor being null. However, this is incorrect. The Relay cursor specification states
startCursor and endCursor must be the cursors corresponding to the first and last nodes in edges, respectively.
I believe the tests should be updated to reflect the above condition. The cursors in pageInfo should only ever be null when there are no edges. (The spec currently says cursors should be a non-nullable type, contradicting even that, but that's being worked on)
Subset test confusion
The test returns a subset of the cached items if the query requests less items than the cached ones does not do what it states on the tin. Its implementation actually tests that the entire cache is returned when a smaller subset is requested.
The naming of this test is somewhat confusing. The name of the test may do what you expect but the behaviour of the test matches that of the documentation (and behaviour desirable for pagination).
I hope we can use the data that urql has available for itself to save another developer that same time.
Proposed Solution
Would it be possible to validate the resolvers configuration of the Graphcache schema against the schema that is loaded for schema awareness when Urql is used in development mode?
Requirements
When schema awareness is set-up the Graphcache should check the keys for the resolvers entry of its configuration and
Check that all defined types exist, provide a warning if that's not the case
Check that all used types are concrete types. Graphcache currently doesn't apply a resolver for an interface to all its implementing types, so the user should get a warning saying something like Graphcache does not support resolvers for interface types. Please move the resolver for 'Interface' to the concrete types 'SomeImplementsInterface', 'OtherImplementsInterface'.
The text was updated successfully, but these errors were encountered:
Kingdutch
added
the
future 🔮
An enhancement or feature proposal that will be addressed after the next release
label
Jan 12, 2021
Could it be that you'd maybe want to submit a bug ticket if they're slightly inaccurate at times?
kitten
added
needs more info ✋
A question or report that needs more info to be addressable
and removed
future 🔮
An enhancement or feature proposal that will be addressed after the next release
labels
Jan 12, 2021
However, the scenario I ran into is that I defined a resolver for an interface. However, resolvers for interface types are never actually used since the __typename returned by API calls, that is used by the cache, are always a concrete type.
functionwarnAboutAbstractResolver(name: string,kind: 'UNION'|'INTERFACE'): void{warn(`Invalid resolver type: \`${name}\` does not match to a concrete type in the schema, but the \`resolvers\` option is referencing it. Implement the resolver for the types that ${kind==='UNION' ? 'make up the union' : 'implement the interface'} instead.`,26);}
This would help catch the scenario that I ran into sooner and provides a message on how to resolve this issue.
Summary
I've just spent two days trying all sorts of things to debug why my pagination wasn't working. The good news is, I now have an intimate understanding of the Urql relayPagination inner workings and its test
(and I see some robustness changes in the tests I'd be happy to make separately)
Cursor nullability
The test seem to indicate that there's a relationship between
hasNextPage
being false andendCursor
being null as well ashasPreviousPage
being false andstartCursor
being null. However, this is incorrect. The Relay cursor specification statesI believe the tests should be updated to reflect the above condition. The cursors in pageInfo should only ever be null when there are no edges. (The spec currently says cursors should be a non-nullable type, contradicting even that, but that's being worked on)
Subset test confusion
The test
returns a subset of the cached items if the query requests less items than the cached ones
does not do what it states on the tin. Its implementation actually tests that the entire cache is returned when a smaller subset is requested.The naming of this test is somewhat confusing. The name of the test may do what you expect but the behaviour of the test matches that of the documentation (and behaviour desirable for pagination).
I hope we can use the data that urql has available for itself to save another developer that same time.
Proposed Solution
Would it be possible to validate the
resolvers
configuration of the Graphcache schema against the schema that is loaded for schema awareness when Urql is used in development mode?Requirements
When schema awareness is set-up the Graphcache should check the keys for the
resolvers
entry of its configuration andGraphcache does not support resolvers for interface types. Please move the resolver for 'Interface' to the concrete types 'SomeImplementsInterface', 'OtherImplementsInterface'.
The text was updated successfully, but these errors were encountered: