使用 graphql-code-generator 生成 React/Apollo 钩子时数组类型是否不正确?

Are array types incorrect when generating React/Apollo hooks with graphql-code-generator?

我想知道在 graphql queries/mutations 中定义的数组,在有效的 graphql 实现中可以是单例或元组,是否被 graphql-codegen 转换为严格的数组类型。这是设计使然吗?

鉴于此架构:

schema {
  query: Query
}

input CustomFieldFilterInput {
  id: ID
  value: String
}

type Query {
  me: User!
  users(ids: [ID], customFields: [CustomFieldFilterInput]): [User]
}

type CustomField {
  id: ID
  value: String
}

interface Node {
  id: ID!
}

type User implements Node {
  id: ID!
  username: String!
  email: String!
  customfields: [CustomField]
}

而这个查询:

query findUserOrUsers($userIds: [ID], $customFields: [CustomFieldFilterInput]) {
  users(ids: $userIds, customFields: $customFields) {
    ...UserFields
  }
}
fragment UserFields on User {
  id
  username
}

graphql-code-generator 将生成:

export type FindUserOrUsersQueryVariables = Exact<{
  userIds?: Maybe<Array<Maybe<Scalars['ID']>>>;
  customFields?: Maybe<Array<Maybe<CustomFieldFilterInput>>>;
}>;

但是在我见过的(大多数)graphql 实现中放入数组或单个值是有效的:

query findUsersString {
  users(ids: 123, customFields: { value: "123", id: 123 }) {
    ...UserFields
  }
}

query findUsersArray {
  users(ids: [123], customFields: [{ value: "123", id: 123 }]) {
    ...UserFields
  }
}

我错过了什么吗?有没有办法覆盖它?

这是一个重现 'issue' 的小回购协议:https://github.com/kweestian/arrays-gql-gen

操作中的 GraphQL 输入支持强制转换,但 codegen 不支持(参见:https://github.com/dotansimha/graphql-code-generator/issues/4888) 我们正在努力解决这个问题,希望在即将发布的版本中修复它 ;)