Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding entity resolver tests in the federation plugin
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
- Loading branch information