首页 > 解决方案 > 如何在 React Native 中将查询变量传递给我的查询?

问题描述

我正在尝试从 GraphCMS 获取有关我的 API 的信息,但我不确定如何实现这一点。

我还没有尝试过任何事情,因为我不确定如何在我的 React 应用程序的查询中添加一个变量。

const NewsQuery = gql'
  query contentView_b0488406c55f4bf5a28ceb86138c948c($first: Int, $skip: Int, $where: PostWhereInput, $orderBy: PostOrderByInput) {
  contentView_content_b0488406c55f4bf5a28ceb86138c948c: postsConnection(first: $first, skip: $skip, where: $where, orderBy: $orderBy) {
    edges {
      node {
        status
        updatedAt
        createdAt
        id
        title
        slug
        category
        preview
        body
        author
        date
      }
    }
  }
}
' // (change the ' for a tilde)

这是查询变量: {"first":25,"skip":0,"orderBy":null,"where":{"AND":[]}}

我希望获取我 API 上的所有数据,以便将其呈现到我的应用程序中。我正在使用 Apollo 客户端。

标签: javascriptreact-nativegraphqlapolloreact-apollo

解决方案


推荐阅读