captbaritone / grats

Implementation-First GraphQL for TypeScript

Home Page:https://grats.capt.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support defining interfaces by extending classes

captbaritone opened this issue · comments

I had originally opted not to support defining interfaces via classes because of the mismatch between TypeScript having single inheritance and GraphQL having multiple inheritance. You can't express:

type User implements Person, Node {
  # ...
}

using only class inheritance with TypeScript. That said, people do have inheritance setup in their TypeScript code bases which make sense as interfaces as they expose that same code in GraphQL. Following this design principle, we ought to support this for the cases where users have such code.

There will be some challenges:

  1. How do we figure out from TypeScript which classes extend which other classes. Note that we need to include transitive cases. This may impact our incremental compilation strategy.
  2. We need to figure out how overrides work and ensure their ordering is applied correctly. If the concrete class and extended class both implement a field, which one wins? With multiple inheritance this gets tricky.