Hasura July 2023 Newsletter 個人的まとめ
![chima91](https://res.cloudinary.com/zenn/image/fetch/s--0MVa50Z7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3d8d9aa01d.jpeg)
Hasura v3 updates
The beta is scheduled for August,
Hasura v3 のベータ版は8月に予定されており、登録はここからできる。
![chima91](https://res.cloudinary.com/zenn/image/fetch/s--0MVa50Z7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3d8d9aa01d.jpeg)
Input validations for mutations
You can now perform custom input validations for mutations using external webhooks.
v2.29.0
以上でサポートされる機能。
多くの場合、データを挿入・削除・更新する前に、GraphQLミューテーションの入力引数に対してバリデーションを行う必要がある。
そこでHasuraは複雑な検証ロジックを実行するために、ミューテーションの入力引数をHTTP Webhookにルーティングする。
- table:
schema: public
name: products
insert_permissions:
- role: user
permission:
columns: []
filter: {}
validate_input:
type: http
definition:
url: http://www.somedomain.com/validateProducts
headers:
- name: X-Validate-Input-API-Key
value_from_env: VALIDATION_HOOK_API_KEY
forward_client_headers: true
timeout: 5
![chima91](https://res.cloudinary.com/zenn/image/fetch/s--0MVa50Z7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3d8d9aa01d.jpeg)
Schema Registry
The Hasura Schema Registry now allows you to tag your schemas to versions that you can easily identify, as well as customize email alerts for specific changes in your schema.
Hasura Cloud v2.26.0-cloud.1
以降でサポートされる機能。
HasuraのプロジェクトにあるすべてのGraphQLスキーマを保存するレジストリ。
GraphQLスキーマの変更をより信頼性の高いものにし、破壊的変更を防ぐ。
Hasuraエンジン上でGraphQLスキーマを変更するような操作があるたびに、HasuraはイベントをSchema Registry
に送信する。GraphQLスキーマを変更する可能性のある操作は以下。
- 新しいメタデータの適用
- メタデータのリロード
- Hasuraのバージョンアップデート
![chima91](https://res.cloudinary.com/zenn/image/fetch/s--0MVa50Z7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3d8d9aa01d.jpeg)
Aggregation queries for computed fields
We’re delighted to have released a highly requested feature for our PostgreSQL users – aggregation queries for computed fields, with which you can now calculate computed field values and aggregate them on the fly.
v2.27 for Postgres
でサポートされる機能。
集約クエリには、数値クエリ (sum
やavg
など) 、比較クエリ (max
やmin
) の2種類がある。
これまでは、これらのクエリは、フィールドがcomputed field
ではない限り適用することができた。
computed field
を使うと、カスタムSQL関数を使用してGraphQLスキーマノードにフィールドを追加できる。しかし、例えば全レコードのcomputed field
の平均値を知りたいなどの場合に、全レコードのcomputed field
をクエリしてクライアント側で平均を計算したり (レコードが何千行にもなると大変) 、テーブルのカラムとして値を計算するデータベーストリガーを追加したり (テーブルスキーマの変更が必要だったり、値を再計算するタイミングが難しかったりで大変) する必要があった。
そこで、Hasuraは今回、集約クエリパーサを拡張し、computed field
を集約する方法を知っているものとして認識させることにした。これにより、スカラー型をもつフィールドを集約できるようになった。
query {
articles_aggregate {
aggregate {
avg {
word_count
} # What's the average word count for all articles?
min {
word_count
} # What's the shortest word count of any article?
}
}
}
![chima91](https://res.cloudinary.com/zenn/image/fetch/s--0MVa50Z7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3d8d9aa01d.jpeg)
Caching updates
We’ve made several improvements to our caching features on Hasura Cloud – improved observability, support for Redis clusters on EE, and improved configurations for caching remote schemas and responses to actions.
GraphQLクエリのレスポンスをキャッシュするために使用できるキャッシュレイヤーを提供する。これにより、データソースへのリクエスト数を減らし、アプリケーションのパフォーマンスを向上させることができる。
キャッシュの有効期間を完全に制御でき、必要なときにキャッシュを強制的に更新することもできる。
TTL (Time To Live) が経過すると、キャッシュは無効になり、次のリクエストはキャッシュミスとなる。
query MyProducts @cached(ttl: 120) {
products {
id
name
}
}