Skip to content

[GraphQL Directives] MissingDefaultException is sometimes unreasonable #1328

@Leksat

Description

@Leksat

Problem

Error:

Missing @default directive for type Page.
Either add a @default directive to Page or turn all occasions of 'Page!' into 'Page'.

(source)

But I want to keep

type Query {
  allPages: [Page!]! # <= this occasion of Page non-nullable
  page(id: ID!): Page
}

And I don't want to add a default value for the Page type.

Possible solution 1

Instead, I maybe can do something like this:

type Query {
  allPages: [Page!]! @a @b @c @filterNulls
}

where
@a @b @c are any resolvers returning the list of nullable objects and
@filterNulls is a new resolver that filters out nulls from the list

Then we can improve the logic of DirectiveInterpreter to take @filterNulls into account and ignore this exact type occasion.

Downsides:

  • We will invest time
  • It will make the DirectiveInterpreter code more complicated

Possible solution 2 (already in use)

Do nothing.

type Query {
  allPages: [Page]!
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    drupalConcerns Drupal backends.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions