0

I am trying to load in graphql product details. I am only managing to get the details of one product $json['Transaction']['OrderItems'][0] but I would like to get the values for all the products which are in $json['Transaction']['OrderItems']. In resolver I have:

return [
        'cart' => [
            'products' => [
                'sku' => $json['Transaction']['OrderItems'][0]['ItemCode'],
                'quantity' => $json['Transaction']['OrderItems'][0]['ItemQuantity'],
                'price' => $json['Transaction']['OrderItems'][0]['ItemQuantity']
            ],
]

in schema.graphqls I have:

type AddProductsToCartOutput {
products: ITEMS
}


type ITEMS {
sku: String!
quantity: Float!
price: Float!
}

in the request:

   cart {
  
products {
    sku
    quantity
    price
}
}

and in the output I am getting:

"cart": {
    "products": {
      "sku": "33150220000",
      "quantity": 5,
      "price": 5
    },
 }

But I need to show all the items!

1 Answer 1

0

In order to pass multiple items data to graphql output you will have to define the ITEMS as array in your schema.graphqls

Try changing with below code

type AddProductsToCartOutput {
    products: [ITEMS]
}

Thanks!

3
  • thank you but how do i show afterwards all the products? 'sku' =>? Jul 28, 2022 at 7:24
  • You will have to loop through the data you are having in the resolver and pass all the products data array in the resolver. Above query will return array of products objects. Jul 28, 2022 at 9:18
  • in my resolver i have return [ 'cart' => [ 'products' => [ 'sku' => $json['Transaction']['OrderItems'][0]['ItemCode'], 'quantity' => $json['Transaction']['OrderItems'][0]['ItemQuantity'], 'price' => $json['Transaction']['OrderItems'][0]['ItemQuantity'] ], ] what should i change there? could you help me? Jul 28, 2022 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.