简体   繁体   中英

how to pass graphql list to mutation in apollo in react js

I have a mutation like this:

orderAdd(products: [ProductInput],restaurant: RestaurantInput)

in graphql and i want to pass parameter to it in Apollo in react js like this:

 mutation orderAdd ($products: [ProductInput]!, $restaurant: RestaurantInput!)
{
    orderAdd(products: $products, restaurant: $restaurant)
      {
        errors
        order {
          id
          createdAt
          products {
            id
            name
            price
            quantity
            totalPrice
          }
          rate {
            speed
            service
            flavor
          }
       }
    }
  }
;

but it does not work i think the problem with graphql list because the parameter products is type of products: { type: new GraphQLList(productInputType) } , please can you tell me how to pass graphql list to mutation in apollo ?

You can pass list in mutation like this

 orderAdd(products: [{ProductInput1},{ProductInput2}],restaurant: RestaurantInput){.. } 

Hope, this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM