dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.72k stars 1.31k forks source link

[preset/client] Custom hash function for persisted operations #9994

Open nahn20 opened 4 weeks ago

nahn20 commented 4 weeks ago

Is your feature request related to a problem? Please describe.

I'd like to add more flexibility for persisted operations to allow developers to insert a custom hashing function instead of being limited to sha1 and sha256. This helps to avoid any issues requesting additional algorithms in the future, as well as supports additional use-cases. For example, I have a use-case in which we sign operations with a specific secret, and I'd like to re-use that for the persisted operation hash.

Describe the solution you'd like

An additional configuration option allowing developers to pass in a hashFunction. I've put together a proof of concept here. (Also, I'm happy to create a pull request for this).

Describe alternatives you've considered

Currently, I'm using this plugin which supports the use-case of generating an additional file with the operations and the hashes. For convenience, simplicity, and bundle size, I'd like to attach the hash to the operation document itself.

Is your feature request related to a problem? Please describe.

No response

n1ru4l commented 4 weeks ago

Instead of adding a nee config option we can make allow the existing hash algorithm property to be a function. Please feel free to send a PR with tests and documentation updates!