Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple schemas and resolvers #184

Open
mytototo opened this issue Mar 23, 2018 · 4 comments
Open

Allow multiple schemas and resolvers #184

mytototo opened this issue Mar 23, 2018 · 4 comments

Comments

@mytototo
Copy link

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.

@tonyghita
Copy link
Member

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?

@mytototo
Copy link
Author

mytototo commented Mar 31, 2018

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).

@tonyghita
Copy link
Member

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

@RaniSputnik
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants