This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
add generateId option to graphql-mini-transforms #99
base: main
Are you sure you want to change the base?
add generateId option to graphql-mini-transforms #99
Changes from 5 commits
5439516
7f42407
d50b4da
fad6a45
f6d9023
c8c54ff
13b8012
d099346
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking this here, can you add a default value when destructuring the argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow this remark. What default value are you suggesting? The line you've commented on would still be required, so do you just want to explicitly destructure to
undefined
ornull
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what he proposed is something like :
If we want to do something like this, both
defaultGenerateId
andgenerateId
will have to receive the same source. Currently,defaultGenerateId
receives the normalized source and thegenerateId
receives the document source.I don't remember why
generateId
needs the document source.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's what the code originally looked like... the commits and comments leading to that change are still there for review. That's why I'm a bit confused.
While changing the code to prevent printing the source twice, I also changed it so that
minifySource
was only called once since the extra operations seemed to be a concern.The general
generateId
needs the unminifed source (this is explained in a previous comment). The default implementation minifies it, so it was happening twice. That motivated that change.I can change it back, but I'm going to address the other comments first and leave this for now, so I don't go in circles on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I just missed this, but I am a bit confused why
generateId
needs to take the "full" document source, not the minified version. I assumed everything should be operating on the minified source, since that includes all the relevant fragments and normalizes away differences in whitespace and commas.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to take a decision on what we want here. Do we want to pass the minified version or the "full" document source to the
generateId
function?generateId
would be the simplest solution but I think this was causing an issue for your use case @dsanders11 ?The key points here are what is the limitation with the minified version @dsanders11 and does the cost of the minification is high @lemonmade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexandcote, I think you've accurately summarized where things stand.
In no way trying to be rude, but all of the previous discussion and explanation still exists in this PR, nothing has been deleted. If you don't remember something about certain choices I'd suggest looking back on the other comments here for clarification. My comment from September explains why the non-minified version is needed for
generateId
. If that explanation isn't clear, I can try to clarify any point of confusion. The TL;DR is simply that the string given togenerateId
should match the query sent to the server, and the query sent to the server is the non-minified version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is an unfortunate side effect of me/ us having let a PR review go for 4 months :p
I see where you are coming from on this, but I worry that the approach is very specific to one very special case where the printed, "normalized" document is identical to the original GraphQL source. This only happens when you aren't using fragments from external files, and you aren't letting the library automatically add
__typename
fields. IMO, this case is specific and uncommon enough (__typename
additions are on by default), that we should push the pain of dealing with it to consumers' application code. An application can fairly easily run the same minification on the server source before computing the SHA (happy to export a utility for it if necessary), and that will work regardless of the fragment/ typename situation (and also works if you ever switch to our "simple" document format that doesn't need to be parsed and re-printed by the GraphQL client).How do you feel about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't do that, I think we need to give the "generate me an ID" option three different sources that might be relevant for them: the minified source code, the original document source code (no fragments or typenames embedded), and the "normalized" document that includes all the fragments and typenames.