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

client:push operation is re-ordering document definitions #986

Closed
justinanastos opened this issue Feb 7, 2019 · 3 comments
Closed

client:push operation is re-ordering document definitions #986

justinanastos opened this issue Feb 7, 2019 · 3 comments

Comments

@justinanastos
Copy link
Contributor

justinanastos commented Feb 7, 2019

The problem lies here:

get mergedOperationsAndFragments(): {
[operationName: string]: DocumentNode;
} {
return separateOperations({
kind: Kind.DOCUMENT,
definitions: [
...Object.values(this.fragments),
...Object.values(this.operations)
]
});
}

The order of the definitions is changed, and then the result is hashed. When we use apollo-server-plugin-operation-registry and turn on forbidUnregisteredOperations (https://www.apollographql.com/docs/platform/operation-registry.html#Installation-steps), the operation is received in it's original order, hashed, and then compared. If the order does not match, the operation will be rejected.

Side note: It might be possible that we're relying on apollo-server's sortAST to correctly order the AST. Looking at that function, unless I'm reading it incorrectly, it does not re-order operations, but instead normalizes content inside them.

https://github.com/apollographql/apollo-server/blob/master/packages/apollo-graphql/src/transforms.ts#L97-L151

Two possible solutions:

  1. Find a way to maintain the original order of the definitions in the original document. This could easily be tested, even though it might be harder to implement.

    The operation registry has the luxury the browser interpolating the gql at runtime.

  2. Change sortAST to sort the definitions in a document. I don't know what the ramifications of this would be.

@justinanastos justinanastos changed the title client:push operation is re-ordering operation nodes client:push operation is re-ordering document definitions Feb 7, 2019
@trevor-scheer
Copy link
Member

See apollographql/apollo-server#2282 for initial work and tracking progress. Once this PR lands, transitive dependencies will need to be updated to use the new apollo-graphql package for normalizing operation signatures.

@abernix
Copy link
Member

abernix commented Mar 19, 2019

This should be fixed via #1027. Anyone who is experiencing this problem (which appears to be a fair number, based on 👍 s!) should:

  • Re-register all of their operations with a new version of the apollo CLI which @trevor-scheer and I published under the register tag. Users who do not have apollo installed into their devDependencies of their project's package.json can use:

    npx apollo@register client:push
    

    While this is currently a "3.x alpha" of the apollo CLI, it is only done that way for semantic versioning reasons: to avoid users inadvertently updating to it. It is otherwise functionally identical to 2.x releases of Apollo and we will back-port this functionality to apollo@2 if and when possible. In order to unblock users who are currently experiencing the problem with fragments though, we're offering this immediate upgrade path.

  • After re-registering all operations using client:push on the new version update their apollo-server-plugin-operation-registry to the newer version, currently published on the next tag: npm install apollo-server-plugin-operation-registry@next.

We encourage anyone who is an Apollo Engine plan which includes the operation registry can reach out on Intercom support for help in this upgrade process and someone will be happy to assist.

@abernix
Copy link
Member

abernix commented Mar 19, 2019

cc @ctbradley

@abernix abernix closed this as completed Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants