Hello,
Right now gql-gen doesn't check if ! (non-nullable) applies to a list or elements inside the list:
As a result, the list is considered required even when it isn't:
GraphQL type | Expected Typescript Type | Actual Generated Type
------------ | ------------- | -------------
[String] | (string \| null)[] \| null | string[] \| null
[String]! | (string \| null)[] | string[]
[String!] | string[] \| null | string[]
[String!]!| string[] | string[]
More generally, GraphQL allows arbitrary nesting of list and non-null modifiers according to http://graphql.org/learn/schema/#lists-and-non-null .
I ran into the same problem.
Yea just encountered this too. Should be pretty simple fix seeing that code, something like lastIndexOf(']!') should be sufficient in my opinion.
Unfortunately, it feels like @dotansimha is rather busy lately, he is not responding to issues much. Looks like custom fork will be necessary, but that's going to be a pain considering monorepo structure.
I made the PR. It's a working solution, I have a rather big schema and nothing was broken by that change.
@FredyC Hi, I'd like to try your PR. Could you tell me a little bit about how to use it in my project.
package.json
"graphql-code-generator": "git://github.com/FredyC/graphql-code-generator.git#FredyC-patch-1",
I executed yarn install, but gql-gen command was not created in ./node_modules/.bin/.
@shinyaohira I don't think you can do that because of a monorepo structure which includes multiple packages that need to be built. However, looks like that PR will be merged soon, just be a little patient :)
Fixed in 0.8.16. Thanks @FredyC !
Also, @shinyaohira, @FredyC is right, you can't use it from git. But you can compile it locally and try to use it this way...
@FredyC @dotansimha Thank you 馃檶
Most helpful comment
Fixed in 0.8.16. Thanks @FredyC !