Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GraphQL references and handle redirects for id/link changes #215

Merged
merged 7 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,88 @@ id: overview
title: Overview
---

# Overview
# GraphQL API Overview

To query the state of a Cartesi Rollups instance, frontend clients can make use of a GraphQL API that is exposed by the Cartesi Nodes.
The Cartesi Rollups GraphQL API provides a powerful interface for querying the state of a Cartesi Rollups instance. This API allows frontend clients to retrieve detailed information about inputs processed by the rollup and the outputs produced by the dApp's backend in response to these inputs.

This API allows any client to retrieve outputs produced by a dApp's backend, and to link those outputs to the corresponding inputs that triggered them. Outputs can generally come in the form of vouchers, notices and reports, and allow clients to both receive dApp updates and enforce consequences on the base layer.
The API primarily deals with four main types of entities:

The Cartesi Rollups state query API is fully specified by its GraphQL schema.
1. [Inputs](./queries/inputs.md): Requests submitted to the application to advance its state.
2. [Notices](./queries/notices.md): Informational statements that can be validated in the base layer blockchain.
3. [Vouchers](./queries/vouchers.md): Representations of transactions that can be carried out on the base layer blockchain.
4. [Reports](./queries/reports.md): Application logs or diagnostic information.

This specification is displayed in a more accessible and navigable way in the next sections.

Some key features of the GraphQL API include the ability to:

## Queries
- Retrieve detailed information about individual inputs, notices, vouchers, and reports.
- List and paginate through collections of these entities.
- Access proof data for notices and vouchers, allowing for validation on the base layer.
- Filter and sort results based on various criteria.

A number of top-level queries are available in order to retrieve rollup information for a Cartesi dApp.
## Basic Query Structure

In GraphQL, submitting a query involves defining parameters for filtering the entries to retrieve, and also specifying the data fields of interest, which can span any objects linked to the entry being retrieved.
GraphQL queries in the Cartesi Rollups API typically involve specifying:

For example, the following query retrieves the number of the base layer block in which the [input](./objects/input.mdx) was recorded:
1. The type of entity you're querying (input, notice, voucher, or report).
2. Any necessary arguments (e.g., index values, pagination parameters).
3. The fields you want to retrieve from the entity.

```
input(index: "1") {
blockNumber
}
```

You can submit the query above as an HTTP POST request, specifying the Content-Type as `application/json`. For instance, using `curl` you could submit it as follows:

```
curl 'https://<graphql_url>' -H 'Content-Type: application/json' -d '{"query":"{ input(index:1) {blockNumber} }"}'
```

The response of which would be something like this:
Here's a basic example of querying an input:

