How best to test the __resolveReference resolver? #5866
-
Howdy folks! As part of our federated gateway, we use the To accomplish this, in import { Author, Resolvers, GraphQLRecursivePick } from '../graphql/types'
const resolvers: Resolvers = {
Author: {
async __resolveReference(
{ id }: GraphQLRecursivePick<Author, { id: true }>,
): Promise<Author> {
...
}
} How should one test (ideally with the service running, so not unit) this resolver? Now, no other entity in Ideally too I would prefer not having to add types/resolvers to accomplish this for the sole purpose of testing, as this gives me a less confidence that this would work in production. What do folks suggest? :) Thanks all! Edit: Should add that I've scoured high and low for suggestions in the docs and online, but have come up dry 💧 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can pretend to be the gateway and executing the query ($representations: [_Any!]!) {
_entities(representations: $representations) {
... on User {
id
username
}
}
} which is documented here: https://www.apollographql.com/docs/federation/subgraphs/#query_entities Hope this helps! |
Beta Was this translation helpful? Give feedback.
You can pretend to be the gateway and executing the
__resolveReference
functions by calling the_entities
field like this:which is documented here: https://www.apollographql.com/docs/federation/subgraphs/#query_entities
Hope this helps!