99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.87k stars 1.15k forks source link

Generated resolver go files are not going into sub packages using `follow-schema` #2093

Open Junaid-Ahm opened 2 years ago

Junaid-Ahm commented 2 years ago

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

sarmad4444 commented 2 years ago

This is a much needed feature.

dotdevio commented 2 years ago

+1 for this

andrioid commented 1 year ago

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.

flymedllva commented 1 year ago

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

saschacontes commented 12 months ago

+1

eugene-suvorov commented 4 months ago

+1

demeralde commented 2 months ago

Did anyone find a decent workaround for this?

momilo commented 1 day ago

Question to the maintainers - is this a feature whose addition would be welcomed? If yes, would you be open to somebody opening a PR with such functionality (and helping with review/getting it across)?

Just trying to sense out your view, before dedicating time to it. Thank you in advance for voicing your thoughts!