```
{
"data": {
"input": {
"blockNumber": 8629116
}
```graphql
query {
input(index: 1) {
index
status
timestamp
msgSender
payload
}
}
```

You can also retrieve linked information from the input. For example, the following query would retrieve notices from this particular input with support for pagination and with total number of entries that match the query:
## Pagination

```
input(index: "1") {
notices {
totalCount
}
}
```
The API uses cursor-based pagination for queries that return collections of entities (e.g., listing all notices). This is implemented through connection types (e.g.,[`InputConnection`](./objects/input-connection.md), [`NoticeConnection`](./objects/notice-connection.md)) that include `edges` and `pageInfo` fields.

The response of which would be something like this:
Example of a paginated query:

```
{
"data": {
"input": {
"notices": {
"totalCount": 6
```graphql
query {
notices(first: 5, after: "cursor_value") {
edges {
node {
index
payload
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
```

## Response format
## Response Format

As exemplified above, GraphQL query responses are given in JSON format. In practice, a query might result in some data and some errors, and as such the specification of the returned JSON object is actually of the following form:
API responses are in JSON format and typically have the following structure:

```
```json
{
"data": { ... },
"errors": [ ... ]
"data": {
// Requested data here
},
"errors": [
// Any errors encountered during query execution
]
}
```


## GraphQL Playground

The [GraphQL Playground](https://github.com/graphql/graphql-playground) is a graphical, interactive, in-browser GraphQL IDE. It is a tool that can be used to explore the contents of a GraphQL server, and as such can be used to navigate the inputs and outputs of a Cartesi Rollups dApp.

For local development, the interactive playground is accessible at [http://localhost:8080/graphql](http://localhost:8080/graphql).
You can use the GraphQL Playground, an interactive in-browser IDE, to test and explore the API. For local development, it's typically accessible at `http://localhost:8080/graphql`.


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
id: input-filter
title: InputFilter
hide_table_of_contents: false
---


Filter object to restrict results depending on input properties

```graphql
input InputFilter {
indexLowerThan: Int
indexGreaterThan: Int
}
```


## Fields

| Name | Type | Description |
| ---- |------| ------|
| `indexLowerThan` | [`Int`](../../scalars/int) | Filter only inputs with index lower than a given value |
| `indexGreaterThan` | [`Int`](../../scalars/int) | Filter only inputs with index greater than a given value |


This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: completion-status
title: CompletionStatus
hide_table_of_contents: false
---

Enum representing the possible statuses of an input's processing.

```graphql
enum CompletionStatus {
Unprocessed
Accepted
Rejected
Exception
MachineHalted
CycleLimitExceeded
TimeLimitExceeded
PayloadLengthLimitExceeded
}
```

## Values

| Name | Description |
| ---- | ----------- |
| `Unprocessed` | The input has not been processed yet. |
| `Accepted` | The input was accepted and processed successfully. |
| `Rejected` | The input was processed and the results were rejected. |
| `Exception` | An exception occurred during the processing of the input. |
| `MachineHalted` | The machine halted during the processing of the input. |
| `CycleLimitExceeded` | The cycle limit was exceeded during the processing of the input. |
| `TimeLimitExceeded` | The time limit was exceeded during the processing of the input. |
| `PayloadLengthLimitExceeded` | The payload length limit was exceeded during the processing of the input. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
id: input-connection
title: InputConnection
hide_table_of_contents: false
---


Represents a paginated connection of Inputs.

```graphql
type InputConnection {
edges: [InputEdge!]!
pageInfo: PageInfo!
}
```

## Fields

| Name | Type | Description |
| ---- |------| ------|
| `edges`| [`InputEdge`](../../objects/input-edge) | A list of `InputEdge` objects. Each edge contains an `Input` object and a cursor for pagination. |
| `pageInfo`| [`PageInfo`](../../objects/page-info) | Metadata about the pagination. |




This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
id: input-edge
title: InputEdge
hide_table_of_contents: false
---


Pagination entry.

```graphql
type InputEdge {
node: Input!
cursor: String!
}
```


## Fields

| Name | Type | Description |
| ---- | ---- | ----------- |
| `node` | [`Input!`](../../objects/input) | The Input object. |
| `cursor` | [`String!`](../../scalars/string) | A string that serves as a pagination cursor for this particular edge. |




This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: input
title: Input
hide_table_of_contents: false
---


Request submitted to the application to advance its state

```graphql
type Input {
index: Int!
status: CompletionStatus!
timestamp: DateTime!
msgSender: String!
blockNumber: Int!
payload: String!
notices: NoticeConnection!
vouchers: VoucherConnection!
reports: ReportConnection!
}
```

### Fields

| Name | Type | Description |
| ---- | ---- | ----------- |
| `index` | [`Int!`](../../scalars/int) | Unique identifier for the input. |
| `status` | [`CompletionStatus!`](../../objects/completion-status) | Current status of the input processing. |
| `timestamp` | [`DateTime!`](../../scalars/date-time) | Timestamp associated with the input submission. |
| `msgSender` | [`String!`](../../scalars/string) | Address of the account that submitted the input. |
| `blockNumber` | [`Int!`](../../scalars/int) | Number of the base layer block in which the input was recorded. |
| `payload` | [`String!`](../../scalars/string) | The actual data/content of the input. |
| `notices` | [`NoticeConnection!`](../../objects/notice-connection) | List of notices associated with this input. |
| `vouchers` | [`VoucherConnection!`](../../objects/voucher-connection) | List of vouchers associated with this input. |
| `reports` | [`ReportConnection!`](../../objects/report-connection) | List of reports associated with this input. |



Loading
Loading