Sign up for Hasura Newsletter
Loading...

获取待办事项 - 查询

您将写的第一个graphql 查询将是获取个人待办事项。您将需要从属于登录用户的数据库中加载待办事项数据。让我们定义一个graphql 查询以获取所需数据。

query getMyTodos {
todos(where: { is_public: { _eq: false} }, order_by: { created_at: desc }) {
id
title
created_at
is_completed
}
}

在 GraphiQL 中针对应用程序数据库尝试此查询,以查看响应是什么样的。

:您需要在查询前传递Authorization: Bearer <token>标头,以获取结果。在通过Auth0登录后,该令牌会在用户界面中自动填充。

该查询是实际的graphql查询,我们将在我们的React应用中使用,因此对其进行测试是为了确保它能按预期运行。

现在让我们将这个graphql查询集成到我们的React应用程序中。

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