Update operations

API documentation detailing update operations using GraphQL. Highlights use of filter/value pairs and filters/values pairs, with examples.

Update operations are available through a field having the name of the form <tablename>_update of a type having the name of the form <parenttype>_<tablename>_Result. For instance, for the Associate table, the field is called associate_update and its type is Mutation_UseCompany_Associate_Result. The result type is the same for inserts, updates, and deletes.

The form of this operation is the following:

associate_update(
   filter: FilterExpression_Associate
   value: Associate_Input
   filters: [FilterExpression_Associate]
   values: [Associate_Input!]
): Mutation_UseCompany_Associate_Result

The <tablename>_update field has two pairs arguments, that you must use together. The first pair is:

  • An argument called filter which defines the selection filter for the records to be updated. The type of this argument is the same used for filters in queries and will be described in details later in the document.
  • An argument value which is an object of type <tablename>_Input. For instance, for the Associate table, the input type is Associate_Input. This is the same input type used for insert operations for tables with a single primary key column. For tables with more than one primary key columns, it’s a type slightly different than the one used for inserting, none of the primary key columns being available for updating.

You can use this if you want to update all records matching the filter with the same values. If you want to update each (or different) record with a different value, you must use the second pair of arguments:

  • An argument called filters which is a list of filters, one for each record to be updated. The type of the elements of filters is the same used as the type of `filter.
  • An argument called values which is a list of objects of type <tablename>_Input.

Note

The filter \ value pair is considered deprecated and will be removed in the future. You should use the filters \ values pair instead.

An update operation has the following form (in this example, we set the languageNo field to 44 for all associates that have the associateNo field greater than 546):

Query

mutation update_lang($cid : Int!)
{
  useCompany(no:$cid)
  {
    associate_update(
      filter : {associateNo : {_gt : 546}},
      value:{languageNo:44})
    {
      affectedRows
      items
      {
        associateNo
        customerNo
        name
        shortName
        languageNo
      }
    }
  }
}
Result

{
  "data": {
    "useCompany": {
      "associate_update": {
        "affectedRows": 2,
        "items": [
          {
            "associateNo": 547,
            "customerNo": 30101,
            "name": "Erik Larson",
            "shortName": "Erik",
            "languageNo": 44
          },
          {
            "associateNo": 548,
            "customerNo": 30102,
            "name": "Frida Olson",
            "shortName": "Frida",
            "languageNo": 44
          }
        ]
      }
    }
  }
}

You can collect multiple edits in a single update operation. You can do that with the use of filters and values. The following examples shows how to update multiple lines of an order with the different values. One filter and one value are provided for each line:

mutation multi_order_line_update($cid : Int!, $ono : Int!)
{
  useCompany(no : $cid)
  {
    orderLine_update(
      filters: [
        # filter for line 1
        {_and:[
            {orderNo : {_eq : $ono}}
            {lineNo : {_eq : 1}}]},
        # filter for line 2
        {_and:[
            {orderNo : {_eq : $ono}}
            {lineNo : {_eq : 2}}]}
      ]
      values: [
        # value for line 1
        {
          priceInCurrency : 199.99,
          invoiceNow : 1.0
        },
        # value for line 2
        {
          priceInCurrency : 59.99,
          invoiceNow : 1.0
        },
      ])
    {
      affectedRows
      items
      {
        orderNo
        lineNo
        quantity
        priceInCurrency
        invoiceNow
      }
    }
  }
}

You can transform any query using filter and value into a query using filters and values. An example is the following query:

filter & value

mutation update_lang($cid : Int!)
{
  useCompany(no:$cid)
  {
    associate_update(
      filter : {associateNo : {_gt : 546}},
      value:{languageNo:44})
    {
      affectedRows
      items
      {
        associateNo
        customerNo
        name
        shortName
        languageNo
      }
    }
  }
}
filters & values

mutation update_lang($cid : Int!)
{
  useCompany(no:$cid)
  {
    associate_update(
      filters : [{associateNo : {_gt : 546}}],
      values: [{languageNo:44}] )
    {
      affectedRows
      items
      {
        associateNo
        customerNo
        name
        shortName
        languageNo
      }
    }
  }
}
Last modified September 24, 2024