-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support for multiple @key directives in federation #1684
Merged
StevenACoffman
merged 2 commits into
99designs:master
from
carldunham:cd/mutiple-key-directives
Nov 3, 2021
Merged
Support for multiple @key directives in federation #1684
StevenACoffman
merged 2 commits into
99designs:master
from
carldunham:cd/mutiple-key-directives
Nov 3, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
carldunham
force-pushed
the
cd/mutiple-key-directives
branch
from
November 3, 2021 01:41
7ce0f28
to
85beda0
Compare
Thanks for this! |
MiguelCastillo
added a commit
to Khan/gqlgen
that referenced
this pull request
Nov 8, 2021
The tests work by sending `_entities` queries with `representation` variables directly to the mocked server, which will allow us to test the generated end to end. For context, the format of the entity query is something like: ``` query($representations:[_Any!]!){_entities(representations:$representations){ ...on Hello{secondary} }} ``` And `representations` are the list of federated keys for the entities being resovled, and they look like ``` representations: [{ "__typename": "Hello", "name": "federated key value 1", }, { "__typename": "Hello", "name": "federated key value 2", }] ``` The entity resolver tests are in `plugin/federation/federation_entityresolver_test.go` and they rely on `plugin/federation/testdata/entityresolver`. NOTE: currently there are two regressions from 99designs#1684. 1. The generated code federation plugin creates a self executing function for resolving entities. The issue is that the self executing function specifies the graphql entity the resolver returns and it includes the namespace. So generating federation.go in the same package as the generated models causes compile errors. See plugin/federation/testdata/entityresolver/federation.gp:70. 2. When there are multiple federated keys on an entity and one is nested, depending on the order in which the entities are resolved there can be exceptions. Because of the first issue, the generated code has to be manually changed to remove the namespace `generated` from `testdata/entityresolver/generated/federation.go`. Then you should be able to run the tests. The second test fails because of issue two. To run the tests: 1. Build the entityresolver testdata - From plugin/federation, run `go run github.com/99designs/gqlgen --config testdata/entityresolver/gqlgen.yml` 2. Run the tests with `go test ./...` or similar
StevenACoffman
added a commit
that referenced
this pull request
Nov 8, 2021
This reverts commit 47de912.
MiguelCastillo
added a commit
to Khan/gqlgen
that referenced
this pull request
Nov 9, 2021
The tests work by sending `_entities` queries with `representation` variables directly to the mocked server, which will allow us to test the generated end to end. For context, the format of the entity query is something like: ``` query($representations:[_Any!]!){_entities(representations:$representations){ ...on Hello{secondary} }} ``` And `representations` are the list of federated keys for the entities being resovled, and they look like ``` representations: [{ "__typename": "Hello", "name": "federated key value 1", }, { "__typename": "Hello", "name": "federated key value 2", }] ``` The entity resolver tests are in `plugin/federation/federation_entityresolver_test.go` and they rely on `plugin/federation/testdata/entityresolver`. NOTE: currently there are two regressions from 99designs#1684. 1. The generated code federation plugin creates a self executing function for resolving entities. The issue is that the self executing function specifies the graphql entity the resolver returns and it includes the namespace. So generating federation.go in the same package as the generated models causes compile errors. See plugin/federation/testdata/entityresolver/federation.gp:70. 2. When there are multiple federated keys on an entity and one is nested, depending on the order in which the entities are resolved there can be exceptions. Because of the first issue, the generated code has to be manually changed to remove the namespace `generated` from `testdata/entityresolver/generated/federation.go`. Then you should be able to run the tests. The second test fails because of issue two. To run the tests: 1. Build the entityresolver testdata - From plugin/federation, run `go run github.com/99designs/gqlgen --config testdata/entityresolver/gqlgen.yml` 2. Run the tests with `go test ./...` or similar
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your PR and link to any relevant issues.
Adds support for multiple @key directives for OBJECT types, which is allowed for in the Apollo spec. Can be useful in cases where some subgraphs have different pieces of data for an external type that can be resolved in multiple ways.
Should also open the door for #1670 to be implemented, and remove another * from apollographql/apollo-federation-subgraph-compatibility#42.
I have: