Sign up for Hasura Newsletter
Loading...

権限を試す

todos テーブル用のGraphQL APIによる権限のテストを始めましょう。

クエリ

では、2つの要求ヘッダーを追加して、データのクエリを行いましょう。

  • x-hasura-role: user
  • x-hasura-user-id: 1
query {
todos {
id
title
is_public
is_completed
user_id
}
}

以下のような応答が得られるはずです。

todoクエリ

ユーザーid 1 に対して、受信した応答がフィルターされることに注意してください。x-hasura-user-id から 2 に値を変更すると、ユーザーid 2 に対してのみデータが返されます。これにより、前のステップで設定した権限が確認されます。

users テーブルでも、同様に権限設定をテストできます。

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin