Generics

Generics can be used to reuse types or inputs that have some small subset of the fields slightly different from each other:

Open in sandbox

Source GraphQXL Compiled GraphQL
type Generic<T> {
    foo: T
}

type FooString = Generic<String!>

type FooInt = Generic<Int!>
type FooString {
    foo: String!
}

type FooInt {
    foo: Int!
}

Notice how the generic type definition is omitted from the generated GraphQL. If a type or an input is declared with generic type parameters, it will not be present in the generated GraphQL.

It can even be combined with inheritance:

Open in sandbox

Source GraphQXL Compiled GraphQL
type Book {
    title: String!
}

type List<T> {
    first: T
    last: T
    content: [T!]!
}

type ListOfBooksWithLength {
    ...List<Book>
    length: Int!
}
type Book {
    title: String!
}

type ListOfBooksWithLength {
    first: Book
    last: Book
    content: [Book!]!
    length: Int!
}