【问题标题】:Write WHERE GraphQL queries with Apollo gql使用 Apollo gql 编写 WHERE GraphQL 查询
【发布时间】:2020-08-01 00:44:54
【问题描述】:

在我的 Playground 上运行此查询非常有效:

 query {
    users(where:{email_contains: "b"}) {
      nodes {
        email
        firstName
      }
      totalCount
    }
  }

但我无法将其转换为这种格式以在我的代码中使用 Apollo gql。如何以可以传递任何我想要的变量的方式修复它?连同where

interface Input {
  email: String;
  firstName: String;
  lastName: String;
}

export const LoadUsersQuery = gql`
  query users(where $email: String!){
    users {
      nodes {
        firstName
        email
      }
      totalCount
    }
  }
`;

从架构中,我知道:

users(
where: UserFilter
): UserConnection
type UserFilter{
  email_contains: string
  firstName_contains: string
}

等等等等

【问题讨论】:

    标签: reactjs typescript graphql apollo react-apollo


    【解决方案1】:

    你需要定义类似的东西

     query {
        usersList($email_contains: string) {
          users(email_contains: $email_contains}) {
            nodes {
              email
              firstName
            }
            totalCount
          }
       }
    }
    

    查看文档了解更多信息:https://www.apollographql.com/docs/tutorial/queries/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-31
      • 2018-10-19
      • 2020-01-06
      • 2021-07-04
      • 1970-01-01
      • 2020-10-13
      • 2020-10-01
      • 2018-03-02
      相关资源
      最近更新 更多