Skip to content

Conversation

@benjie
Copy link
Member

@benjie benjie commented Sep 8, 2020

Fixes #641.

As explained in our documentation, root level fields in the GraphQL schema should be nullable if it's possible for them to throw an error: https://www.graphile.org/postgraphile/why-nullable/

However, due to an oversight we made custom queries which return connections non-nullable. This is a bug, and it's embarassing it's been present for 3 years and wasn't spotted until a few weeks ago.

Making a field that was previously non-nullable nullable is technically a breaking change in GraphQL. However, these fields were never truly non-nullable, they could throw an error which (due to the non-null of the root field) could invalidate the entire GraphQL result. Hence I'm classifying this as a bugfix and not a breaking change. If you use TypeScript (or similar) you may have to add a few more ?. operators in your client code to deal with this, other languages may have other ways of dealing with this nullability.

Should you wish to opt out of it, you may do so with the disableIssue641Fix flag:

app.use(postgraphile(DATABASE_URL, SCHEMA, {
  graphileBuildOptions: {
    disableIssue641Fix: true,
  }
}));

You could alternatively selectively change the nullability of your fields with makeChangeNullabilityPlugin.

I'm sorry no-one spotted this sooner!

Fixes #641

@benjie benjie merged commit 131c6ac into v4 Sep 8, 2020
@benjie benjie deleted the fix-non-nullable-root-fields branch September 8, 2020 13:03
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.

Root field for custom query returning connection should not be non-nullable

2 participants