Sign up for Hasura Newsletter
Loading...

测试权限

现在开始通过 GraphQL API 测试todos表的权限。

查询

现在继续,通过添加两个请求头查询数据:

  • x-hasura-roleuser
  • x-hasura-user-id1
query {
todos {
id
title
is_public
is_completed
user_id
}
}

你应该会得到类似这样的响应:

待办事项查询

请注意,你收到的响应已针对用户 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