-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paginating over subfield #7135
Comments
I haven't used TypePolicies yet, but is it:
|
@KeithGillette thanks for the response, but didn't work :( neither under Same issue:
|
@PedroBern What's the type of the object returned for the In other words, assuming the type is new ApolloClient({
uri: URL,
cache: new InMemoryCache({
typePolicies: {
Foo: { // instead of Query
fields: {
bar: offsetLimitPagination(),
},
},
},
}),
}) You also do not need the |
@benjamn thanks it did help! But a new issue came up with your solution: I have 2 screens: Screen 1Simple feed pagination that was working before the solution: query FooFeed($offset: Int = 0) {
foo(limit: 20, offset: $offset,){
...FooItem_data
bar(limit: 1) {
...BarItem_data
}
}
} Screen 2Details screens that paginate over query FooDetail($pk: uuid!, $offset: Int = 0) {
foo_by_pk(pk: $pk) {
bar(limit: 20, offset: $offset) {
...BarItem_data
}
}
} Type Policiesexport const cache: InMemoryCache = new InMemoryCache({
typePolicies: {
foo: {
fields: {
bar: offsetLimitPagination(), // used in Screen 2 -> Details
},
},
Query: {
fields: {
foo: offsetLimitPagination(), // used in Screen 1 -> Feed
},
},
},
}) Question@benjamn before your solution, the |
@PedroBern Can you see what happens if you do |
@benjamn Yes actually I have already done it and worked, was coming here to tell you! It's weird that now I need to add some useless arguments in the queries, but it's ok for now. Also, I need to add all Thanks for the time you took to help me :) You can close it now, or maybe let it open, I think it has something to do with #6502 query FooFeed($offset: Int = 0) {
foo(limit: 20, offset: $offset,){
...FooItem_data
bar(limit: 1, offset: 0) { # add offset to be type policy compliant (?)
...BarItem_data
}
}
} |
Great to hear! Since that was the problem, I believe |
does this technique also work with relayStylePagination? |
Summary
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 afterfetchMore
it becomes[]
. What I'm doing wrong?Code
query
field policy
fetch more
The text was updated successfully, but these errors were encountered: