graphql / graphql/graphql-spec

Allow merging nullable and non-null fields

Open
#1,204 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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
```graphql
union ExternalResource = LinkedResource | ResourceCitation

type LinkedResource {
title: String!
link: String
}

type ResourceCitation {
citation: String!
link: String
}
```
and this selection set
```graphql
{
... on LinkedResource {
link
}
... on ResourceCitation {
link
}
}
```
The selection set is valid (`FieldsInSetCanMerge` returns `true` on it).
Suppose the schema evolves:
```graphql
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.