Skip to content

Commit

Permalink
Add Query Ecosystem guides
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbayly committed Feb 28, 2024
1 parent 447b138 commit 80e2fee
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 40 deletions.
8 changes: 6 additions & 2 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,21 @@ export default defineUserConfig({
"/build/quickstart/quickstart_chains/terra.html":
"/build/quickstart/quickstart_chains/cosmos.html",
"/run_publish/ipfs.html": "/miscellaneous/ipfs.html",
"/run_publish/query.html": "/run_publish/query/graphql.html",
"/run_publish/aggregate.html": "/run_publish/query/aggregate.html",
"/run_publish/subscription.html":
"/run_publish/query/subscription.html",
};
return {
...redirects,
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace(
"/subquery_network/node_operators/indexers/",
"/subquery_network/indexers/",
"/subquery_network/indexers/"
),
path,
]),
])
),
};
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions docs/.vuepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,22 @@ export const getSidebar = (locale: string) =>
},
`${locale}/run_publish/cli.md`,
{
text: "Querying",
text: "Query and Access Data",
link: `${locale}/run_publish/query/query.md`,
collapsible: true,
children: [
`${locale}/run_publish/query/query.md`,
{
text: "GraphQL",
children: [
`${locale}/run_publish/query.md`,
`${locale}/run_publish/aggregate.md`,
`${locale}/run_publish/subscription.md`,
`${locale}/run_publish/query/graphql.md`,
`${locale}/run_publish/query/aggregate.md`,
`${locale}/run_publish/query/subscription.md`,
],
},
{
text: "Other Tools",
children: [`${locale}/run_publish/other_tools/metabase.md`],
children: [`${locale}/run_publish/query/other_tools/metabase.md`],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion docs/academy/herocourse/module5.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Slots are a feature in SubQuery's Managed Service that are the equivalent of a d

Once your project is deployed, access your project and run your desired query in the playground. For more information, visit:

- [Query your Project using GraphQL in SubQuery Explorer](/run_publish/query.md)
- [Query your Project using GraphQL in SubQuery Explorer](/run_publish/query/graphql.md)

#### Step 6: Query via the API

Expand Down
2 changes: 1 addition & 1 deletion docs/build/graph-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ SubQuery does not support historical metadata querying. However `deployments` wi

- SubQuery has a larger support for query pagination. You have the options of using `first` and `offset`, or `cursors` on `edges`.
- Note that [cursor-based pagination](https://graphql.org/learn/pagination/#pagination-and-edges) is far more efficient compared to `first`/`offset`/`after` pagination
- SubQuery supports [advanced aggregate functions](../run_publish/aggregate.md) to allow you to perform a calculation on a set of values during your query.
- SubQuery supports [advanced aggregate functions](../run_publish/query/aggregate.md) to allow you to perform a calculation on a set of values during your query.

## What's Next?

Expand Down
2 changes: 1 addition & 1 deletion docs/build/project-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ Other notes:
- Only supports PostgreSQL stores
- Migrations will not succeed `--unfinalizedBlocks` is enabled
- Does not support Enum modification
- [GraphQL subscriptions](../run_publish/subscription.md) are not supported
- [GraphQL subscriptions](../run_publish/query/subscription.md) are not supported
- [Rewind](../run_publish/historical.md) will only be supported if the new schema does not drop any `fields` or `entity`. Note that [automated historical state tracking](../run_publish/historical.md) must be enabled to support rewind.
6 changes: 3 additions & 3 deletions docs/quickstart/quickstart_chains/polkadot-astar.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Navigate to the default mapping function in the `src/mappings` directory. There
type ApproveCallArgs = [AccountId, Balance];

export async function handleWasmCall(
call: WasmCall<ApproveCallArgs>,
call: WasmCall<ApproveCallArgs>
): Promise<void> {
logger.info(`Processing WASM Call at ${call.blockNumber}`);
const approval = new Approval(`${call.blockNumber}-${call.idx}`);
Expand All @@ -214,7 +214,7 @@ The `handleWasmCall` function receives event data from the WASM execution enviro
```ts
export async function handleBondAndStake(event: SubstrateEvent): Promise<void> {
logger.info(
`Processing new Dapp Staking Bond and Stake event at ${event.block.block.header.number}`,
`Processing new Dapp Staking Bond and Stake event at ${event.block.block.header.number}`
);
const {
event: {
Expand Down Expand Up @@ -265,7 +265,7 @@ query {
```

::: tip
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query.md).
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query/graphql.md).
:::

You should see results similar to below:
Expand Down
12 changes: 6 additions & 6 deletions docs/quickstart/quickstart_chains/polkadot-kilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ Navigate to the default mapping function in the `src/mappings` directory. There

```ts
export async function handleAttestationCreated(
event: SubstrateEvent,
event: SubstrateEvent
): Promise<void> {
logger.info(
`New attestation created at block ${event.block.block.header.number}`,
`New attestation created at block ${event.block.block.header.number}`
);
// A new attestation has been created.\[attester ID, claim hash, CType hash, (optional) delegation ID\]
const {
Expand All @@ -112,10 +112,10 @@ export async function handleAttestationCreated(
}

export async function handleAttestationRevoked(
event: SubstrateEvent,
event: SubstrateEvent
): Promise<void> {
logger.info(
`New attestation revoked at block ${event.block.block.header.number}`,
`New attestation revoked at block ${event.block.block.header.number}`
);
// An attestation has been revoked.\[account id, claim hash\]
const {
Expand All @@ -138,7 +138,7 @@ export async function handleAttestationRevoked(

export async function handleDailyUpdate(
date: Date,
type: "CREATED" | "REVOKED",
type: "CREATED" | "REVOKED"
): Promise<void> {
const id = date.toISOString().slice(0, 10);
let aggregation = await Aggregation.get(id);
Expand Down Expand Up @@ -194,7 +194,7 @@ query {
```

::: tip
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query.md).
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query/graphql.md).
:::

You should see results similar to below:
Expand Down
8 changes: 4 additions & 4 deletions docs/quickstart/quickstart_chains/polkadot-moonbeam.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Navigate to the default mapping function in the `src/mappings` directory. There

```ts
export async function handleCollatorJoined(
call: SubstrateExtrinsic,
call: SubstrateExtrinsic
): Promise<void> {
//We added a logger to the top of this function, in order to see the block number of the event we are processing.
logger.info(`Processing SubstrateEvent at ${call.block.block.header.number}`);
Expand All @@ -152,7 +152,7 @@ export async function handleCollatorJoined(
}

export async function handleCollatorLeft(
call: SubstrateExtrinsic,
call: SubstrateExtrinsic
): Promise<void> {
//We added a logger to the top of this function, in order to see the block number of the event we are processing.
logger.info(`Processing SubstrateCall at ${call.block.block.header.number}`);
Expand All @@ -168,7 +168,7 @@ The `handleCollatorJoined` and `handleCollatorLeft` functions receives Substrate
export async function erc20Transfer(
event: MoonbeamEvent<
[string, string, BigNumber] & { from: string; to: string; value: BigNumber }
>,
>
): Promise<void> {
//We added a logger to the top of this function, in order to see the block number of the event we are processing.
logger.info(`Processing MoonbeamEvent at ${event.blockNumber.toString()}`);
Expand Down Expand Up @@ -209,7 +209,7 @@ query {
```

::: tip
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query.md).
There is a _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and helps you find what entities and methods you can query. To learn more about the GraphQL Query language [here](../../run_publish/query/graphql.md).
:::

