question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle lists and non-null properly

See original GitHub issue

Hello,

Right now gql-gen doesn’t check if ! (non-nullable) applies to a list or elements inside the list:

https://github.com/dotansimha/graphql-code-generator/blob/f3f6e0aa4d482bf407e507267424e363d1d32758/packages/graphql-codegen-core/src/schema/resolve-type.ts#L10

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 .

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
dotansimhacommented, Mar 13, 2018

Fixed in 0.8.16. Thanks @FredyC !

0reactions
shinyaohiracommented, Mar 13, 2018

@FredyC @dotansimha Thank you 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Nulls Inside Lists where List Element Type is @NotNull
ObjectWithStringList defines strings as List, which means that users should expect that the strings inside the list are never null (List<String?> ...
Read more >
Best way to check collections not null & null conditions
In short, let your methods return Collections.emptyList() instead of null and you've got one thing less to worry about. 2. if(list.
Read more >
How to Handle NullPointerException in Java - freeCodeCamp
Before looping over the list, we need to put a null check on the list. If the null check is not present, then...
Read more >
Using nullability in GraphQL
A field can either be nullable or non-null, and this tells you whether or not you ... For example, you can have a...
Read more >
Removing all nulls from a List in Java | Baeldung
User management is very complex, when implemented properly. No surprise here. Not having to roll all of that out manually, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found