-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Document fulltext search * Review updates --------- Co-authored-by: James Bayly <[email protected]>
- Loading branch information
1 parent
497dd5a
commit 265dd90
Showing
3 changed files
with
87 additions
and
38 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -77,7 +77,7 @@ All entites can be imported from the following directory after codegen: | |
import { GraphQLEntity1, GraphQLEntity2 } from "../types"; | ||
``` | ||
|
||
### Entities | ||
### IDs | ||
|
||
Each entity must define its required fields `id` with the type of `ID!`. It is used as the primary key and unique among all entities of the same type. | ||
|
||
|
@@ -91,6 +91,32 @@ type Example @entity { | |
} | ||
``` | ||
|
||
### Supported scalar types | ||
|
||
We currently support the following scalar types: | ||
|
||
- `ID` (supports [full text search](#full-text-search)) | ||
- `Int` | ||
- `String` (supports [full text search](#full-text-search)) | ||
- `BigInt` | ||
- `Float` | ||
- `Date` | ||
- `Boolean` | ||
- `<EntityName>` for nested relationship entities, you might use the defined entity's name as one of the fields. Please see in [Entity Relationships](graphql.md#entity-relationships). | ||
- `JSON` can alternatively store structured data, please see [JSON type](graphql.md#json-type) | ||
- `<EnumName>` types are a special kind of enumerated scalar that is restricted to a particular set of allowed values. Please see [Graphql Enum](https://graphql.org/learn/schema/#enumeration-types) | ||
|
||
### Naming Constraints | ||
|
||
You'll need to shorten the entity's name if you get an error such as the following when running the app: | ||
|
||
```shell | ||
subquery-notifications-postgres-1 | 2022-08-26 14:18:12.355 UTC [1922] ERROR: constraint "bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fk" for table "bank_msg_multi_send_input_coins" does not exist | ||
subquery-notifications-postgres-1 | 2022-08-26 14:18:12.355 UTC [1922] STATEMENT: COMMENT ON CONSTRAINT bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fkey ON "app"."bank_msg_multi_send_input_coins" IS E'@foreignFieldName coins' | ||
``` | ||
|
||
SubQuery automatically generates Postgres identifiers for your entities. For example, if you have an entity named `BankMsgMultiSendInputCoins`, then an identifier `bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fkey` will be automatically generated in Postgres. However, this identifier is 65 bytes, and Postgres doesn't support identifiers larger than 63 bytes. In this example, shortening the entity's name to `BankMultiSendInputCoins` will resolve the issue. | ||
|
||
### Adding Documentation Strings to GraphQL Schema | ||
|
||
Documentation strings (also known as "doc strings") can be added to a GraphQL schema to provide human-readable descriptions of the schema's types and fields. This can be particularly useful for maintaining and understanding the schema over time, and for auto-generating API documentation. | ||
|
@@ -124,61 +150,37 @@ In addition, when using GraphQL query Playground, these doc strings will automat | |
![image](../.vuepress/public/assets/img/build/schema_docstring.png) | ||
### Naming Constraints | ||
You'll need to shorten the entity's name if you get an error such as the following when running the app: | ||
```shell | ||
subquery-notifications-postgres-1 | 2022-08-26 14:18:12.355 UTC [1922] ERROR: constraint "bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fk" for table "bank_msg_multi_send_input_coins" does not exist | ||
subquery-notifications-postgres-1 | 2022-08-26 14:18:12.355 UTC [1922] STATEMENT: COMMENT ON CONSTRAINT bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fkey ON "app"."bank_msg_multi_send_input_coins" IS E'@foreignFieldName coins' | ||
``` | ||
SubQuery automatically generates Postgres identifiers for your entities. For example, if you have an entity named `BankMsgMultiSendInputCoins`, then an identifier `bank_msg_multi_send_input_coins_bank_msg_multi_send_input_id_fkey` will be automatically generated in Postgres. However, this identifier is 65 bytes, and Postgres doesn't support identifiers larger than 63 bytes. In this example, shortening the entity's name to `BankMultiSendInputCoins` will resolve the issue. | ||
### Supported scalar types | ||
We currently support the following scalar types: | ||
- `ID` | ||
- `Int` | ||
- `String` | ||
- `BigInt` | ||
- `Float` | ||
- `Date` | ||
- `Boolean` | ||
- `<EntityName>` for nested relationship entities, you might use the defined entity's name as one of the fields. Please see in [Entity Relationships](graphql.md#entity-relationships). | ||
- `JSON` can alternatively store structured data, please see [JSON type](graphql.md#json-type) | ||
- `<EnumName>` types are a special kind of enumerated scalar that is restricted to a particular set of allowed values. Please see [Graphql Enum](https://graphql.org/learn/schema/#enumeration-types) | ||
## Indexing by non-primary-key field | ||
## Indexing | ||
To improve query performance, index an entity field simply by implementing the `@index` annotation on a non-primary-key field (you can also use [composite indexes](#composite-index)). | ||
`@index` annotations are not supported on any [JSON](graphql.md#json-type) object or a boolean field. | ||
By default, indexes are automatically added to foreign keys and for JSON fields in the database, but only to enhance query service performance. | ||
### Standard Indexes | ||
Assuming we knew this user's `email`, but we don't know the exact `id` value, rather than extract all users and then filtering by `email` we can add `@index` behind the `email` field. This makes querying much faster and we can additionally pass the `unique: true` to ensure uniqueness. | ||
Here is an example. | ||
```graphql | ||
type User @entity { | ||
id: ID! | ||
name: String! @index(unique: true) # unique can be set to true or false | ||
email: String! @index(unique: true) # unique can be set to true or false | ||
name: String! | ||
title: Title! # Indexes are automatically added to foreign key field | ||
} | ||
type Title @entity { | ||
id: ID! | ||
name: String! @index(unique: true) | ||
title: String! @index(unique: true) | ||
} | ||
``` | ||
Assuming we knew this user's name, but we don't know the exact id value, rather than extract all users and then filtering by name we can add `@index` behind the name field. This makes querying much faster and we can additionally pass the `unique: true` to ensure uniqueness. | ||
**If a field is not unique, the maximum result set size is 100** | ||
When code generation is run, this will automatically create a `getByName` under the `User` model, and the foreign key field `title` will create a `getByTitleId` method, | ||
which both can directly be accessed in the mapping function. | ||
When code generation is run, this will automatically create a `getByEmail` under the `User` model, and the foreign key field `title` will create a `getByTitleId` method, which both can directly be accessed in the mapping function. | ||
```sql | ||
/* Prepare a record for title entity */ | ||
|
@@ -190,14 +192,14 @@ INSERT INTO titles (id, name) VALUES ('id_1', 'Captain') | |
import { User } from "../types/models/User"; | ||
import { Title } from "../types/models/Title"; | ||
const jack = await User.getByName("Jack Sparrow"); | ||
const jack = await User.getByEmail("[email protected]"); | ||
const captainTitle = await Title.getByName("Captain"); | ||
const pirateLords = await User.getByTitleId(captainTitle.id); // List of all Captains | ||
``` | ||
### Composite Index | ||
### Composite Indexes | ||
Composite indexes work just like regular indexes, except they provide even faster access to data by utilising multiple columns to create the index. | ||
|
@@ -362,6 +364,30 @@ type Transfer @entity { | |
} | ||
``` | ||
## Full Text Search | ||
We support a fast, efficient way to perform full text search across multiple fields in entities. | ||
::: warning Note | ||
This will create a new generated column and index in your Database. Adding full text search to an existing project via [project upgrade](./project-upgrades.md) or on an existing dataset might result in some performance issues when initially building these indexes. | ||
::: | ||
To add support for full text search on an entity field, add the `fullText` directive to an entity. This directive requires the fields that wish to be searchable. These fields must be either `ID`, `String`, or a foreign key. A language option is also required to provide optimal search functionality, supported languages can be found at [https://stackoverflow.com/a/39752553](https://stackoverflow.com/a/39752553). | ||
```graphql | ||
type NFT | ||
@entity | ||
@fullText(fields: ["name", "description"], language: "english") { | ||
id: ID! | ||
name: String! | ||
description: String! | ||
} | ||
``` | ||
To read about how to query full text fields, see [querying with full text search](../run_publish/query/graphql.md#full-text-search). | ||
## JSON type | ||
We are supporting saving data as a JSON type, which is a fast way to store structured data. We'll automatically generate corresponding JSON interfaces for querying this data and save you time defining and managing entities. | ||
|
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