How to read data from a single record

In the previous post, we have saved the data into the instance of Hypi’s low code backend. Now, we need to read it to populate the user interface.

Let’s see how to read data from a single record/object.

The get function returns a single record using the hypi.id of an object.
get(type: HypiMutationType!, id: String!): HypiRootAggregate

First, we will insert data into the ReadObject data type below.

type ReadObject {
   field1: String
   field2: Int
}
  
#upsert
mutation {
  upsert(
    values: {
      ReadObject: {
        field1: "Go serverless with Hypi's low code platform"
        field2: 1
      }
    }
  ) {
    id
  }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FGV16MCMRRKCYQHTE95SVYXC"
      }
    ]
  }
}

Above mutation returned hypi.id of the created ReadObject. We can use the same hypi.id to read data from the fields of the object. We will use the get function to retrieve the record.

Sample Query

{
  get(type: ReadObject, id: "01FGV16MCMRRKCYQHTE95SVYXC"){
    ... on ReadObject {
      hypi{
        id
        created
        updated
      }
      field1
      field2
    }
  }
}
#result
{
  "data": {
    "get": {
      "hypi": {
        "id": "01FGV16MCMRRKCYQHTE95SVYXC",
        "created": "2021-09-30T09:40:08Z",
        "updated": "2021-09-30T09:40:08Z"
      },
      "field1": "Go serverless with Hypi's low code platform",
      "field2": 1
    }
  }
}

Output

get query returns only the data from the fields you define within the query. In the above query, data from the hypi object, field1 and field2 have been returned.

Query with Variables

query GetSingleRecord($type: HypiMutationType!, $hypiid: String!) {
  get(type: $type, id: $hypiid) {
    ... on ReadObject {
      hypi {
        id
        created
        updated
      }
      field1
      field2
    }
  }
}

#query variable  

{
  "type": "ReadObject",
  "hypiid": "01FGV16MCMRRKCYQHTE95SVYXC"
}

Please note query variables has the form of JSON.
Check the POSTMAN collection for the get 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