graphql-go icon indicating copy to clipboard operation
graphql-go copied to clipboard

Allow multiple schemas and resolvers

Open mytototo opened this issue 6 years ago • 4 comments

Hi,

I'm writing Go / GraphQL applications and I'm looking to make everything a "module" / "plugin".

Is there any plan to allow slice of schemas and resolvers for MustParseSchema so we can import GraphQL "modules" and make them live on the same GraphQL mux?

Thanks.

mytototo avatar Mar 23 '18 10:03 mytototo

Hey, thanks for the question. I'm not sure I completely understand what we are trying to achieve with allowing multiple schema strings... can you expand your question a bit?

tonyghita avatar Mar 30 '18 16:03 tonyghita

Hi @tonyghita. Sure.

I'm currently using Go and this GraphQL library for multiple projects. Some of them share the same schemas and resolvers (user management for example).

What I'm trying to achieve is to make the "user management" feature a plugin (or even a Go plugin) so I can simply import it and use its schema and resolvers whenever I need in my projects. This way, I avoid code duplication by allowing plugins / packages of GraphQL schemas and resolvers.

The goal here would be for the library to merge strings of schemas (I got that part easily) but also merging root resolvers (I can't succeed for now).

mytototo avatar Mar 31 '18 09:03 mytototo

Are you looking for a kind of schema stitching functionality? Or is this different?

tonyghita avatar Apr 06 '18 04:04 tonyghita

Hey @mytototo, if I understand you correctly merging root resolvers could be done by type embedding. Eg.

We have two resolvers, our UserManagementResolver and our ProductsResolver

type UserManagementResolver struct {}
func (r *UserManagementResolver) User() (*userResolver, error) { ... }
func (r *UserManagementResolver) Register(args struct{ Username string }) (*userResolver, error) { ... }

type ProductsResolver struct {}
func (r *ProductsResolver) GetAll() ([]*productResolver, error) { ... }

Now when we want to create a root resolver, we can embed these other two "plugin" resolvers.

type RootResolver struct {
    UserManagementResolver
    ProductsResolver
}

And our RootResolver will be able to resolve all of the queries / mutations from both the UserManagementResolver and the ProductsResolver. Of course, these two resolvers could live in separate packages too.

Hopefully I've understood what you're after.

RaniSputnik avatar Apr 08 '18 11:04 RaniSputnik