Skip to content

RFC: Type composition #1197

@wiegell

Description

@wiegell

Background:

The two proposals above discuss the option on how to write GraphQL in a more DRY fashion. Some concerns raised in those topics include:

  • The GraphQL language is intended for reading over writing
  • We should preserve backwards compatibility at all costs.

Proposal

If instead of changing the way interfaces work and/or are implemented, what if we instead enabled type composition much like Go does it. This could then be an example:

type Humanoid {
  id: String
  name: String
  appearsIn: [Episode]
}

type Human {
  Humanoid
  homePlanet: String
}

type Droid {
  Humanoid
  primaryFunction: String
}

Or multiple types could be combined:

type TimelineItem {
  date: String!
}

type Identifiable {
  id: ID!
  name: string
}

type SomeTimelineEvent {
  TimelineItem
  Identifiable
  eventName: string
}

There are some details that would need to be discussed in particular how field collisions should be handled.
I don't see any real breaking changes in this or problems with backwards compatibility and it would let the typing become more DRY - let me know what you think.

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