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

refactor(experimental): use json-stable-stringify with bigint support for cache keys #2022

Conversation

buffalojoec
Copy link
Contributor

This PR swaps fast-stable-stringify for json-stable-stringify for the
resolvers' cache key functions.

Adding bigint support via the replacer option solves the BigInt parsing
bug reported in #1986.

Closes #1986.

Copy link
Contributor

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Clean! 👌

Copy link
Contributor Author

buffalojoec commented Jan 9, 2024

Merge activity

@buffalojoec buffalojoec merged commit 0835c79 into master Jan 9, 2024
7 checks passed
@buffalojoec buffalojoec deleted the 01-09-refactor_experimental_use_json-stable-stringify_with_bigint_support_for_cache_keys branch January 9, 2024 23:12
@steveluscher
Copy link
Collaborator

Unfortunately, this has to be backed out. #2014 (comment)


function replacer(_: any, value: any) {
if (typeof value === 'bigint') {
return value.toString() + 'n';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes these a hash collision:

  • {foo: 1n}
  • {foo: '1n'}

"fast-stable-stringify": "^1.0.0",
"graphql": "^16.8.0"
"graphql": "^16.8.0",
"json-stable-stringify": "^1.1.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@buffalojoec
Copy link
Contributor Author

Alright, I'll revisit this ASAP. Are we sure rolling our own hasher is the most efficient way to do this? Would we reuse it anywhere else?

Steve shared a scratch-pad approach to forking fast-stable-stringify and turning it into a hash function with SubtleCrypto, didn't seem too bad.

@lorisleiva
Copy link
Contributor

Since the replacer of json-stable-stringify doesn't fit our need, I'd vote for forking our own version over writing an asynchronous implementation.

Making such a low-level helper asynchronous could bubble up the asynchronousnesss all over the place.

@steveluscher
Copy link
Collaborator

Yeah, I see it as real simple. These stringifiers endeavour to be JSON compatible when that’s the last thing we need. We just need something order-independent, deterministic, and unique.

nobody will accept a PR for this. We can however fork fast-stable-stringify, and make it JSON incompatible by forcing it to shit out the string {"foo":1n}

@steveluscher
Copy link
Collaborator

Making such a low-level helper asynchronous could bubble up the asynchronousnesss all over the place.

It would definitely suck. On the other hand we could still make a sync version with a userland implementation of SHA-256. I just don’t know how much slower this would be than the ‘crap out megabytes of strings’ solutions.

It would definitely be more space efficient though. Ask me for that story later.

Copy link
Contributor

🎉 This PR is included in version 1.89.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2024
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.

[graphql] BigInt variables cause runtime fatal when passed to isFinite()
3 participants