Paginating over subfield
See original GitHub issueSummary
Hi, I’m coming from Relay where it’s super easy to paginate over subfields. However, I’m not managing to achieve this with apollo, can somebody please give me a heads up?
Problem
When the component loads, the query works fine, then when fetchMore
is called, all data from the paginating field vanish. In the example below, bar
would have results on initial load, then after fetchMore
it becomes []
. What I’m doing wrong?
Code
query
export const MY_QUERY = gql`
query foo($pk: uuid!, $offset: Int = 0) {
foo_by_pk(pk: $pk) {
bar(limit: 20, offset: $offset) @connection(key: "foo_bar") {
...bar_data
}
}
}
${Bar_Fragment.data}
`
field policy
const client = new ApolloClient({
uri: URL,
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
bar: offsetLimitPagination(),
},
},
},
}),
})
fetch more
const onEndReached = () => {
fetchMore({
variables: {
offset: data.foo.bar.length,
},
})
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Pagination with sub field in mongodb - Stack Overflow
Getting sub-fields are can be done with 'dot notation'. Pagination is simply using query.limit() and query.skip() .
Read more >300: Physical Description (Network Development and MARC ...
When the statement of pagination and of illustrative matter are combined, they are both recorded in a single subfield $a.
Read more >Tutorial: Pagination - Apollo GraphQL Blog
In Parts 6 and 7 we went over how to add subscriptions to the server and hot-load changes to the server in your...
Read more >11. 300 ‡a: Extent for multi-parts with Examples - Yale Library
On CIP, with a blank 300 field, and only one volume in hand, a multipart monograph ... these are not recorded as plates...
Read more >Pagination - Hot Chocolate - ChilliCream GraphQL Platform
If we need more control over the pagination process we can do so, by returning a ... if it has been specified as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Great to hear! Since that was the problem, I believe
offsetLimitPagination
can be improved so that it defaultsargs.offset
to zero. I’ll fix that shortly.@benjamn thanks it did help! But a new issue came up with your solution:
I have 2 screens:
Screen 1
Simple feed pagination that was working before the solution:
Screen 2
Details screens that paginate over
bar
for a givenfoo
. Now this one is working as expected thanks to you. Before your solution, I was needing to querybar
with awhere
constraint.Type Policies
Question
@benjamn before your solution, the
Screen 1
was working andScreen 2
broken. Now it’s the opposite. Thebar
field ofScreen 1
is always empty. What am I doing wrong here? Thanks for the help