GraphQL
1 Introduction
GraphQL serves as a powerful intermediary layer that simplifies and enhances the process of fetching data from databases. Unlike traditional methods, where each endpoint corresponds to a fixed data structure and often results in over-fetching or under-fetching of data, GraphQL offers a more efficient and precise approach to retrieving data.
2 Use GraphQL to Get Data
Users can leverage GraphQL to retrieve data by sending queries to a GraphQL server. Here's a step-by-step guide on how users can use GraphQL to get data.
2.1 Access GraphQL API Endpoint
InfStones provides GraphQL endpoint as below:
https://stakingapi.infstones.com
2.2 Write GraphQL Query
Compose a GraphQL query to specify the retrieved data. A GraphQL query is a JSON-like string that describes the shape and structure of the desired data. Queries can include fields, arguments, and nested selections to tailor the request to their exact requirements.
Example Query
query {
get_activity() {
activity {
id
wallet
raw_tx
activity_status
action
timestamp
}
}
}
2.3 Send Query to GraphQL Server
2.3.1 Use GraphQL API to Send Query
Use HTTP to send a query as a POST request to the GraphQL API endpoint.
2.3.2 Use GraphQL Playground to Send Query
Open GraphQL Playground, input your query and access token, and then send the request.
3 Get Activity
3.1 Query
Arguments
Key | Type | Required | Detail |
---|---|---|---|
id | String | ❌ | Unique ID of the activity |
page | Integer | ❌ | Page number |
page_size | Integer | ❌ | The number of results returned on each page |
Query Fields
Users have the flexibility to customize the fields displayed in the results by specifying the desired fields within the query, allowing for tailored and selective data presentation.
For available fields, see fields list here.
Example
This GraphQL query retrieves activity data associated with a specific <activity_id>
, limited to the first page with 10 results, including attributes such as ID, Protocol, Wallet, ActivityStatus, Action, Amount, RawTx, and Timestamp, along with the total count of activities that match the criteria.
{
get_activity(id:"<activity_id>",page:1, page_size:10) {
activity {
id
protocol
wallet
raw_tx
amount
activity_status
action
timestamp
},
count
}
}
3.2 Response
Result
activity
: the array of individual activity objects, each containing the fields specified in the aboveQuery Fields
count
: the total number of activities that user generated
Example
{
"data": {
"get_activity": {
"activity": [
{
"id": "d32f467a-c34f-4dbc-9bb8-85ca7abf3794",
"protocol": "ethereum",
"wallet": "0x068e866a5b6a968599c353ee359442ec7bbc9b61",
"raw_tx": "",
"amount": "32",
"activity_status": "completed",
"action": "unstake",
"timestamp": "1692776958"
},
{
"id": "b03ddb4b-4cb3-4672-9a37-ab93800ac326",
"protocol": "sui",
"wallet": "0x8454ca63a85c5c4dba3e596caf53a0466c20f0c5e5a2af3e43bb73c2093a796d",
"raw_tx": "AAAEAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQEAAAAAAAAAAQEASBh2xmGPEOc7W6W9E5/yCPMjp5ZBMtdPp2lcrtyfr/sTqQwAAAAAACC6qbS/Lbf0iJLDdeyA3TdcovaH+KKQKHduArLHn5n7BgAJAQDKmjsAAAAAACDKWAS/t+BCghItq8OiAVfiAC5Tnbq5qMpssbDyKlJUogIFAAEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMKc3VpX3N5c3RlbRpyZXF1ZXN0X2FkZF9zdGFrZV9tdWxfY29pbgAEAQAAAgAAAQIAAQMAhFTKY6hcXE26Pllsr1OgRmwg8MXloq8+Q7tzwgk6eW0BCh56GEwy5l2BquUaGwJ8tmFEiK4ovYltgVEp+jqB69uJYH0AAAAAACBEA8jefVNcKiCC/q2tbWJ51POTljnB54rmRbcjUqgwvoRUymOoXFxNuj5ZbK9ToEZsIPDF5aKvPkO7c8IJOnlt6AMAAAAAAACuz6UAAAAAAAA=",
"amount": "1",
"activity_status": "completed",
"action": "stake",
"timestamp": "1692810380"
}
],
"count": 92
}
}
}
4 Get Asset
4.1 Query
Arguments
Key | Type | Required | Detail |
---|---|---|---|
sort_field | String | ❌ | Customize sorting criteria for results |
reverse | Boolean | ❌ | Reverse sort order with true |
protocols | String Array | ❌ | Filter by specific protocols |
keywords | String Array | ❌ | Filter for wallet and validator , case insensitive |
start_time | String | ❌ | Filter after a specified start_time , represented in epoch time format |
end_time | String | ❌ | Filter after a specified end_time , represented in epoch time format |
id | String | ❌ | Unique ID of the asset |
page | Integer | ❌ | Page number |
page_size | Integer | ❌ | The number of results returned on each page |
Query Fields
Users have the flexibility to customize the fields displayed in the results by specifying the desired fields within the query, allowing for tailored and selective data presentation.
For available fields, see fields list here.
Example
{
get_asset(page:1, page_size:2) {
asset {
id
protocol
wallet
validator
active_stake
last_action_time
}
count
}
}
{
get_asset(keywords: ["eth"], sort_field: "active_stake", reverse: true, page: 1, page_size:3) {
asset {
id
protocol
wallet
validator
active_stake
last_action_time
},
count
}
}
4.2 Response
Result
asset
: the array of individual activity objects, each containing the fields specified in the aboveQuery Fields
count
: total number of assets the user possesses
Example
{
"data": {
"get_asset": {
"asset": [
{
"id": "00f87495-7c2a-4137-9c3c-d68522e8f023",
"protocol": "ethereum",
"wallet": "0x5a1f4d3975749719ef98716e0afb26fbc2216cb4",
"validator": "0x89520838dc7f72321aed8eac23af78567273eb7cf00943bba6f2d418fbde72cddd1ef7464b02f096cd0d3f411262ae77",
"active_stake": "0",
"pending_stake": "0",
"total_reward": "0.114285714285714286",
"received_reward": "0",
"claimable_reward": "0.114285714285714286",
"unstaking": "0",
"unstaking_in_progress": "0",
"unstaking_withdrawable": "0",
"last_action_time": "1693340388"
}
],
"count": 37
}
}
}
5 Get History
5.1 Query
Arguments
Key | Type | Required | Detail |
---|---|---|---|
protocols | String Array | ✅ | Filter by specific protocols |
wallet | String | ✅ | Filter by specific wallet |
validator | String | ✅ | Filter by specific validator |
sort_field | String | ❌ | Customize sorting criteria for results |
reverse | Boolean | ❌ | Reverse sort order with true |
keywords | String Array | ❌ | Performs a strict equality comparison against the txHash field, retrieving data that precisely matches the provided keywords |
statuses | String Array | ❌ | Filter by specific statuses, such as ["unsigned", "failed", "completed", "pending"] |
actions | String Array | ❌ | Filter by specific actions, such as ["stake", "unstake", "claim", "withdraw"] |
start_time | String | ❌ | Filter after a specified start_time , represented in epoch time format |
end_time | String | ❌ | Filter after a specified end_time , represented in epoch time format |
id | String | ❌ | Unique ID of the asset |
page | Integer | ❌ | Page number |
page_size | Integer | ❌ | The number of results returned on each page |
Query Fields
Users have the flexibility to customize the fields displayed in the results by specifying the desired fields within the query, allowing for tailored and selective data presentation.
For available fields, see fields list here.
Example
{
get_history(
protocol: "<protocol_name>",
wallet: "<token_wallet_address>",
validator: "<validator_address>",
actions: ["stake", "unstake"]
) {
history {
amount
wallet
validator
action
tx_hash
timestamp
tx_status
},
count
}
}
5.2 Response
history
: the array of individual activity objects, each containing the fields specified in the aboveQuery Fields
count
: the total count of history the use has
Example
{
"data": {
"get_history": {
"history": [
{
"amount": "1",
"wallet": "0x8454ca63a85c5c4dba3e596caf53a0466c20f0c5e5a2af3e43bb73c2093a796d",
"validator": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"action": "stake",
"tx_hash": "DEUKzK4cVo9WsR2csEJE4Ah7h43T8pkZSDQBaTsnDvSC",
"timestamp": "1694205374",
"tx_status": "completed"
},
{
"amount": "2",
"wallet": "0x8454ca63a85c5c4dba3e596caf53a0466c20f0c5e5a2af3e43bb73c2093a796d",
"validator": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"action": "stake",
"tx_hash": "Gs9R97WQVtNh5ZrRaEFXNDKk9xrbHNWMgVSoV97wVB1w",
"timestamp": "1694120509",
"tx_status": "completed"
}
],
"count": 25
}
}
}
Updated about 1 month ago