Skip to content

Conversation

martinbonnin
Copy link
Contributor

@martinbonnin martinbonnin commented Nov 27, 2023

Introduce 2 directives used to help working with nullability.

@semanticNonNull

type User {
    # generate email as non-null String in Kotlin even though its type is nullable
    email: String @semanticNonNull
}

@semanticNonNull is the third state found in proposals such as SemanticNonNull except it adds no new GraphQL syntax.

@semanticNonNull can be used in the server schema but also as client extensions:

extend type User @semanticNonNull(field: "email")

@catch

{
  # generate user as `FieldResult<String, Error>` in Kotlin to have access to the error if needed
  user @catch(to: RESULT) {
    name
  }
}

@catch can also be used to fail the whole response in case there is an error in one field:

{
  # fail the response if user or name has an associated error
  user @catch(to: THROW) {
    name
  }
}

Copy link
Contributor

@BoD BoD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hwillson hwillson self-requested a review December 8, 2023 19:28
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @martinbonnin - thanks for working on this!

@martinbonnin martinbonnin merged commit ec27a72 into main Dec 11, 2023
@martinbonnin martinbonnin deleted the nullability branch December 11, 2023 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants