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 not marked with @client are being resolved locally #9571

Closed
vigie opened this issue Mar 31, 2022 · 5 comments · Fixed by #9573
Closed

Fields not marked with @client are being resolved locally #9571

vigie opened this issue Mar 31, 2022 · 5 comments · Fixed by #9573

Comments

@vigie
Copy link

vigie commented Mar 31, 2022

It is important to be able to precisely control which fields are resolved locally versus remotely while a remote service is developed and incrementally replaces a local implementation. Once a remote service starts offering a field, I want to start removing @client from some queries that use that field, without yet removing the local resolver definition.

This scenario is not supported today due to a bug.

Intended outcome:
Only fields marked @client should be sent to local resolvers

Actual outcome:
If a @client directive appears anywhere in a document, local resolvers are looked for and run for all fields in the entire document, regardless of whether those fields were tagged with the @client directive.

How to reproduce the issue:
Have a resolver both locally and on the server for a field. Send a query that does not tag that field with @client, but does tag some other field with @client. Observe that the result for the field not tagged with @client was supplied by the local resolver, despite the lack of tag.

The problem is in the local state code that indiscriminately returns the entire document instead of just stripping out the @client parts:

Screen Shot 2022-03-31 at 11 50 13 AM

Versions

  System:
    OS: macOS 12.2
  Binaries:
    Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.0/bin/npm
  Browsers:
    Chrome: 100.0.4896.60
    Firefox: 84.0.1
    Safari: 15.3
  npmPackages:
    @apollo/client: ^3.4.16 => 3.4.16
    apollo-angular: ^2.6.0 => 2.6.0
@vigie
Copy link
Author

vigie commented Mar 31, 2022

I appreciate that local resolvers are being moved out of core and into a link, but this should be addressed regardless of where the implementation lives, thanks

@vladar
Copy link
Contributor

vladar commented Apr 1, 2022

I've faced the same issue, and it turns out that the presence of a single @client directive significantly affects the performance of the whole query because of this (because Apollo basically traverses every single item in the GraphQL result, even for selectionSets without the @client directive).

Here is a benchmark to demonstrate the impact of this issue: https://github.com/vladar/apollo-at-client-bench

Without client resolver
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
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)

Note that the client resolver executes only once for the whole query, but performance degrades significantly. I have a potential fix for this problem, will publish a PR soon.

@vladar
Copy link
Contributor

vladar commented Apr 4, 2022

@vigie can you try PR #9573 and see if it fixes the problem for you?

@vigie
Copy link
Author

vigie commented Apr 12, 2022

Hey @vladar , I finally had time to try your PR and can confirm it fixes the issue. I see the non-client parts only being correctly sent across the link and the client parts only being resolved locally.

Thanks for working on this!

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants