graphql-request
graphql-request copied to clipboard
Destructuring mutation response
With GraphQL mutations, the data object which comes back is then wrapped in the name of my mutation createItemInDatabase.
client:
const mutation = (`
mutation createNewItem($title: String!) {
createItemInDatabase(title: $title) {
name
description
}
}
`);
request(url, mutation).then(({ createItemInDatabase }) => console.log(createItemInDatabase));
apollo-micro-server:
type Mutation {
createItemInDatabase(
title: String!
): Item
}
Is there someway to get the name of the mutation in javascript rather than relying on matching what is essentially part of the substring?
(I'm using 2.0.0 btw)
Hi @tettoffensive I'm not part of the graphql-request team, but I believe the behaviour you're seeing is part of the GraphQL spec and not necessarily specific to graphql-request.
Closing this, as this is expected behavior. The data structure is supposed to match the query you provide.