You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we can't set root operation resolvers. We can only set resolvers for the fields of the root operations. This is in contrast to the object fields of a non-root object type, where we can set the resolver for the field and additionally for the sub-fields. It would be useful to treat the root operation as any other object type for which a resolver can be set.
One use case for a root operation resolver is atomic transactions. For two mutations, either both should succeed or both should fail. Because resolvers are run sequentially, we can't coordinate the database calls through shared state, since one needs to return before the other even started. With root resolvers, we could handle both mutations in a single resolver and ensure an atomic transaction. One limitation would be, that both mutations can only return the same type, since the single return value from the root resolver would be used for both.
This would probably work well together with middleware #1516 too.
Uh oh!
There was an error while loading. Please reload this page.
Currently, we can't set root operation resolvers. We can only set resolvers for the fields of the root operations. This is in contrast to the object fields of a non-root object type, where we can set the resolver for the field and additionally for the sub-fields. It would be useful to treat the root operation as any other object type for which a resolver can be set.
One use case for a root operation resolver is atomic transactions. For two mutations, either both should succeed or both should fail. Because resolvers are run sequentially, we can't coordinate the database calls through shared state, since one needs to return before the other even started. With root resolvers, we could handle both mutations in a single resolver and ensure an atomic transaction. One limitation would be, that both mutations can only return the same type, since the single return value from the root resolver would be used for both.
This would probably work well together with middleware #1516 too.
A workaround currently is to bundle the mutations into a single mutation such that you can create a single resolver for them. There's a nice example here https://web.archive.org/web/20220113210551/https://graphqlme.com/2018/05/13/transactions-mutations-and-graphql/
The text was updated successfully, but these errors were encountered: