GraphQL Guides

After creating an API on ZettaBlock, you can query it using GraphQL.

Simple examples

You can query for a single record.

{
  record(data_creation_date: "2021-03-01") {
    data_creation_date
  }
}

Query all records. By default we return 1000 items:

{
  records {
    data_creation_date
  }
}

This is equivalent to:

{
  records(limit: 1000) {
		data_creation_date
  }
}

For querying records, we support the following operations:

Filtering

You can use the filter parameter in your queries to filter by different properties. You can filter on multiple values within the filter parameter.

Example using filter

You can use eq, not, min, max, in operators in the filters:

{
  records(filter: { data_creation_date: {
    eq: "2015-07-30"
  }}) {
    data_creation_date
  }
}

For convenience, if you only need a eq filter, you can use the following shorthand. The previous example is equivalent to the following query:

{
  records(data_creation_date: "2015-07-30" }) {
    data_creation_date
  }
}

Example using not filter

{
  records(filter: { data_creation_date: {
    not: "2015-07-30"
  }}) {
    data_creation_date
  }
}

Example using min and max filters

{
  records(filter: { data_creation_date: {
    min: "2015-07-30"
    max: "2022-03-10"
  }}) {
    data_creation_date
  }
}

Example using in filter

{
  records(filter: { data_creation_date: {
    in: ["2015-07-30", "2022-03-10"]
  }}) {
    data_creation_date
  }
}

Sorting

When querying a collection, the orderBy parameter can be used to sort records by a specific attribute. Additionally, the orderDirection can be used to specify the sort direction - asc for ascending anddesc for descending. By default, the orderDirection is set to asc.

Example

{
  records(orderBy: data_creation_date) {
    data_creation_date
  }
}

This is equivalent to:

{
  records(orderBy: data_creation_date, orderDirection: asc) {
    data_creation_date
  }
}

Pagination

When querying a collection, the limit parameter can be used to limit records.

Further, the skip parameter can be used to skip entities and paginate. e.g. limit:100 shows the first 100 entities and limit:100, skip:100 shows the next 100 entities.

Example using limit and skip

Query 10 records , offset by 10 places from the records:

{
  records(first: 10, skip: 10 orderBy: data_creation_date) {
    data_creation_date
  }
}

Variables

You can specify your own arguments and pass them along with their queries to customize the data they receive, for more detail can check https://graphql.org/learn/queries/#variables

Example:

// https://app.zettablock.com/community/apis/sq_e84d0a335e384d92843c1f2066981e17/playground

// Query:
query nftTransfers(
  $symbol: String!
) {
  records(
    symbol: $symbol,
    limit: 1000
  ) {
    symbol
    decimals
    contract_address
  }
}

// Parameters
{
  "symbol": "coco"
}