apollo - How do you pass a list or array of objects into a GraphQL mutation designed to update a single object? -


i'm using scaphold.io build out end of little app i'm working on, , have run problem trying update number of items in single mutation request.

in scaphold, when create new type, mutations created common operations: create, update, , delete.

you can't redefine schema these mutations, or input types. in type of model i'm working (card), these mutations out of box:

createcard(input: createcardinput!): createcardpayload  updatecard(input: updatecardinput!): updatecardpayload  deletecard(input: deletecardinput!): deletecardpayload 

the updatecardinput type defines following fields:

listid: id description: text name: string order: int id: id! clientmutationid: string 

what can do: update single card

with this, know how define mutation updates order single card:

mutation updatecardorder($card: updatecardinput!) {   updatecard(input: $card) {     changedcard {       id       order     }   } } 

variables:

{   "card": {     "id": "q2fyzdo4mza=",     "order": "1"   } } 

what want do: update multiple cards in single mutation

i got pointers use list of cards ([card]) input, can't figure out how work.

ideally, like:

mutation updatecardorder($cards: updatecardinput!) {   updatecard(input: $card) {     changedcard {       id       order     }   } } 

and pass in multiple cards variable, example:

{   "cards": [     {       "id": "q2fyzdo4mjk=",       "order": "1"     },     {       "id": "q2fyzdo4mza=",       "order": "2"     }   ] } 

when try this, 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… right way think doing in graphql, given can't change input types or mutations schema in scaphold? possible?

since want run multiple mutations in single request, can use graphql aliases accomplish that. more information here: https://github.com/mugli/learning-graphql/blob/master/3.%20querying%20with%20field%20aliases%20and%20fragments.md

essentially, can run mutation this:

mutation updatecardorder($card1: updatecardinput!, $card2: updatecardinput!, $card3: updatecardinput!) {   update1: updatecard(input: $card1) {     changedcard {       id       order     }   }   update2: updatecard(input: $card2) {     changedcard {       id       order     }   }   update3: updatecard(input: $card3) {     changedcard {       id       order     }   } } 

and variables this:

{   "card1": {     "id": "q2fyzdo4mjk=",     "order": "1"   },   "card2": {     "id": "q2fyzdo4mza=",     "order": "2"   },   "card3": {     "id": "q2fyzdo4mza=",     "order": "3"   } } 

hope helps!


Comments

Popular posts from this blog

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -