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

feat(core): Reuse stringifyDocument and cached prints across @urql/core #2847

Merged
merged 7 commits into from
Dec 7, 2022

Conversation

kitten
Copy link
Member

@kitten kitten commented Dec 1, 2022

Resolves #2787

Summary

This changes the internals of @urql/core to allow us to reuse stringifyDocument in fetchOptions and other places, to ensure that printing is memoised whenever possible — including for formatDocument outputs.

This means that we had to adjust our hashing slightly to account for the different outputs; that said, sanitisation will still be applied to stringifyDocument inputs. However, we will no longer reuse loc.source strings when they haven't been printed by @urql/core.

Set of changes

  • Replace phash hashing function and create opaque type for clarity
  • Refactor request.ts' stringifyDocument and hashing
  • Reuse stringifyDocument in subscriptionExchange and fetchOptions
  • Update document sanitisation to only remove comments
  • Update hashing to add the operation name only to the hash key, rather than the stringifyDocument output

@kitten kitten requested a review from JoviDeCroock December 1, 2022 13:25
@kitten kitten merged commit ece64fc into main Dec 7, 2022
@kitten kitten deleted the feat/reuse-stringify-document branch December 7, 2022 12:37
@github-actions github-actions bot mentioned this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Memoize the printing of queries
2 participants