You should see results similar to below:
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/snippets/query-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Next, let's query our project. Follow these three simple steps to query your Sub

3. Find the _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and it helps you find what entities and methods you can query.

Try the following queries to understand how it works for your new SubQuery starter project. Don’t forget to learn more about the [GraphQL Query language](../../run_publish/query.md).
Try the following queries to understand how it works for your new SubQuery starter project. Don’t forget to learn more about the [GraphQL Query language](../../run_publish/query/graphql.md).
2 changes: 1 addition & 1 deletion docs/quickstart/whats-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Now that you have a clear understanding of how to build a basic SubQuery project

- [Multi-chain indexing support](../build/multi-chain.md) - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks.
- [Dynamic Data Sources](../build/dynamicdatasources.md) - When you want to index factory contracts, for example on a DEX or generative NFT project.
- [GraphQL Subscriptions](../run_publish/subscription.md) - Build more reactive front end applications that subscribe to changes in your SubQuery project.
- [GraphQL Subscriptions](../run_publish/query/subscription.md) - Build more reactive front end applications that subscribe to changes in your SubQuery project.

- Find out **how to build a performant SubQuery project and avoid common mistakes** in [Project Optimisation](../build/optimisation.md).

Expand Down
4 changes: 2 additions & 2 deletions docs/run_publish/optimisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SubQuery runs well behind an API gateway or a DDOS mitigation service. For any p

## Request Caching

Although @subql/node does not natively provide any default request level caching, one of the easiest ways to increase performance when the number of users hitting your SubQuery project increases is by adding a cache in front of the GraphQL endpoint with a basic TTL of a few seconds (depending on how stale you want to allow your data). Most cloud providers offer simple to setup and manage caching solutions (e.g. Redis) that will work well with the GraphQL api endpoints that we provide. If you're worried about stale data affecting your user's experience, by leveraging [GraphQl subscriptions](./subscription.md) you can ensure that the most recent data is never affected by the cache while older, slower data is mostly from the cache. Additionally, consider different TTLs for each different entity.
Although @subql/node does not natively provide any default request level caching, one of the easiest ways to increase performance when the number of users hitting your SubQuery project increases is by adding a cache in front of the GraphQL endpoint with a basic TTL of a few seconds (depending on how stale you want to allow your data). Most cloud providers offer simple to setup and manage caching solutions (e.g. Redis) that will work well with the GraphQL api endpoints that we provide. If you're worried about stale data affecting your user's experience, by leveraging [GraphQl subscriptions](./query/subscription.md) you can ensure that the most recent data is never affected by the cache while older, slower data is mostly from the cache. Additionally, consider different TTLs for each different entity.

## Database Configuration

Expand All @@ -34,6 +34,6 @@ GraphQL is extremely powerful, but one of the downsides is that it allows users
- `--query-timeout` is a flag that will restrict the time each query will be allowed to run for, [read more here](./references.md#query-timeout).
- `--max-connection` is a flag that will restrict the number of simultaneous DB connections created by the query endpoint, [read more here](./references.md#max-connection).
- `--query-limit` is a flag that allows you to limit the number of results returned by any query and enforce pagination, [read more here](./references.md#query-limit).
- `--unsafe` is a flag that enables some advanced features like [GraphQL aggregations](./aggregate.md), these may have performance impacts, [read more here](./references.md#unsafe-query-service)
- `--unsafe` is a flag that enables some advanced features like [GraphQL aggregations](./query/aggregate.md), these may have performance impacts, [read more here](./references.md#unsafe-query-service)

You should also consider reading this excellent guide from Apollo on how they recommend you secure your [GraphQL API from malicious queries](https://www.apollographql.com/blog/graphql/security/securing-your-graphql-api-from-malicious-queries/).
2 changes: 1 addition & 1 deletion docs/run_publish/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Once your deployment has succesfully completed and our nodes have indexed your d

![Project being deployed and synced](/assets/img/run_publish/projects_deploy_sync.png)

Alternatively, you can click on the three dots next to the title of your project, and view it on SubQuery Explorer. There you can use the in browser playground to get started - [read more about how to use our Explorer's GraphQL playground here](../run_publish/query.md).
Alternatively, you can click on the three dots next to the title of your project, and view it on SubQuery Explorer. There you can use the in browser playground to get started - [read more about how to use our Explorer's GraphQL playground here](../run_publish/query/graphql.md).

![Projects in SubQuery Explorer](/assets/img/run_publish/projects_explorer.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SubQuery provides the following aggregate functions when in unsafe mode:
SubQuery's implementation of aggregate functions is based on [pg-aggregates](https://github.com/graphile/pg-aggregates), you can find more information there.

::: warning Important
Please note that you must enable the `--unsafe` flag on the query service in order to use these functions. [Read more](./references.md#unsafe-query-service).
Please note that you must enable the `--unsafe` flag on the query service in order to use these functions. [Read more](../references.md#unsafe-query-service).

Also, note that the `--unsafe` command will prevent your project from being run in the SubQuery Network, and you must contact support if you want this command to be run with your project in [SubQuery's managed service](https://managedservice.subquery.network).
:::
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

::: info Coming from the Graph?

You may want to take a look at the information we have [on the differences](../build/graph-migration.md#graphql-query-differences) between SubQuery's GraphQL library, and The Graph.
You may want to take a look at the information we have [on the differences](../../build/graph-migration.md#graphql-query-differences) between SubQuery's GraphQL library, and The Graph.

:::

You can follow the [official GraphQL guide here](https://graphql.org/learn/) to learn more about GraphQL, how it works, and how to use it:

- There are libraries to help you implement GraphQL in [many different languages](https://graphql.org/code/) - we recommend [Apollo Client](https://www.apollographql.com/docs/react/) as it will allow a [seamless migration to our decentralised network](../subquery_network/publish.md#changes-to-your-dapp) when you publish your project in the future.
- You will want to review advice on how to [structure your GraphQL queries to maximise performance](../build/optimisation.md#query-performance-advice).
- There are libraries to help you implement GraphQL in [many different languages](https://graphql.org/code/) - we recommend [Apollo Client](https://www.apollographql.com/docs/react/) as it will allow a [seamless migration to our decentralised network](../../subquery_network/publish.md#changes-to-your-dapp) when you publish your project in the future.
- You will want to review advice on how to [structure your GraphQL queries to maximise performance](../../build/optimisation.md#query-performance-advice).
- For an in-depth learning experience with practical tutorials, see [How to GraphQL](https://www.howtographql.com/).
- Check out the free online course, [Exploring GraphQL: A Query Language for APIs](https://www.edx.org/course/exploring-graphql-a-query-language-for-apis).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ The objective of this guide is to show you how to analyse data from any SubQuery

:::warning Automated Historical State Tracking

When running your project for the sole purpose of visualising in Metabase, we strongly recommending running your project with [Automated Historical State Tracking](../historical.md) disabled.
When running your project for the sole purpose of visualising in Metabase, we strongly recommending running your project with [Automated Historical State Tracking](../../historical.md) disabled.

Automated Historical State Tracking alters the underlying DB tables to manage state tracking for you automatically. However this may make things complicated for Metabase visualisations. You can read more about these alterations [here](../historical.md#db-schema).
Automated Historical State Tracking alters the underlying DB tables to manage state tracking for you automatically. However this may make things complicated for Metabase visualisations. You can read more about these alterations [here](../../historical.md#db-schema).

:::

At a high level, there is no specific configuration required to ensure compatibility between your SubQuery indexing project and Metabase. The key factor is that your Metabase instance must be able to access the Postgres database that your SubQuery project is indexing into.

For that reason, visualising data in Metabase is not supported in SubQuery decentralised network or Managed Service, you must self host and run your SubQuery Indexing project.

You will want to follow the guide on how to run your [SubQuery indexing project locally](../run.md#running-subquery-locally). Please pay attention to what you set as your Postgres database host, port, username, and password.
You will want to follow the guide on how to run your [SubQuery indexing project locally](../../run.md#running-subquery-locally). Please pay attention to what you set as your Postgres database host, port, username, and password.

## Configuring Metabase

Expand All @@ -28,7 +28,7 @@ The installation steps are thoroughly documented, ensuring a seamless configurat

![](/assets/img/run_publish/metabase/metabase-database-connection.png)

If you are running your indexer project [locally](../run.md) through Docker, all the requisite information can be found in the `docker-compose.yml` file. When you provide the correct credentials, Metabase will attempt to establish a connection. It will only proceed if the connection is successful. This connection allows Metabase to access the indexed blockchain data, enabling robust analysis and visualisation capabilities.
If you are running your indexer project [locally](../../run.md) through Docker, all the requisite information can be found in the `docker-compose.yml` file. When you provide the correct credentials, Metabase will attempt to establish a connection. It will only proceed if the connection is successful. This connection allows Metabase to access the indexed blockchain data, enabling robust analysis and visualisation capabilities.

## Browse Data

Expand Down
Loading

0 comments on commit 80e2fee

Please sign in to comment.