Graphql-codegen typescript types for ImgixParams are too strict

Hi! We (think we) found a problem with the GraphQL schema for the ImgixParams and the new X-Eclude-Invalid header:

Since it’s all a bit complicated, I went ahead and opened a reproduction repo: GitHub - peerigon/datocms-codegen-imgix-repro: datocms-codegen-imgix-repro

Summary:

  • We generate typescript types and a request SDK from Dato’s GQL schema using graphql-codegen, typescript-operations and typescript-graphql-request
  • In order to have stricter types we use the new X-Exclude-Invalid header in conjunction with avoidOptionals

Result: The type for ImgixParams is too strict, since all of the properties that are possible as imgix params are resolved as required.

A quick “workaround” would be some post processing hook to wrap the whole type in Partial<…> but it seems like an unnecessary hack.

Thanks for your support, keep up the great work.

2 Likes

Hello @moritz.jacobs ,

Thank you for the detailed report and for the repository for reproduction of the issue!
I forwarded this to the development team and i’ll get back to you as soon as we have any updates.

1 Like

@moritz.jacobs I’m not sure what should we do differently on our end. :confused: This is the current definition of the ImgixParams GraphQL input type:

input ImgixParams {
  ar: String
  auto: [ImgixParamsAuto!]
  bg: String
  // ...etc...
}

Every transformation field of the input type is defined as optional. Of course if you enable an option called avoidOptionals on the codegen tool… they’ll became non optional :smiley:

Let us know how we can help!

Thanks for your reply @s.verna! Much appreciated.

We solved this on our side to configure codegen to not avoidOptionals for input types likes this:

						avoidOptionals: {
							field: true,
							inputValue: false,
							object: true,
							defaultValue: true,
						}

This gives us the types we want.

More info:

2 Likes