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

Entity resolver tests #1697

Merged
merged 2 commits into from
Nov 9, 2021
Merged

Conversation

MiguelCastillo
Copy link
Collaborator

@MiguelCastillo MiguelCastillo commented Nov 8, 2021

The tests work by sending _entities queries with representation variables directly to the mocked server, which will allow us to test generated federation code 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.

To run the tests:

  1. Build the entityresolver testdata
  • From plugin/federation, run go run github.com/99designs/gqlgen --config testdata/entityresolver/gqlgen.yml
  1. Run the tests with go test ./... or similar

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

}
switch typeName {
case "Hello":
entity, err := func() (*generated.Hello, error) {
Copy link
Collaborator Author

@MiguelCastillo MiguelCastillo Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generated.Hello is one bug where we include generated.


case "World":
entity, err := func() (*generated.World, error) {
id0, err := ec.unmarshalNString2string(ctx, rep["hello"].(map[string]interface{})["name"])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another bug if the entity query is for the key bar then this will throw an error.

@MiguelCastillo
Copy link
Collaborator Author

@vektah these are the tests. I think I may be able to fix the couple of issues I mentioned here some time later today or tomorrow, so sadly these tests are going to be failing until then.

Reorganizing the tests in the federation plugin a little bit so make it simpler to add more safely without testdata colliding. This is in anticipation for a follow up PR for adding entity resolver tests.

Run the tests with `go test ./plugin/federation/...` and verify they all pass. Also verify that the testdata/allthething directory has a `generated` directory specific to that test.

NOTE: There is a catch all type of test that I moved to the directory `allthething`.  Open to suggestions for a better name! One potential thing to considere here is to split up the tests that use that testdata and break them down into more specific tests. E.g. Add a multikey test in the testdata/entity.  For now, Im leaving that as a TODO.
@MiguelCastillo MiguelCastillo force-pushed the entity-resolver-tests branch 6 times, most recently from 2654671 to 94656da Compare November 9, 2021 02:00
The tests work by sending `_entities` queries with `representation` variables directly to the mocked server, which will allow us to test generated federation code 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`.

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
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.2%) to 50.819% when pulling bc3ac51 on Khan:entity-resolver-tests into b7db36d on 99designs:master.

@StevenACoffman StevenACoffman merged commit 01d3c4f into 99designs:master Nov 9, 2021
@StevenACoffman
Copy link
Collaborator

Something weird about how the coverage decreased with this PR.

@MiguelCastillo MiguelCastillo deleted the entity-resolver-tests branch November 15, 2021 14:32
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

Successfully merging this pull request may close these issues.

3 participants