graphql-spec icon indicating copy to clipboard operation
graphql-spec copied to clipboard

Allow merging nullable and non-null fields

Open ornamental opened this issue 2 months ago • 1 comments

It is widely believed that, in the process of schema evolution, changing field type from T to T! is not a breaking change. A counter-example is given below (a like of it was encountered in a real-life application).

Consider the following [partial] schema

union ExternalResource = LinkedResource | ResourceCitation

type LinkedResource {
  title: String!
  link: String
}

type ResourceCitation {
  citation: String!
  link: String
}

and this selection set

{
  ... on LinkedResource {
    link
  }
  ... on ResourceCitation {
    link
  }
}

The selection set is valid (FieldsInSetCanMerge returns true on it). Suppose the schema evolves:

type LinkedResource {
  title: String!
  link: String!
}

The selection set given above is now invalid, since SameResponseShape (step 3a) returns false.

Since T! is naturally embedded in T, it seems reasonable to allow such 'compatible' fields to be queried without forcing aliasing upon API clients (and possibly causing a breaking change where, semantically, there is none).

The problem looks related to these recently opened issues: https://github.com/graphql/graphql-spec/issues/1171 https://github.com/graphql/graphql-spec/issues/1169

ornamental avatar Nov 03 '25 21:11 ornamental

I think there’s some support for this position already; would you like to step up and be the champion of it? Read about our contribution process here:

https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md

benjie avatar Nov 04 '25 10:11 benjie