How to create a link between two objects by using `hypi.id`

We’ve seen how to save data by creating an object.
Let’s check how to use hypi.id to create a link between two objects!

Look at the following schema.

type OldObject {
    field1: String 
}

type NewObject {
    fld1: String
    fld2: OldObject
    fld3: [OldObject]
}

NewObject holds the references for OldObject. We’ll see how to create the reference/link between these two objects.

Create two objects of type OldObject.

mutation {
  upsert(
    values: {
      OldObject: [
        { field1: "Hypi's Low code Platform!" }
        { field1: "Hypi easy to use backend-as-a-service" }
      ]
    }
  ) {
    id
  }
}
#Result
{
  "data": {
    "upsert": [
      {
        "id": "01FGP82JAW51DW7CFPG1CB5YFN"
      },
      {
        "id": "01FGP82JAXFFYMGHZXP0JJ9CRM"
      }
    ]
  }
}

Use the hypi.id of the generated objects to create an object of type NewObject.

mutation {
  upsert(
    values: {
      NewObject: [
        {
          fld1: "Create link between two objects"
          fld2: { hypi: { id: "01FGP82JAW51DW7CFPG1CB5YFN" } }
          fld3: [
            { hypi: { id: "01FGP82JAW51DW7CFPG1CB5YFN" } }
            { hypi: { id: "01FGP82JAXFFYMGHZXP0JJ9CRM" } }
          ]
        }
      ]
    }
  ) {
    id
  }
}
#Result
{
  "data": {
    "upsert": [
      {
        "id": "01FGP9M76KJ0RP1B28AMGW0Z2T"
      }
    ]
  }
}

Let’s retrieve the data inside the newly created object.

{
  get(type: NewObject, id: "01FGP9M76KJ0RP1B28AMGW0Z2T") {
    ... on NewObject {
      fld1
      fld2 {
        field1
      }
      fld3 {
        field1
      }
    }
  }
}
{
  "data": {
    "get": {
      "fld1": "Create link between two objects",
      "fld2": {
        "field1": "Hypi's Low code Platform!"
      },
      "fld3": [
        {
          "field1": "Hypi's Low code Platform!"
        },
        {
          "field1": "Hypi easy to use backend-as-a-service"
        }
      ]
    }
  }
}

You can see that values of the fields from OldObject type objects get reflected in the fields of NewObject.

Thus, you may use hypi.id as demonstrated above to create a link/reference between objects!

Check the POSTMAN collection for the link/reference creation using hypi.id 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