Object Spreads In Abstract Scope

Union or interface spreads can be used within the context of an object type fragment, but only if the object type is one of the possible types of that interface or union.

For example, the following fragments are valid:

fragment petFragment on Pet {
  name
  ... on Dog {
    barkVolume
  }
}

fragment catOrDogFragment on CatOrDog {
  ... on Cat {
    meowVolume
  }
}

petFragmentis valid becauseDogimplements the interfacePet.catOrDogFragmentis valid becauseCatis a member of theCatOrDogunion.

By contrast the following fragments are invalid:

fragment sentientFragment on Sentient {
  ... on Dog {
    barkVolume
  }
}

fragment humanOrAlienFragment on HumanOrAlien {
  ... on Cat {
    meowVolume
  }
}

Dogdoes not implement the interfaceSentientand thereforesentientFragmentcan never return meaningful results. Therefore the fragment is invalid. LikewiseCatis not a member of the unionHumanOrAlien, and it can also never return meaningful results, making it invalid.

results matching ""

    No results matching ""