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.

schema generator should fail if input types with nullable fields do not define a default value

See original GitHub issue

Discussed in https://github.com/ExpediaGroup/graphql-kotlin/discussions/1525

<div type='discussions-op-text'>

Originally posted by Anthonyzou August 22, 2022 With the changes in version 6.2.0 and above, input types that could be nullable did not require a default value.

This code would work before version 6.2.0

@GraphQLDescription("")
data class Book(
    val title: String?
)

Now I get the error No argument provided for a required parameter: parameter #0... unless I change the input type to:

@GraphQLDescription("")
data class Book(
    val title: String? = null
)
```</div>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
samuelAndaloncommented, Aug 24, 2022

we can add more custom logic here https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/hooks/SchemaGeneratorHooks.kt#L144

adding this logic when unwrapped is GraphQLInputObjectType

type.jvmErasure.primaryConstructor?.parameters?.forEach { param ->
  if (param.type.isMarkedNullable && !param.isOptional) {
   // just for demo, we can use a custom exception
    throw RuntimeException("${type.jvmErasure.simpleName}.${param.name} is nullable but not optional")
  }
}

@xenomachina i would assume you did it in the didGenerateGraphQLType hook ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent behavior for defaultValue and nullable on input ...
A field in an input type or argument list is set to nullable: true , if a default is provided, even when the...
Read more >
Using nullability in GraphQL
A field can either be nullable or non-null, and this tells you whether or not you could receive a null value when you...
Read more >
Problems with adding NOT NULL columns or making nullable ...
I need to add a new column, make it non-NULL, but not provide a permanent default value - the users should always fill...
Read more >
use of "default" in avro schema - Stack Overflow
Schema says that: if "age" field is missing, then consider value as -1. Likewise for "name" field. Now, if I try to construct...
Read more >
Nullability - GraphQL Nexus
When you make an input nullable then Nexus will alter its TypeScript type ... is for the case where the client simply did...
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