I'm using Scaphold.io to build out the back end of a little app I'm working on, and have run into a problem trying to update a number of items in a single mutation request.
In Scaphold, when you create a new Type, mutations are created for common operations: create, update, and delete.
You can't redefine the schema for these mutations, or their input types. In the type of the model I'm working (card
), I get these mutations out of the box:
createCard(input: CreateCardInput!): CreateCardPayload
updateCard(input: UpdateCardInput!): UpdateCardPayload
deleteCard(input: DeleteCardInput!): DeleteCardPayload
The updateCardInput
type defines the following fields:
listId: ID
description: Text
name: String
order: Int
id: ID!
clientMutationId: String
What I can do: update a single card
With this, I know how to define a mutation that updates order
for a single card:
mutation updateCardOrder($card: UpdateCardInput!) {
updateCard(input: $card) {
changedCard {
id
order
}
}
}
Variables:
{
"card": {
"id": "Q2FyZDo4MzA=",
"order": "1"
}
}
What I want to do: update multiple cards in a single mutation
I got some pointers to use a list of cards ([card]
) as an input, but I can't figure out how to get that to work.
Ideally, something like:
mutation updateCardOrder($cards: UpdateCardInput!) {
updateCard(input: $card) {
changedCard {
id
order
}
}
}
And pass in multiple cards as a variable, for example:
{
"cards": [
{
"id": "Q2FyZDo4Mjk=",
"order": "1"
},
{
"id": "Q2FyZDo4MzA=",
"order": "2"
}
]
}
When I try this, I get an error:
{
"errors": [
{
"message": "Variable \"$cards\" of type \"[UpdateCardInput!]\" used in position expecting type \"UpdateCardInput!\".",
"locations": [
{
"line": 1,
"column": 32
},
{
"line": 2,
"column": 27
}
],
"name": "GraphQLError"
}
]
}
So… what is the right way to think about doing this in GraphQL, given that I can't change the Input Types or mutations schema in Scaphold? Is it even possible?