Closed mvanalphen closed 2 years ago
Agree that this is unexpected.
We just released the first alpha of the upcoming federation 2.0 that, amongst other things, fix this particular issue (through 9cd5c07b2b9baa0371e0ffaa2fc83b5628e9e8cb and db5b3b4abdbe81e410b0812befe4dbf9ef7f0001). Tests demonstrating this is now working can be found here.
I'm afraid fixing this on prior versions is a bit involved and this will likely remain a "known" limitation on those versions.
As described here, it is possible to return the
Query
type in a mutation payload. This allows a user to execute a query after the completion of a mutation, which is then returned with the original mutation response.Mutation query example
For instance, take the following Mutation defined in a hypothetical federated
order-graphql
application (of course running behind a Apollo GraphQL Gateway):The mutation resolver looks like this:
Now, let's run the following mutation:
This works perfectly. The mutation is executed, and the
order
query (also defined in theorder-graphql
) is executed and returns the new order status or any other data theorder
query is able to return.What doesn't work
What does not work, however, if we try to run a query in the mutation that is not defined in the
order-graphql
, but in a completely different federated GraphQL instance. For instance, thestore
query which is defined in a federatedstore-graphql
application:This returns the following error:
Cannot query field "store" on type "Query"
. The execution fails with a400 Bad Request
.However, if we run an introspection:
The
store
query is returned:Expected behaviour
Because both the
order-graphl
andstore-graphl
applications are running in the federation behind a gateway, I'd expect to be able to run any query from a mutation when returning aQuery
object.I'd love to hear if there's any ways around this and if my assumptions are correct that this should work.