Skip to content

Nullability/error awareness improvements #3438

@swizzlr

Description

@swizzlr

Use case

I would like to have a similar feature set to Apollo Kotlin which is adopting semanticNonNull in order to more accurately describe the domain of null because nothing, null because of error, and null because of bubbled error. I would also like the solution to provide ergonomic access to field errors for existing nullable types

Describe the solution you'd like

  • Improved accessors. One or a choice of the following (the choice could be configured through codegen or directive parameters):
    • for a semantically non-null field:
      • var field: String { get throws(GraphQLError) } or
      • var field: Result<String, GraphQLError> or
      • @SemanticNonNull var field: String? where @SemanticNonNull is a property wrapper providing a projected value $field that is of type GraphQLError?
    • for a semantically nullable field:
      • the above accessors, except with optionals where appropriate
  • A way to opt-in to this behavior incrementally via schema directives. For consistency's sake, the Kotlin implementation seems like a sensible starting point: https://www.apollographql.com/docs/kotlin/advanced/nullability#introduction.

Given the spec is still in flux, dropping the server directive and simply offering something like _semanticNonNullField might be a good way to scare off uninitiated users who aren't following the workgroup discussions.

I understand Swift 6 is a big priority right now but at least having this on the roadmap would be a good start, I think!

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenIssues related to or arising from code generationfeatureNew addition or enhancement to existing solutions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions