Skip to main content

Read Data

Read the inserted data by using query functions. get and find are the two functions that return the data. If you need a single record, use the get function. For getting multiple records, use the find function.

Get

The get function returns a single record using the ‘id’ of an object. You may use the ‘id’ received after creating the record. The magic hypi object also contains the ‘id’ of the object (hypi.id).

get(type: HypiMutationType!, id: String!): HypiRootAggregate

Let’s pass the Author data type as an argument to fetch the data. Get the records in the fields like name, booklist, hypi id, created date, updated date. You can get titles and availability of books from the array booklist. You may use the fields from which you want to fetch the data.

{
get(type: Author, id: "01F0DVHM26HHWS8X8X3NBRSAV6"){
... on Author {
hypi{
id
created
updated
}
name
booklist{
title
available
}
}
}
}

Find

The second approach to getting data out of an instance is by using thefind  function. Unlike the get function, this returns a list of objects matching the arcql filter provided.

find(
type: HypiMutationType!
arcql: String!
first: Int
after: String
last: Int
before: String
includeTrashed: Boolean
): HypiFilterConnection!

This function has many parameters. Let’s look at this table to understand them.

ParameterDescriptionExample
typeThe type (table) to find data fromMessage, Author
arcqlQuery to filter the dataarcql: "hypi.id= '01F0FW9XYQWQNNEDYV3S5P2WGQ'"
firstLimit the number of records in the results. Used with the ‘after’ parameter.12
afterReturn records after an object with this ID“01F0FW9XYQWQNNEDYV3S5P2WGQ”
lastLimit the number of records in the results. Used with the ‘before’ parameter.6
beforeReturn records before an object with this ID“01F0FW9XYQWQNNEDYV3S5P2WGQ”
pageThe page number to be returned3
includeTrashedDisplay Trashed objects in the record. ‘false’ by defaultFalse
  • ‘first’ and ‘after’ parameters work together. ‘last’ and ‘before’ work together.

  • ‘first’ and ‘last’ are the limits i.e. the max results to return (up to 25)

  • ‘before’ and ‘after’ are the ID of objects to return results before or after.

  • If ‘before’ is set, then results matching the arcql query are returned before this id

  • If ‘after’ is set, then results matching the arcql query are returned after this id

  • ‘includeTrashed’ is false by default. ‘find’ does not return the objects which were trashed using the ‘trash’ function. But if you set this parameter to true or use the untrash method then ‘find’ returns those objects.

  • 'page' number works with the first parameter. If this parameter is specified, then the records get divided into pages. Each page has the number of rows specified by the first parameter.

Let’s check the below example. Records from an Author object are received using the find function. Records of Hypi IDs, updated date, name of the authors, and count of books are returned.

{  
find (
type: Author,
arcql: "hypi.id = '01F0DVHM2AZCGM0JSR9QRNBWZY'"
)
{
edges {
cursor
node {
... on Author {
hypi {
id
updated
}
name
count
}
}
}
}
}

Pagination

Let's see how the pagination works while retrieving the records. A page has a specific number of rows (first). The total number of records get divided by the number of rows to get the number of pages. If the page parameter has the value of n (integer), the nth page gets displayed in the result of the find function.

Suppose the book object has the following records. The after parameter has the hypi.id value of the book alchemist. The pagination starts after the Alchemist record. Let's say each page has two books (first parameter). So, the remaining records after Alchemist get divided into two records each. The table shows the page number of each record.

BookPage No
The Last Symbol-
Alchemist ( after Parameter)-
In the wonderland of Investment1
Ikigai1
Outlook2
Blink2
History of nearly everything3
Sapiens3
Hamlet4
Merchant of Venice4
note

page parameter doesn't work with the before parameter.

Let's retrieve page 3 after the alchemist record. Here is the query.

{
find(type: Book, arcql: "*", first: 2, after:"01F6EFAYAX79ZG3Q13WGXKDAR5", page:3) {
edges {
node {
... on Book {
title

}
}
cursor
}
}
}

If the after parameter has not been specified, the pagination begins from the first record.