How to test extensions on federated types? #1924
-
Say I have something like this: @GraphQLName("User")
@KeyDirective(fields = FieldSet("id"))
class User(@ExternalDirective val id: Long) {
fun myField(
env: DataFetchingEnvironment,
) = env.getValueFromDataLoader(...)
} What's a good strategy for testing this? The way I see it there's a lot worthy of testing here. There's checking that the field is added correctly to the type, checking the name of the field, that the dataloader is working correctly and so on. I buy that testing that the external directive and gql name are correct is impossible without running it in a dev/release environment and integrating with other services, but testing the full flow from dataloader => field => entity => graphqlserver (but perhaps not => ktor/springboot/webserver) should be possible somehow? Our setup is a Ktor server, and in our tests we use a test server where we currently add mocked entities of the linked type to be able to access this, but it's not a great setup and you can easily get into a position where you need to manually edit the schema.graphqls. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello 👋 query ($representations: [_Any!]!) {
_entities(representations: $representations) {
...on User {
myField
}
} with variables {
"representations": [
{
"__typename": "User",
"id": 123
}
]
} Currently it is not great user experience so if you have any ideas how to improve it let us know! We (Apollo) are looking into ways how to simplify the entity resolution logic but it may take a while for the feature to land and be made widely available (it requires composition and query planner changes). For the time being --- FYI
|
Beta Was this translation helpful? Give feedback.
Hello 👋
It sounds like you are asking is how to test entities? In order to be able to hit
myField
you need an instance of your type which is resolved through_entities
query -> at a minimum you would need to construct a schema and then you can manually execute entities query, e.g. executing query like thiswith variables
Currently it is not great user experience so if you have any ideas how to improve it let us know! We (Apollo) are looking…