Fragments

Fragment Targets

Interfaces

Fragments can also target interfaces. In this case, all fields referenced to by a fragment’s selection will apply to any type that implements that interface.
interface Character {
    name: String!
}

type Human implements Character {
    name: String!
    homePlanet: String
}

type Droid implements Character {
    name: String!
    primaryFunction: String
}

fragment characterFragment on Character {
    name
}

Unions

You can also target unions. However, in this case you need to provide an explicit selection set for each concrete type of the union that you want to query.
union FooOrBar = Foo | Bar

fragment Example on FooOrBar {
    ... on Foo {
        foo
    }
    ... ExampleOnBar
}

fragment ExampleOnBar on Bar {
    bar
}