rmosolgo / graphql-ruby

Ruby implementation of GraphQL
http://graphql-ruby.org
MIT License
5.38k stars 1.39k forks source link

Support `extend` in Schema.from_definition? #1600

Closed rmosolgo closed 5 years ago

rmosolgo commented 6 years ago

The GraphQL SDL has a concept of "extending" type definitions, for example:

http://facebook.github.io/graphql/June2018/#sec-Object-Extensions

Should we support this in GraphQL-Ruby? I have heard several folks who use Schema.from_definition to build their schemas, would this be helpful?

cjoudrey commented 6 years ago

As a first step I'll take a stab at adding support for extend ... to the lexer and parser.

Tybot204 commented 5 years ago

Have there been any latest thoughts on implementing this?

I have a system of many microservices, each implementing their own GQL schema. These schemas are stitched together in a gateway service that exposes all of the queries / mutations to clients in one convenient schema. extend would help greatly in allowing me to define resolvers that return types from another service's schema!

Example:

# Defined in service A
type User {
  id: ID!
  name: String!
}

extend type Account {
  user: User!
}

# Defined in service B
type Account {
  id: ID!
  type: String!
}

extend type User {
  accounts: [Account]!
}

I'm not super familiar with the inner workings of this gem, but I'll start digging in and seeing what needs to be added to make this happen!

EDIT: Digging into this a bit more, I realized I don't even know what the DSL would look like for this. I'm going to take a stab at what exactly we might want to support with this.

rmosolgo commented 5 years ago

Hi! No, as far as I know, there hasn't been more thought in implementing it. Personally, I don't use the Schema.from_definition feature, so I don't work on it much 😬. (Although I know plenty of folks use it for their whole schema!)

cjoudrey commented 5 years ago

After implementing the lexer/parser pieces of extend, I remember taking a look at GraphQL.js to see how extend works there. Reading the implementation one thing that seemed important is that extending a schema should not alter the existing instance of the schema, but rather return a new schema. I probably won't have time to implement the rest of this in the near future, but I'd happily help review any PR that adds this functionality.

rmosolgo commented 5 years ago

I don't have plans to work on this, so I'm closing this issue. It'd definitely be a nice addition to the library, though!