graphql / graphql/graphql-spec

Allow fields to diverge more?

Open
#820 2 comments 5 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

The current spec rule for overlapping rules allows the following:

Query:
```graphql
{pets {
... on Cat {
friend: catFriend {
catFriendName
}}
... on Dog {
friend: dogFriend {
dogFriendName
}}
}}
```

Schema:
```graphql
type Query {
pets: Pet
}
interface Pet {
name: String
}
type Cat implements Pet {
name: String
catValue: Int
catFriend: CatFriend
}
type CatFriend {
catFriendName: String
}
type Dog implements Pet {
name: String
dogValue: Float
dogFriend: DogFriend
}
type DogFriend {
dogFriendName: String
}

```

This query is allowed because `friend` can't never be executed at the same time because the fragment types are both different Object types and and execution time only one Fragment can be therefore valid.

The `friend` results will have two different "shapes" depending on if it is a `Cat` or `Dog`: One has `dogFriendName`, the other `catFriendName`.

But the following query is not allowed (same schema as above):

```graphql
{pets {
... on Cat {
value: catValue
}
... on Dog {
value: dogValue
}
}}
```
The reason for that is that `catValue` is `Int` but `dogValue` is `Float` and the current rule doesn't allow it.

Different object shapes are already allowed: should the spec allow for more diverging?

The suggestion is to never compare the different result types for fields which can never executed at the same time and therefore allow the second query above.

I would also be interested in the historical context: the current rule was modified in this PR https://github.com/graphql/graphql-spec/pull/120. @leebyron do you have maybe an explanation reasoning for the current rule?

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.