---
title: "Magento 2: How to Pass Multi-Dimensional Array as an Argument in GraphQL"
url: "https://magecomp.com/blog/magento-2-pass-multi-dimensional-array-as-argument-in-graphql/"
date: "2024-06-07T13:56:32+00:00"
modified: "2025-02-12T09:57:40+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 366
reading_time: "2 min read"
summary: "Hello Friends,"
description: "Learn how to pass multi-dimensional arrays as arguments in GraphQL with Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Effective ways to Improve Your SEO Rankings with these Quick DIY Tips in 2026"
    url: "https://magecomp.com/blog/effective-ways-improve-seo-rankings-in-2019/"
  - title: "How to Add Custom Column for New Order Select Product Grid in Magento 2?"
    url: "https://magecomp.com/blog/add-custom-column-for-new-order-select-product-grid-magento-2/"
  - title: "Magento 2: How to Open Popup on Button Click in Admin"
    url: "https://magecomp.com/blog/magento-2-open-popup-on-button-click-in-admin/"
---

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

_Published: June 7, 2024_  
_Author: Dhiren Vasoya_  

![Magento 2: How to Pass Multi-Dimensional Array as an Argument in GraphQL](https://magecomp.com/blog/wp-content/uploads/2024/06/Magento-2-Blog-Title-Magento-2-How-to-Pass-Multi-Dimensional-Array-as-an-Argument-in-GraphQL-1024x512.webp)

**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.
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

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
```
input OrderInput {
  orderId: String!
  comment: String!
}

type Mutation {
    setFormData (
        orderarray: [OrderInput!]!
    ): setData @resolver(class: "Vendor\Extension\Model\Resolver\Setdata")

}

type setData {
    status: Boolean
    message: String
}
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-2.webp)](https://magecomp.com/magento-malware-removal.html)

**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
```
<?php

namespace VendorExtensionModelResolver;

use MagentoFrameworkGraphQlConfigElementField;
use MagentoFrameworkGraphQlExceptionGraphQlAuthenticationException;
use MagentoFrameworkGraphQlExceptionGraphQlInputException;
use MagentoFrameworkGraphQlQueryResolverInterface;
use MagentoFrameworkGraphQlSchemaTypeResolveInfo;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoFrameworkMailTemplateSenderResolverInterface;

class Setdata implements ResolverInterface
{

   public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {

       $data = [];
       $Ordervalue = $this->setOrderdata($args['orderarray']);
       $data = ["status"=>true, "message"=> "passes data successfully."];
       return [$data];

    }

    public function setOrderdata($orderarray){
    	 $requestData = json_decode(file_get_contents('php://input'), true);
        $Ordervalue = $requestData['orderarray'];
    	return $Ordervalue;

    }
}
```

You need to call above API as per below parameters.

```
{
    "orderarray": [
        {orderId: "1", comment: "test order"},
        {orderId: "2", comment: "demo order"}
    ]
}
```

## Conclusion
By following these steps, you’ll be well-equipped to handle multi-dimensional arrays with confidence in your Magento 2 GraphQL queries.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

Related Article – [**Magento 2: How to Pass Multi-Dimensional Array as an Argument in REST API**](https://magecomp.com/blog/magento-2-pass-multi-dimensional-array-as-argument-in-rest-api/)

Share the solution with your friends and stay in touch with us for more.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/magento-2-pass-multi-dimensional-array-as-argument-in-graphql/](https://magecomp.com/blog/magento-2-pass-multi-dimensional-array-as-argument-in-graphql/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 11:54:00 UTC_  
