How to update data saved in an object

We know how to save data by creating an object. But, we need to update the saved data sometimes.

Let’s see how to update data saved in an object.

upsert function also does the job of updating data in an object. We need to pass on the hypi.id of the created object to update it.

upsert (values: HypiUpsertUnion!) : [Hypi!] !

First we will insert data into the UpdateObject data type below.

type UpdateObject {
   field1: String
}  
#create object
mutation {
  upsert(values: { UpdateObject: [{ field1: "Low code No code" }] }) {
    id
  }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FGS6C1M4ZNHNAMJJZ87DD101"
      }
    ]
  }
}

Above mutation returned hypi.id of the created UpdateObject. We can use the same hypi.id to update the fields of the object. Specifying hypi.id simply tells to update the specified field of an existing object rather than creating a new object.

Let’s update the field1 of the created object.

Sample Query

mutation {
  upsert(
    values: {
      UpdateObject: [
        {
          hypi: { id: "01FGS6C1M4ZNHNAMJJZ87DD101" }
          field1: "Hypi's low code platform"
        }
      ]
    }
  ) {
    id
  }
}
{
  "data": {
    "upsert": [
      {
        "id": "01FGS6C1M4ZNHNAMJJZ87DD101"
      }
    ]
  }
}

Output

Check the new value of field1 from UpdateObject after the update request.

{
  get(type: UpdateObject, id: "01FGS6C1M4ZNHNAMJJZ87DD101") {
    ... on UpdateObject {
      field1
    }
  }
}
#result
{
  "data": {
    "get": {
      "field1": "Hypi's low code platform"
    }
  }
}

Query with Variables

  mutation Upsert($values: HypiUpsertInputUnion!) {
    upsert(values: $values) {
      id
    }
  }
{
  "values": {
      "UpdateObject": [
        {
          "hypi": { "id": "01FGS6C1M4ZNHNAMJJZ87DD101" },
          "field1": "Hypi's low code platform"
        }
     ]
  }
}

Please note “values” data has the form of JSON.

Check the POSTMAN collection for the update requests in different programming languages! Click </> and choose the programming language of your choice.
Don’t forget to insert your own Authorization key and Hypi Domain under Headers to test the results!

Run in Postman