graphql-go
graphql-go copied to clipboard
Allow multiple schemas and resolvers
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.
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?
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).
Are you looking for a kind of schema stitching functionality? Or is this different?
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.