I'm wondering if there's a way in GraphiQL that will let me pipe the result from one query / mutation into another query / mutation. Here's an example where the login
mutation is used to get a viewer
and the viewer
would be used to query the addresses
for that user. Is this possible with GraphQL / GraphiQL.
mutation {
login(credentials: {
email: "[email protected]",
password: "password123",
passwordConfirmation: "password123"
}) {
viewer
}
}
query {
addresses(viewer:viewer) {
city
}
}
The purpose of the selection set in the mutations is to be able to fetch data that has changed as a result of the mutation. But it also makes it possible to fetch related data, as long as you can access is through the mutation result type.
Let's assume we have following types:
type Address {
city: String
}
type User {
addresses: [Address]
}
If the result (payload) type of the login
mutation includes a field viewer
of type User
that refers to the successfully logged in user, you can query any field of the User
in the result of the mutation:
mutation {
login(credentials: {
email: "[email protected]",
password: "password123",
passwordConfirmation: "password123"
}) {
viewer {
addresses {
city
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With