Hello Friends,

In this blog we will learn about How to Pass Multi-Dimensional Array as an Argument in GraphQL in Magento 2.

Magento 2’s GraphQL functionality offers a powerful way to interact with your store’s data. But what if you need to pass complex information, like a multi-dimensional array, as an argument in your GraphQL queries? One of the common challenges developers face is passing multi-dimensional arrays as arguments in GraphQL queries or mutations.

In this blog post, we’ll explore how to pass multi-dimensional arrays in GraphQL with Magento 2.

Steps to Pass Multi-Dimensional Array as an Argument in GraphQL in Magento 2:

Step 1: First, we need to create a schema.graphql file inside our extension at the following path

app\code\Vendor\Extension\etc\schema.graphqls

Then add the code as follows

Step 2: Now, we need to create a Setdata.php file inside our extension at the following path

app\code\Vendor\Extension\Model\Resolver\Setdata.php

Then add the code as given below

You need to call above API as per below parameters.

Conclusion

By following these steps, you’ll be well-equipped to handle multi-dimensional arrays with confidence in your Magento 2 GraphQL queries.

Related Article – Magento 2: How to Pass Multi-Dimensional Array as an Argument in REST API

Share the solution with your friends and stay in touch with us for more.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]