Skip to content

Allow fields to diverge more? #820

@andimarek

Description

@andimarek

The current spec rule for overlapping rules allows the following:

Query:

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

Schema:

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):

  {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 #120. @leebyron do you have maybe an explanation reasoning for the current rule?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions