dotansimha / dotansimha/graphql-code-generator

Client preset uses a different hash than apollo server

Open
#9,108 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/client-preset

### Describe the bug

Currently [client preset uses sha1](https://github.com/dotansimha/graphql-code-generator/blob/298cd13ac08f455958c33066a58b838209e90fae/packages/presets/client/src/persisted-documents.ts#L8-L12) while [Apollo Server uses sha256](https://github.com/apollographql/apollo-server/blob/d7e9b97595b063f1e796ec4449850a16d19e8b18/packages/server/src/requestPipeline.ts#L74-L76) with [no plans to make it configurable](https://github.com/apollographql/apollo-server/issues/2894#issuecomment-509387627).

Ideally the exact hashing behavior here would be configurable without me needing to use `unstable_onExecutableDocumentNode` or rewrite my own version of `ClientSideBaseVisitor`.

Ideally, I would like to write my own plugin similar to [`graphql-codegen-persisted-query-ids`](https://github.com/valu-digital/graphql-codegen-persisted-query-ids) that could operate on the document nodes generated by upstream plugins. Currently, the `documents` passed into a plugin are the 'raw' documents from source, but ideally the could be the documents generated by 'upstream' plugins.

The benefit of allowing me access to the generated documents in a plugin is it would allow me to use whatever framework specific hashing I need to do without y'all needing to support every single possible target out there.

### Your Example Website or App

N/A linked directly to relevant code above

### Steps to Reproduce the Bug or Issue

N/A linked directly to relevant code above

### Expected behavior

At a minimum the hash would match what Apollo Server is using since you refer to the "APQ Specification of Apollo" in your current docs: https://the-guild.dev/graphql/yoga-server/docs/features/automatic-persisted-queries.

Best case, I would be able to write a plugin that hashes the document nodes myself without using unstable APIs or effectively duplicating core code.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 16.19.0
- `graphql` version: 16.6.0
- `@graphql-codegen/*` version(s): 3.2.1

### Codegen Config File

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.