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”
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.

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
}
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
pageLimit
previousOffsets
nextOffsets
}
}
}