graphql / graphql/graphql-spec

RFC: Type composition

Open
#1,197 14 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

## Background:

- https://github.com/graphql/graphql-spec/issues/533
- https://github.com/graphql/graphql-spec/issues/500

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](https://gobyexample.com/struct-embedding). 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.