Mutation mapping schema NReco.GraphQL documentation


To perform CUD (create/update/delete) actions to your DB tables as GraphQL objects mapping schema needs to be configured in the MutationObjects section:

{
  "MutationSchemaObjects": [
    {
      "Name": "Customer",
      "Table": "Customers",
      "Create": "AddCustomer",
      "Fields": [
        { "Name": "id", "Column": "CustomerID", "DataType": "string", "PrimaryKey": true },
        { "Name": "CompanyName", "DataType": "string" },
        { "Name": "ContactName", "DataType": "string" }
      ]
    }
  ]
}

Field definition

The section is an array of MutationSchema objects. Each object supports the properties listed below.

PropertyTypeDescription
Namestring (optional)Logical name of the GraphQL object. Used to compose mutation function names, the input-payload type, and variable names. If omitted, Table is used.
Createstring (optional)Name of the add mutation. Defaults to Create<Name>.
Updatestring (optional)Name of the update mutation. Defaults to Update<Name>.
Deletestring (optional)Name of the delete mutation. Defaults to Delete<Name>.
TablestringUnderlying database table mapped to this object.
Descriptionstring (optional)Object description exposed through the GraphQL schema.
FieldsarrayCollection of field definitions (see below).
Note: If the array contains at least one mutation object, a mutation section will automatically be added to the generated GraphQL schema.

Using generated mutations

Mutation GraphQL query Variables
Create
AddCustomer
mutation ($customer: MutationInputType!) {
  AddCustomer(Customer: $customer) {
    CompanyName
    ContactName
  }
}
{
  "customer": {
    "id": "cstm_001",
    "ContactName": "New Hope",
    "CompanyName": "Jedi Academy"
  }
}
Update
UpdateCustomer
mutation ($customer: MutationInputType!) {
  UpdateCustomer(Customer: $customer) {
    id
    ContactName
  }
}
{
  "customer": {
    "id": "cstm_001",
    "ContactName": "Din Grogu"
  }
}
Delete
DeleteCustomer
mutation ($customer: MutationInputType!) {
  DeleteCustomer(Customer: $customer) {
    id
  }
}
{
  "customer": {
    "id": "cstm_001"
  }
}