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

Fields without @client directive should not be resolved locally #9573

Merged
merged 13 commits into from
Jan 30, 2023

Conversation

vladar
Copy link
Contributor

@vladar vladar commented Apr 1, 2022

Description

This PR fixes an incorrect behavior when local resolvers are executed even for fields without a @client directive. Reproduction is in the PR tests. This happens because Apollo walks through every single selectionSet in LocalState without checking if this selectionSet actually has a @client directive.

This problem also affects query performance significantly in some cases, see the benchmark.

For server GraphQL results like this:

{
  items: [
    { id: "0", foo: "foo-0" },
    { id: "1", foo: "foo-1" },
    // ...
    { id: "99", foo: "foo-99" },
  ]
  serverOrClient: `server`
}

The benchmark shows the following numbers:

Without client resolver (baseline)
100 items x 1,078 ops/sec ±4.69% (58 runs sampled)
1000 items x 128 ops/sec ±5.05% (57 runs sampled)
10000 items x 11.90 ops/sec ±8.81% (55 runs sampled)

With client resolver (before the PR)
100 items x 494 ops/sec ±7.05% (59 runs sampled)
1000 items x 56.21 ops/sec ±6.67% (56 runs sampled)
10000 items x 5.10 ops/sec ±10.75% (28 runs sampled)

With client resolver (after the PR)
100 items x 1,002 ops/sec ±7.57% (60 runs sampled)
1000 items x 123 ops/sec ±7.82% (55 runs sampled)
10000 items x 12.80 ops/sec ±8.15% (58 runs sampled)

Fixes #9571

@apollo-cla
Copy link

@vladar: 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/

@vladar vladar marked this pull request as ready for review April 1, 2022 18:09
@jpvajda jpvajda added the 🏓 awaiting-contributor-response requires input from a contributor label May 3, 2022
@jpvajda jpvajda added 🏓 awaiting-team-response requires input from the apollo team and removed 🏓 awaiting-contributor-response requires input from a contributor labels May 5, 2022
@vladar
Copy link
Contributor Author

vladar commented May 19, 2022

@benjamn @brainkim A gentle ping on this PR - performance implications of even a single @client field are quite significant (especially noticeable for frequent subscriptions with big payloads). I think it deserves to be addressed.

@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2023

🦋 Changeset detected

Latest commit: 03f30f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jerelmiller jerelmiller self-assigned this Jan 27, 2023
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Hey @vladar 👋 !

Thanks so much for your patience. I really like the work you've done here and think this will be a tremendous improvement to the client. I've left only minor bits of feedback for you, but overall really like the strategy you took here. Glad its also been confirmed that this solution works for others. I'd like to get this merged as soon as you're able to address some of the feedback. Thanks again for the contribution!

src/__tests__/local-state/resolvers.ts Outdated Show resolved Hide resolved
src/__tests__/local-state/resolvers.ts Show resolved Hide resolved
src/core/LocalState.ts Outdated Show resolved Hide resolved
src/core/LocalState.ts Outdated Show resolved Hide resolved
src/core/LocalState.ts Outdated Show resolved Hide resolved
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

@vladar thanks so much again for the contribution! Looking forward to getting this released 🎉 🎉

@jerelmiller jerelmiller merged commit 4a4f48d into apollographql:main Jan 30, 2023
@github-actions github-actions bot mentioned this pull request Jan 30, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields not marked with @client are being resolved locally
4 participants