Replies: 1 comment
-
Use a caching (dataloader) pattern on your db layer, so that those field resolver will call the db once and share the result data. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If I have a
Person
object and add two fields -petName
andpetBreed
- is there a way to use a single resolver when either field is requested? In order to knowpetName
, I have to query for the person's pet. Once I've queried for the pet, I'd also have the breed. What I want is that if both fields are requested, only one query is made for the pet, but if either field is requested alone, it's able to query for the pet.The only solution that comes to mind is to use promises. The resolver for each field would first check the pet promise and wait on it if it exists, otherwise create and set the shared promise and then query for the pet. It would of course also be possible to create a
pet
object with these fields and have a single resolver for that, but I'm curious if what I'm asking for is possible as well.Beta Was this translation helpful? Give feedback.
All reactions