Customise GraphQLAdaptor for DataManager with Grid

Hi,

I am following this example in your documentation regarding using GraphQL + Grid to do CRUD operations.

https://ej2.syncfusion.com/react/documentation/data/adaptors#performing-crud-action-with-graphqladaptor

I have a problem with the below query: - $datamanager variable.

 query: `query getOrders($datamanager: String) {
getOrders(datamanager: $datamanager) {
count,
getOrders{OrderID, CustomerID, EmployeeID, ShipCity, ShipCountry}
}

As I understand, $datamanager is a parameter passed by the Grid which contains sorting, filtering, paging etc which is used to fetch and update the data in grid. However, my GraphQL backend does not understand this "datamanager" parameter. I have for example the below in my backend.


getOrders(where:String, pageNumber:Int, pageSize:Int, order:String){  
  count,
  getOrders{OrderID,CustomerID,EmployeeID,ShipCity,ShipCountry}
}

My question is, before grid calls the query, can I get access to $datamanager so I can dynamically create the query? so I can do:-



const where= $datamanager.Where;
const pageSize = $datamanager.Take;
// other params

return`query getOrders($where: ${where}, $pageSize: ${pageSize}) {
getOrders(where: $where, pageSize: $pageSize) {
count,
getOrders{OrderID, CustomerID, EmployeeID, ShipCity, ShipCountry}
}


I have a similar requirement for the mutation.

    getMutation: function (action): string {
if (action === 'insert') {
return `mutation CreateOrderMutation($value: OrderInput!){
createOrder(value: $value){
OrderID, CustomerID, EmployeeID, ShipCity, ShipCountry
}}`;
}
// more actions
}

How can I get access to the $value property? As I understand, the $value contains the data from the entire row I am going to insert. However, in my case, some properties(columns) are read-only and should not be sent to the GraphQL server. How can I do this for both insert and update cases?


I hope there is a way to change the syncfusion control otherwise we will need to make backend changes to specifically understand the DataManager interface which is not ideal.


1 Reply

DM Dineshnarasimman Muthu Syncfusion Team November 21, 2023 04:42 PM UTC

Hi Mohammad Kaif Ul Majed,


Greetings from Syncfusion Support.


We have reviewed you query about accessing the $datamanager parameter while using GraphQL adaptor in grid. We suggest you to access the parameter in the server side inside the getOrders() method and you can perform operation. We have attached the image and sample with GraphQL adaptor for your reference.


Image for reference:

Accessing the datamanager parameter in the server-side


 Accessing the value parameter during CRUD operation in server-side


Result in the terminal 


Please let us know if you need any further assistance.


Regards,

Dineshnarasimman M


Attachment: GraphQLSample_dccbd896.zip

Loader.
Up arrow icon