-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e77da
commit b4b91f2
Showing
22 changed files
with
196 additions
and
50 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
reference/openreader-queries/cross-relation-field-queries.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# String/Regex queries | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# OpenReader Schema | ||
|
||
Op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Annotations | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# BigInt fields | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Float fields | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Indexes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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. | ||
|
||
|
@@ -322,7 +322,6 @@ Similar to what's been said in the previous chapter, this requires knowledge of | |
], | ||
"calls": [] | ||
} | ||
|
||
``` | ||
{% endcode %} | ||
|
||
|
@@ -415,7 +414,6 @@ export class SworkWorksReportSuccessEvent { | |
return this.ctx._chain.decodeEvent(this.ctx.event) | ||
} | ||
} | ||
|
||
``` | ||
{% endcode %} | ||
|
||
|
@@ -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[] { | ||
|
@@ -668,7 +666,6 @@ async function getOrCreate<T extends {id: string}>( | |
type EntityConstructor<T> = { | ||
new (...args: any[]): T | ||
} | ||
|
||
``` | ||
{% endcode %} | ||
|
@@ -738,7 +735,6 @@ query AccountFiles{ | |
} | ||
} | ||
} | ||
|
||
``` | ||
It is advisable to search for an Account first and grab its ID. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters