For Check What is GraphQL in Magento 2, Read Blog, GraphQl in Magento 2
Check the link, Get List of Orders of Customer using GraphQl Magento 2 full module
For Get List of orders of Customer by customer id, You need to create a schema file for getting a response from Query.
In above you have declared schema file for getting multiple records of order for a specific customer.
type SalesOrder @doc(description: "Sales Order graphql gather Data of specific order information") {
order_array: [String] @doc(description: "Array of order list.") }
In above order_array is used for getting an array of records but in your resolver, you made mistakes for multiple records.
In $orderCollection[] you need to pass array key for each record and you forgot to add that in your code.
You can try with,
foreach($orders as $k => $order) {
$orderCollection['order_array'][$k] = [
'increment_id' => $order->getIncrementId(),
'grand_total' => $order->getGrandTotal(),
'customer_id' => $order->getCustomerId(),
];
}
Let me know if you have any query.
According to your Shema.graphqls your mutation should look like below.
mutation {
Createpracticedata(
input:{
name: "name"
email: "email"
description: "description"
}
){
id
name
email
description
publish_date
}
}
As per your error in the post, you don't need to include PracticeOutput in your Mutation.Just pass the return attributes defined in the output.
I wrote an article about How to write grapgQl mutation to create and integrate the contact us page functionality in magento 2.3.2?.
I used graphql Mutation to implement contact us page.Please check that.
Hope this answer will help you.
Best Answer
There is already an in-built GraphQl query to retrieve customer data. You can get core Magento customer data via below query.
The above GraphQl request will return a response shown as below.
Refer the developer documents for more information. https://devdocs.magento.com/guides/v2.3/graphql/queries/customer.html
If you want to return your custom customer attributes via GraphQl, instead of writing a new query, you can enhance the existing customer GraphQl query.
'String' is the output data type when you request occupation parameter in customer query.
bin/magento setup:upgrade
rm -rf generated/
bin/magento c:f