Skip to content
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

allow querying connection metadata and then subsequent data in relayStylePagination #6935

Merged
merged 4 commits into from
Sep 9, 2020

Conversation

anark
Copy link
Contributor

@anark anark commented Aug 29, 2020

Currently if you try to query relay connection metadata with no arguments

query todos{
  totalCount
}

And then query for the edges/data

query todos{
  totalCount
  edges {
    node {
      title
    }
  }
}

The cache will never have any todo items and both data and error returned by the cache will always be undefined.

This attempts to fix this.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@anark: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anark Thanks for jumping into this code, and for adding tests! I agree with most of these changes, but I have one request for further consideration (below).

src/utilities/policies/pagination.ts Show resolved Hide resolved
src/utilities/policies/pagination.ts Outdated Show resolved Hide resolved
src/utilities/policies/pagination.ts Outdated Show resolved Hide resolved
@anark
Copy link
Contributor Author

anark commented Sep 4, 2020

@benjamn Thanks for the feedback.

I've adjusted the implementation, extended the test coverage to cover this, and updated from main. Please let me know what else this needs.

@Ilaiwi
Copy link

Ilaiwi commented Sep 9, 2020

I am dealing with an error that this PR could resolve here.

pagination.js:66 Uncaught TypeError: Cannot read property 'slice' of undefined
    at merge (pagination.js:66)
    at Policies.applyMerges (policies.js:294)
    at policies.js:316

I am getting this when I do a subscribe to more on a field with relay style pagination policy and attempting to update the cache where existing is passed as undefined to the merge function in the policy

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM—thanks @anark!

@benjamn benjamn merged commit 28ee893 into apollographql:main Sep 9, 2020
benjamn added a commit that referenced this pull request Sep 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants