我想知道在 graphql 查询/突变中定义的数组(可以是有效的 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
}
}
我错过了什么吗?有没有办法覆盖这个?
这是一个重现“问题”的小型仓库:https ://github.com/kweestian/arrays-gql-gen