-
Notifications
You must be signed in to change notification settings - Fork 469
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
Sort fragments during operation registry operation normalization #1027
Sort fragments during operation registry operation normalization #1027
Conversation
3296fd0
to
9e2fa7d
Compare
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.
Real talk, thanks for the incredibly clear PR body and the semantic commits.
This looks pretty great to me. I've left some comments which I think are worth considering within. I think we're pretty clear on applying these same changes to apollo-server-plugin-operation-registry
as a PR too. I suspect that any follow-up changes to finalize it (e.g. changing the import
-ed function name or matching version
) would be be relatively straight forward.
@@ -66,3 +66,9 @@ export function defaultEngineReportingSignature( | |||
) | |||
); | |||
} | |||
|
|||
export function hashForOperationSignature(operationSignature: string): string { |
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 should keep the word signature out of this even if it's already been a pattern. I think documentHash
or operationHash
might be appropriate. While it was at one time more of a signature (in that it was lossless and not hashed), the signature in the manifest today is actually a hash and I suspect it will remain that way based on the recent discussions we've had.
I realize this suggestion also breaks the name of the file since we're inside signature.ts
right now. That said, I don't think we have anything that relies on the current path-based import and this is relatively new so I think we could still rename this file to something else if we wanted. Straw-person: id
? (But definitely open to something else).
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.
Resolved in 9dfc76e
I'm for this name change. IMO, id
for the filename doesn't give enough information. I went with operationId
which still doesn't feel right.
In my mind, id
-> identifier. I think what we want to express is that this module is for the verb identification.
operationIdentification
? Something else? I'm open to suggestion.
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'd be fine with operationId
or operationIdentification
, the latter being great if it seems to be better fit in your mind!
ctx.filename = filename; | ||
writeFileSync( | ||
filename, | ||
JSON.stringify({ version: 1, operations: ctx.operations }, null, 2) |
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.
It's possible we should bump this version
to 2
, even with the current changes.
Reason being: currently, the apollo-server-plugin-operation-registry
will throw
if the manifest it tries consuming is version !== 1
, so this should allow us to ensure that the new apollo-server-plugin-operation-registry
which starts consuming this will use the same pre-hash normalization algorithm against incoming operations.
If we do bump this, I definitely think we should change the signature
attribute on the individual documents in the operations[]
to be sha256Hash
as @glasser has proposed.
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.
Going to go forward with the version bump, but for now, changing the shape of operations[]
does require a change to the backend (see: RegisteredOperationInput
type).
My intuition says to defer this until 2.0 work in order to keep the scope of this work within reason, but I'm open to being convinced otherwise if you believe this is important enough.
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.
Resolved in f7915e1
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.
Deferring the change of signature
seems fine. We also need to update the backend (not in open-source land!) to support a different version
other than 1
.
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.
Added to overall TODOs and will leave this issue unresolved until I address it on the backend 👍
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.
Overall looking good!
be6231f
to
6137504
Compare
// should not be depended on in the future, as it's likely we will choose not | ||
// to hide them at all. The rationale being, if queries are being shipped to | ||
// a client bundle, exposing PII via this signature is a very small concern, | ||
// relatively speaking. | ||
export function defaultEngineReportingSignature( |
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.
Can we just not change defaultEngineReportingSignature at all in this PR, especially since it's an interim quick fix?
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.
Concur!
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.
Resolved in 7714ee1
0f9d90e
to
7714ee1
Compare
@abernix the comment about What do you propose for moving the logic to one place? Would it be appropriate to open a PR against AS to use |
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.
The parts of this that I've been paying attention to look good.
@trevor-scheer any updates on Apollo Operation Registry? |
@ctbradley: as we speak, @abernix and I are fully focused on landing this fix! |
…. (#1112) * Cutover to apollo-graphql * Add apollo-graphql as a dependency (and project reference) * Remove apollo-engine-reporting as a dependency * Update sortAST to normalize order of fragments w.r.t operations * Tests are failing expectedly at this point * Update tests This update is exactly as expected. All fragments will now move to the beginning of a normalization result. * Use snapshot tests This is a valid use case for snapshots. Even better would be inline snapshots - something we can get to later. * Centralize operation hashing function These two operations will likely be used in tandem, and we want this to be consistent across consumers. * Incorporate rename suggestions * Add explicit comment about sort order * Transform the operation in a less aggressive manner - don't remove aliases and be less strict about removing literals. * Update incorrect reference to renamed module, update related snapshots. * Revert changes to defaultEngineReportingSignature. Apply changes to new function, defaultOperationRegistrySignature. This new function is the effective interim fix, and the current existing function is now left alone. * Add CHANGELOG.md entry for #1112.
7714ee1
to
131bc40
Compare
1) Remove duplication from client:push and client:extract. 2) Create a test to verify upcoming changes for this PR.
* Add apollo-graphql as a dependency (and project reference) * Remove apollo-engine-reporting as a dependency * Update sortAST to normalize order of fragments w.r.t operations * Tests are failing expectedly at this point
These two operations will likely be used in tandem, and we want this to be consistent across consumers. Incorporate rename suggestions Update version for extracted manifest output. Use empty string and add comment about unused metadata field. Revert changes to defaultEngineReportingSignature. Apply changes to new function, defaultOperationRegistrySignature. This new function is the effective interim fix, and the current existing function is now left alone.
131bc40
to
ad47aa1
Compare
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.
LG(reat)TM! 🎉
This is a breaking change that will necessitate users of the apollo-server-plugin-operation-registry
plugin bump their version of that plugin to a version that matches this normalization technique. We expect that to be apollo-server-plugin-operation-registry@0.1.x
-(something) but the exact version is yet to be determined.
Since this is a breaking change this PR intentionally targets the release-apollo-3.x
branch where it will live (and we'll open a PR soon to track those changes more specifically.)
Great work, @trevor-scheer!
This includes the work from #1027, #1115 and #1118, which first surfaced in an `apollo@next` CLI version which was released in order to provide a migration path for paying customers who utilize the Apollo Operation Registry through the CLI's `apollo client:push` features. Those customers were notified and advised to either pin their `apollo` version prior to this being released, so the hope is that we'll be able to released this under the `apollo@2` cover without incurring breaking changes on anyone else. The summary of the relevant commit messages is below: 1) Remove duplication from client:push and client:extract. 2) Create a test to verify upcoming changes for this PR. Cutover to apollo-graphql * Add apollo-graphql as a dependency (and project reference) * Remove apollo-engine-reporting as a dependency * Update sortAST to normalize order of fragments w.r.t operations * Tests are failing expectedly at this point Centralize operation hashing function These two operations will likely be used in tandem, and we want this to be consistent across consumers. Incorporate rename suggestions Update version for extracted manifest output. Use empty string and add comment about unused metadata field. Revert changes to defaultEngineReportingSignature. Apply changes to new function, defaultOperationRegistrySignature. This new function is the effective interim fix, and the current existing function is now left alone. Pass operation name along to the operation registry signature function Leverage updated registerOperations API Now that registerOperations supports version as an argument to the mutation, we can leverage this for v2 oeprations manifest work.
This includes the work from #1027, #1115 and #1118, which first surfaced in an `apollo@next` CLI version which was released in order to provide a migration path for paying customers who utilize the Apollo Operation Registry through the CLI's `apollo client:push` features. Those customers were notified and advised to either pin their `apollo` version prior to this being released, so the hope is that we'll be able to released this under the `apollo@2` cover without incurring breaking changes on anyone else. The summary of the relevant commit messages is below: 1) Remove duplication from client:push and client:extract. 2) Create a test to verify upcoming changes for this PR. Cutover to apollo-graphql * Add apollo-graphql as a dependency (and project reference) * Remove apollo-engine-reporting as a dependency * Update sortAST to normalize order of fragments w.r.t operations * Tests are failing expectedly at this point Centralize operation hashing function These two operations will likely be used in tandem, and we want this to be consistent across consumers. Incorporate rename suggestions Update version for extracted manifest output. Use empty string and add comment about unused metadata field. Revert changes to defaultEngineReportingSignature. Apply changes to new function, defaultOperationRegistrySignature. This new function is the effective interim fix, and the current existing function is now left alone. Pass operation name along to the operation registry signature function Leverage updated registerOperations API Now that registerOperations supports version as an argument to the mutation, we can leverage this for v2 oeprations manifest work.
This includes the work from #1027, #1115 and #1118, which first surfaced in an `apollo@next` CLI version which was released in order to provide a migration path for paying customers who utilize the Apollo Operation Registry through the CLI's `apollo client:push` features. Those customers were notified and advised to either pin their `apollo` version prior to this being released, so the hope is that we'll be able to released this under the `apollo@2` cover without incurring breaking changes on anyone else. For more information on the operation registry, see: https://www.apollographql.com/docs/platform/operation-registry.html And if you encounter any problems, please contact our customer support via Intercom from within your Engine UI. --- The summary of the relevant commit messages is below: 1) Remove duplication from client:push and client:extract. 2) Create a test to verify upcoming changes for this PR. Cutover to apollo-graphql * Add apollo-graphql as a dependency (and project reference) * Remove apollo-engine-reporting as a dependency * Update sortAST to normalize order of fragments w.r.t operations * Tests are failing expectedly at this point Centralize operation hashing function These two operations will likely be used in tandem, and we want this to be consistent across consumers. Incorporate rename suggestions Update version for extracted manifest output. Use empty string and add comment about unused metadata field. Revert changes to defaultEngineReportingSignature. Apply changes to new function, defaultOperationRegistrySignature. This new function is the effective interim fix, and the current existing function is now left alone. Pass operation name along to the operation registry signature function Leverage updated registerOperations API Now that registerOperations supports version as an argument to the mutation, we can leverage this for v2 oeprations manifest work.
Until the work in apollographql/apollo-tooling#1027 is completed, this will ensure that we can publish this package with the current setup, which I'd rather do for the first time _soon_ rather than _whenever_.
Until the work in apollographql/apollo-tooling#1027 is completed, this will ensure that we can publish this package with the current setup, which I'd rather do for the first time _soon_ rather than _whenever_.
Until the work in apollographql/apollo-tooling#1027 is completed, this will ensure that we can publish this package with the current setup, which I'd rather do for the first time _soon_ rather than _whenever_.
Preface
Now that we've migrated
apollo-graphql
into this repo (and made some decisions about the state of op. normalization), I'm unblocked from making these changes.Previous discussion and work for reference:
apollographql/apollo-server#2282
With the expectation that future work will drastically simplify the way we normalize operations for the registry, we came to the consensus to solve an immediate problem now, and make larger changes later on as operation registry v2 becomes ready for implementation.
Purpose
The main focus of this PR is to sort fragments w.r.t operations within a document as one of the steps in
sortAST
. The important snippet is literally just this:Miscellaneous
Some other changes in this PR that felt appropriate:
client:extract
andclient:push
defaultEngineReportingSignature
as the only way to do normalization within the CLIapollo-graphql
, in order to be prescriptive about how the operation signature hash is generated (hashForOperationSignature
)TODO
apollo-server-operation-registry-plugin
to use both:defaultEngineReportingSignature
hashForOperationSignature
TODO: