1

I am wondering if arrays defined in graphql queries/mutations, which can be either singletons or tuples in valid graphql implementation get converted to strict array types by graphql-codegen. Is this is by design ?

Given this schema:

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]
}

And this query:

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

graphql-code-generator will generate:

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

But putting in an array or a single value is valid in (most) graphql implementations I've seen:

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

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

Am I missing something ? Is there a way to override this ?

Here is a small repo that reproduces the 'issue': https://github.com/kweestian/arrays-gql-gen

1 Answer 1

2

GraphQL inputs in operations supports coercion, but codegen doesn't (see: https://github.com/dotansimha/graphql-code-generator/issues/4888) We are working on it and hope to fix that in upcoming versions ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.