As you need to include a query
inside of your mutation to get the internal cache to update after a mutation I have now come across a situation where I
have a query
with a function
that accepts variables
. I cannot find a way to include this query inside the mutation.
I thought I may need to pass all variables inside the mutation including those that are needed for the query, but this makes no sense.
Works correctly, this will redraw once the mutation has finished
export const GET_PICK_TICKETS = gql`
{
allPickTickets {
edges {
node {
id
createdBy
createdAt
status
}
}
}
}
`
export const MARK_PICK_TICKET_COMPELTE = gql`
mutation markPickTicketAsCompleted($id: Int!) {
updatePickTicketById(input: { id: $id, pickTicketPatch: { status: "PICKED" } }) {
clientMutationId
query ${GET_PICK_TICKETS}
}
}
`
Does not work
When using a query function it will fail
mutation updateMemberTaskById($id: Int!, $startedAt: Datetime!) {
updateMemberTaskById(input: { id: $id, memberTaskPatch: { startedAt: $startedAt, status: "STARTED" } }) {
clientMutationId
query getLocationSet($locationSetId: Int!, $internalId: Int, $jobcardIds: [String!]) {
locationSet: locationSetById(id: $locationSetId) {
id
set: setBySetId {
id
name
}
}
}
}
}
* please ignore that the variables are not being used in the query.
error produced from graphql formatter:
Syntax error while parsing GraphQL query. Invalid input ""STARTED" } }) {\n clientMutationId\n query getLocationSet($", expected Argument, SelectionSet, Value, Directives or ObjectField (line 2, column 94):
updateMemberTaskById(input: { id: $id, memberTaskPatch: { startedAt: $startedAt, status: "STARTED" } }) {
^
Maybe I do not need to do a query, but according to this answer I do.