gqlgen
gqlgen copied to clipboard
Generated resolver go files are not going into sub packages using `follow-schema`
Hi there,
What happened?
I have my .graphql
files organised into sub-directories, eg company
, user
etc
server/schema/
company/
company.queries.graphql
company.mutations.graphql
user/
user.queries.graphql
user.mutations.graphql
Though I am using follow-schema
option (see below) to generate resolvers, generated resolver go files are not being organised into sub packages (under resolver
package). Instead all of them are put directly into main resolver directory.
server/resolver/
company.queries.go
company.mutations.go
user.queries.go
user.mutations.go
resolver.go
Here is my gqlgen.yml
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- server/schema/**/*.graphql
# Where should the generated server code go?
exec:
filename: server/generated/generated.go
package: generated
# Uncomment to enable federation
# federation:
# filename: server/generated/federation.go
# package: generated
# Where should any generated models go?
model:
filename: server/model/models_gen.go
package: model
# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: server/resolver
package: resolver
# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
# struct_tag: json
# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false
# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true
# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
- "github.com/<Account>/<Repo>/server/types"
# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
What did you expect?
Generated resolver go files organised into sub-packages
server/resolver/
company/
company.queries.go
company.mutations.go
user/
user.queries.go
user.mutations.go
resolver.go
Minimal graphql.schema and models to reproduce
Nothing to do with schema and model I believe. Can be reproduced with any two or more .graphql
files organised into sub-directories.
versions
-
go run github.com/99designs/gqlgen version
: v0.17.2 -
go version
: 1.18
This is a much needed feature.
+1 for this
This is exactly what I expected follow-schema
to do and is crucial for those of us who like to split our packages up by domain and not function.
This is also important for the build cache. We've gotten to a huge circuit and compiling after regeneration takes 20+ gigabytes of RAM and about 30 minutes of real time on the Apple M1. If you break up the resolvers into different packages it will work faster
+1