Skip to content

Commit

Permalink
GitBook: [#13] No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
Massimo Luraschi authored and gitbook-bot committed Feb 11, 2022
1 parent 65e77da commit b4b91f2
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 50 deletions.
Binary file added .gitbook/assets/discord-1584x200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
description: Introducing Subsquid, a GraphQL query node for substrate chains.
cover: .gitbook/assets/discord-1584x200.png
coverY: 0
---

# Overview
Expand Down
17 changes: 17 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
* [Generate interfaces for Events and Extrinsics](recipes/generate-typescript-definitions.md)
* [Define a Squid Schema](recipes/define-a-squid-schema.md)
* [Reference](reference/README.md)
* [OpenReader Schema](reference/openreader-schema/README.md)
* [Annotations](reference/openreader-schema/annotations.md)
* [Indexes](reference/openreader-schema/indexes.md)
* [JSON fields](reference/openreader-schema/json-fields.md)
* [BigInt fields](reference/openreader-schema/bigint-fields.md)
* [Float fields](reference/openreader-schema/float-fields.md)
* [Entity Relations](reference/openreader-schema/entity-relations.md)
* [Union types](reference/openreader-schema/union-types.md)
* [Interfaces](reference/openreader-schema/interfaces.md)
* [Full text search](reference/openreader-schema/full-text-search.md)
* [OpenReader Queries](reference/openreader-queries/README.md)
* [AND/OR filters](reference/openreader-queries/and-or-filters.md)
* [Nested field queries](reference/openreader-queries/nested-field-queries.md)
* [Cross-relation field queries](reference/openreader-queries/cross-relation-field-queries.md)
* [JSON queries](reference/openreader-queries/json-queries.md)
* [String/Regex queries](reference/openreader-queries/string-regex-queries.md)
* [Union types/interfaces](reference/openreader-queries/union-types-interfaces.md)
* [Squid CLI](reference/squid-cli.md)
* [Squid Substrate metadata explorer](reference/squid-substrate-metadata-explorer.md)
* [Squid substrate typegen](reference/squid-substrate-typegen.md)
Expand Down
6 changes: 6 additions & 0 deletions reference/openreader-queries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: Collections of Reference pages dedicated to GraphQL queries
---

# OpenReader Queries

51 changes: 51 additions & 0 deletions reference/openreader-queries/and-or-filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# AND/OR filters

## Overview

When performing queries, our GraphQL implementation offers a vast selection of tools to filter and section results. One of these is the `where` clause, very common in most database query languages and [explained here](../../tutorial/graphql/queries.md#the-where-argument) in great detail.

In our GraphQL server implementation, we included logical operators to be used in the `where` clause, allowing to group multiple parameters in the same where argument using the `AND` or the `OR` operators to filter results based on more than one criteria.

### Example of `OR` clause:

Fetch a list of `accounts` that either have a balance bigger than a certain amount, or have a specific id.

```graphql
query {
accounts(
orderBy: balance_DESC,
where: {
OR: [
{balance_gte: "240000000000000000"}
{id_eq: "CksmaBx9rKUG9a7eXwc5c965cJ3QiiC8ELFsLtJMYZYuRWs"}
]
}
) {
balance
id
}
}

```

### Example of `AND` clause:

Fetch a list of `accounts` that have a balance between two specific amounts:

```graphql
query {
accounts(
orderBy: balance_DESC,
where: {
AND: [
{balance_lte: "240000000000000000"}
{balance_gte: "100000000000000"}
]
}
) {
balance
id
}
}

```
11 changes: 11 additions & 0 deletions reference/openreader-queries/cross-relation-field-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Cross-relation field queries



```graphql
query {
users(where:{posts_some:{id: "1"}}){
name
}
}
```
12 changes: 12 additions & 0 deletions reference/openreader-queries/json-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# JSON queries

[https://github.com/subsquid/squid/blob/master/openreader/src/test/lists.test.ts](https://github.com/subsquid/squid/blob/master/openreader/src/test/lists.test.ts)

```
type Foo {
foo: Int
bar: Int
}
```

[https://github.com/subsquid/squid/blob/master/openreader/src/test/typed-json.test.ts](https://github.com/subsquid/squid/blob/master/openreader/src/test/typed-json.test.ts)
42 changes: 42 additions & 0 deletions reference/openreader-queries/nested-field-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Nested field queries

## Overview

With OpenReader, fields of an Entity that contain fields themselves are shown as nested fields and it is possible to filter these as well.

As an example, this query searches for all `accounts` whose balance is bigger than a threshold value, fetching the `id`, `balance` simple fields, and the `historicalBalances` **nested field**.

```graphql
query {
accounts(orderBy: balance_ASC, where: {balance_gte: "250000000000000000"}) {
id
balance
historicalBalances {
balance
date
id
}
}
}

```

The nested field is a list (one account can have multiple `historicalBalances`) of objects with fields of their own and these results are filtered, in turn.

In this query, the `historicalBalances` are filtered, so that only results created after a certain date are returned

```graphql
query {
accounts(orderBy: balance_ASC, where: {balance_gte: "250000000000000000"}) {
id
balance
historicalBalances(where: {date_lte: "2020-10-31T11:59:59.000Z"}, orderBy: balance_DESC) {
balance
date
id
}
}
}

```

2 changes: 2 additions & 0 deletions reference/openreader-queries/string-regex-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# String/Regex queries

7 changes: 7 additions & 0 deletions reference/openreader-queries/union-types-interfaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
description: Resolving union types/interfaces with __typename
---

# Union types/interfaces

[https://graphql.org/learn/queries/#meta-fields](https://graphql.org/learn/queries/#meta-fields)
3 changes: 3 additions & 0 deletions reference/openreader-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OpenReader Schema

Op
2 changes: 2 additions & 0 deletions reference/openreader-schema/annotations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Annotations

2 changes: 2 additions & 0 deletions reference/openreader-schema/bigint-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# BigInt fields

6 changes: 6 additions & 0 deletions reference/openreader-schema/entity-relations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: One-to-Many/One-to-One/Many-to-One/Many-to-Many entity relations
---

# Entity Relations

2 changes: 2 additions & 0 deletions reference/openreader-schema/float-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Float fields

6 changes: 6 additions & 0 deletions reference/openreader-schema/full-text-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: How to define a schema that allows full text search across fields
---

# Full text search

2 changes: 2 additions & 0 deletions reference/openreader-schema/indexes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Indexes

3 changes: 3 additions & 0 deletions reference/openreader-schema/interfaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Interfaces

[https://graphql.org/learn/schema/#interfaces](https://graphql.org/learn/schema/#interfaces)
12 changes: 12 additions & 0 deletions reference/openreader-schema/json-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# JSON fields

[https://github.com/subsquid/squid/blob/master/openreader/src/test/lists.test.ts](https://github.com/subsquid/squid/blob/master/openreader/src/test/lists.test.ts)

```
type Foo {
foo: Int
bar: Int
}
```

[https://github.com/subsquid/squid/blob/master/openreader/src/test/typed-json.test.ts](https://github.com/subsquid/squid/blob/master/openreader/src/test/typed-json.test.ts)
3 changes: 3 additions & 0 deletions reference/openreader-schema/union-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Union types

[https://graphql.org/learn/schema/#union-types](https://graphql.org/learn/schema/#union-types)
14 changes: 5 additions & 9 deletions tutorial/create-a-simple-squid.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ The first thing to do, although it might sound trivial to GitHub experts, is to

![How to fork a repository on GitHub](<../.gitbook/assets/Screenshot 2022-02-02 111440.png>)

Next, clone the created repository (be careful of changing `<account>` with your own account
Next, clone the created repository (be careful of changing `<account>` with your own account)

```
git clone [email protected]:<account>/squid-template.git
```

For reference on the complete work, you can find the entire project [here](https://github.com/RaekwonIII/squid-template).
For reference on the complete work, you can find the entire project [here](https://github.com/RaekwonIII/squid-template/tree/crust-integration-demo).

### Run the project

Expand Down Expand Up @@ -124,7 +124,7 @@ To finalize this step, it is necessary to run the `codegen` tool, to generate Ty
npx sqd codegen
```

## Generate TypeScript types
## Generate TypeScript interfaces

The process to generate wrappers around TypeScript wrappers around Events and Extrinsics has a [dedicated page](../key-concepts/typegen.md) to explain it and a quick [Recipe](../recipes/generate-typescript-definitions.md) to guide you through it, so it is advised to consult them for more information.

Expand Down Expand Up @@ -322,7 +322,6 @@ Similar to what's been said in the previous chapter, this requires knowledge of
],
"calls": []
}

```
{% endcode %}

Expand Down Expand Up @@ -415,7 +414,6 @@ export class SworkWorksReportSuccessEvent {
return this.ctx._chain.decodeEvent(this.ctx.event)
}
}

```
{% endcode %}

Expand All @@ -438,11 +436,11 @@ processor.setDataSource({
archive: 'https://crust.indexer.gc.subsquid.io/v4/graphql',
chain: 'wss://rpc-crust-mainnet.decoo.io'
});
processor.setBlockRange({from: 583000}); // this is the starting block for exploring the change, please don't mind it.
processor.setBlockRange({from: 583000}); // this is the starting block for exploring the chain, please don't mind it.
processor.setTypesBundle(crustTypes);
```

Next, because the added and deleted files are matrices, we are going to declare a function to handle that, for our own convenience. Simply add this code to the `src/processor.ts` file, anywhere.
Next, because the added and deleted files are matrices, we are going to declare a function to handle that, for our own convenience. Simply add this code to the `src/processor.ts` file, anywhere.

```typescript
function stringifyArray(list: any[]): any[] {
Expand Down Expand Up @@ -668,7 +666,6 @@ async function getOrCreate<T extends {id: string}>(
type EntityConstructor<T> = {
new (...args: any[]): T
}

```
{% endcode %}
Expand Down Expand Up @@ -738,7 +735,6 @@ query AccountFiles{
}
}
}

```
It is advisable to search for an Account first and grab its ID.
Expand Down
41 changes: 0 additions & 41 deletions tutorial/graphql/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,44 +167,3 @@ query Query2 {
}
}
```

#### **Using multiple filters in the same query (`AND`, `OR`)**

You can group multiple parameters in the same where argument using the `AND` or the `OR` operators to filter results based on more than one criteria.

Example `AND`:

Fetch a list of videos published in a specific time-frame:

```graphql
query {
videos(
where: {
AND: [
{ publishedOn_gte: "2021-01-05" }
{ publishedOn_lte: "2020-01-05" }
]
}
) {
id
title
publishedOn
}
}
```

Example `OR`:

Fetch a list of videos that are **either** explicit, **or** published after 05/01/2021:

```graphql
query {
videos(
where: { OR: [{ publishedOn_gte: "2021-01-05" }, { isExplicit_eq: true }] }
) {
id
title
isExplicit
}
}
```

0 comments on commit b4b91f2

Please sign in to comment.