Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GraphQL Directives] MissingDefaultException is sometimes unreasonable #1328

Open
Leksat opened this issue Apr 5, 2023 · 0 comments
Open
Labels
drupal Concerns Drupal backends.

Comments

@Leksat
Copy link
Member

Leksat commented Apr 5, 2023

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]!
}
@Leksat Leksat added the drupal Concerns Drupal backends. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drupal Concerns Drupal backends.
Projects
None yet
Development

No branches or pull requests

1 participant