timkendall / tql

A GraphQL query builder for TypeScript. Avoid the pain of codegen.
https://tql.dev
MIT License
133 stars 6 forks source link

Confused by non-optional array types? #106

Open geelen opened 2 years ago

geelen commented 2 years ago

With this input:

input CreateUserInput {
  username: String!
  email: String!
  avatar: String
  posts_ref: [ID!]!
}

input UpdateUserInput {
  email: String
  avatar: String
  posts_ref: [ID!]
}

I get this output:

export interface CreateUserInput {
  readonly username: string;
  readonly email: string;
  readonly avatar?: string;
  readonly posts_ref: string; // <- error here
}

export interface UpdateUserInput {
  readonly email?: string;
  readonly avatar?: string;
  readonly posts_ref?: string[];
}

Something about posts_ref being non-optional? Not sure if this is fixed in the v1 rc, I'm still using 0.8.0

timkendall commented 2 years ago

Yep this is fixed in the latest RC. At this point I would recommend switching to it if you can (let me know if there is anything preventing you from doing so and I can help).

Here's the output from running npx @timkendall/tql-gen <schema>:

export interface ICreateUserInput {
  username: string;
  email: string;
  avatar?: string;
  posts_ref: string[];
}

export interface IUpdateUserInput {
  email?: string;
  avatar?: string;
  posts_ref?: string[];
}