Skip to content

Change @semanticNonNull.level and @catch.level default to be 0? #40

Closed
@martinbonnin

Description

@martinbonnin

Follow up from comment from @captbaritone on discord.
The current description of @semanticNonNull states that:

"""
...
If `level` is null, all levels are semantically non null.
...
"""
directive @semanticNonNull(field: String = null, level: Int = null) repeatable on FIELD_DEFINITION | OBJECT

One advantage is that it's more compact in list cases. Compare:

type User {
  # make all levels nullable with a single directive
  friends: [Users] @semanticNonNull
}

to

type User {
  # making all levels nullable requires several directives
  friends: [Users] @semanticNonNull(level: 0) @semanticNonNull(level: 1)
}

A drawback is that it makes the directive definition more complex (level is now nullable, this is surprising).

Another drawback is that it opens the door to ambiguous behaviour:

type User {
  # should that be an error? a warning?
  friends: [Users!] @semanticNonNull
}

Since @semanticNonNull applies to all levels above, it's also applying to User!, should that be an error?

There's a tradeoff of compactness vs explicitness. Since @semanticNonNull is itself verbose already maybe the extra verbosity is worth it if it makes things more explicit.

See also: apollographql/apollo-kotlin#5462

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions