-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Example of separating schema and resolvers for a large project structure with for multi-team setup #3631
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
Example of separating schema and resolvers for a large project structure with for multi-team setup #3631
Conversation
…ure with for multi-team setup
@@ -0,0 +1,17 @@ | |||
module github.com/corelight/integration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind if we rename this something that matches the directory like:
module github.com/corelight/integration | |
module github.com/99designs/gqlgen/_examples/large-project-structure/integration |
Some of the people who are new to Go have their minds blown when the directory and module names don't match.
Thanks! Also, some larger installations combine other options like |
Just reading some of the comment descriptions on both Hopefully, one of us will get some free time available soon to writeup some more detailed documentation on configs like that and just structuring a project for scale. I definitely think theres a need and the community will benefit from it 😉 Edit: It looks like |
I wonder if some members of the community who have experience using gqlgen in larger orgs or teams might offer guidance here? For a single gqlgen project, what gqlgen config works best really changes at a few key points during the course of that project's normal growth and evolution. For instance:
However, some will instead choose to adopt GraphQL Federation and split into multiple gqlgen instances before one of these growth points is even reached. |
Oh, hey, I forgot to mention another large scale config option is to limit the concurrency for resolvers:
|
This MR includes an additional example of how it is possible to separate schema and resolvers into separate packages, even external packages, allowing support for larger projects. Hoping this kind of dovetails in the this MR: #3595
The project has the following layout:
The main package is the centralized graph and will consume the schema files from both the
shared
and theintegration
packages.The main package, after initial
generate
command, has commented out theresolver:
section in thegqlgen.yml
file. This prevents the main package from generating all resolvers, which we would like other teams to be able to manage. Whengenerate
is ran, it will still generate all model information in the main package, which the external packages can manage.Additionally, the main package in the
resolver.go
file tries to lift the generated interface for external resolvers into its own interface calledExternalQueryResolver
. This interface is then embedded in in theResolver
like so:This allows the
RootResolver
to still function as it should but lifts some of theMutationResolver
andQueryResolver
interfaces that were generated up in a way that other teams can implement the resolver.Then upon initialization, you can define the
ExternalQueryResolver
from another package like so:It was challenging to find a good way to provide a balance of gqlgen built-in functionality in a way that allowed for ease of use, while also allowing still providing some autonomy to other teams.
There are very few discussions on how this is doable and I couldn't really find any examples of doing this in practice. I wanted to put this up in hopes it would help others...or at the very least call out any major flaws that may exist with this.
Describe your PR and link to any relevant issues.
I have: