Closed5

Hasura July 2023 Newsletter 個人的まとめ

chima91chima91

Input validations for mutations
You can now perform custom input validations for mutations using external webhooks.

v2.29.0以上でサポートされる機能。

多くの場合、データを挿入・削除・更新する前に、GraphQLミューテーションの入力引数に対してバリデーションを行う必要がある。
そこでHasuraは複雑な検証ロジックを実行するために、ミューテーションの入力引数をHTTP Webhookにルーティングする。

[table-name].yaml
- 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

https://hasura.io/docs/latest/schema/postgres/input-validations

chima91chima91

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のバージョンアップデート

https://hasura.io/docs/latest/data-federation/schema-registry

chima91chima91

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でサポートされる機能。

集約クエリには、数値クエリ (sumavgなど) 、比較クエリ (maxmin) の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?
    }
  }
}

https://hasura.io/blog/introducing-aggregation-queries-for-computed-fields

chima91chima91

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
  }
}

https://hasura.io/docs/latest/caching/overview

このスクラップは2023/07/22にクローズされました