Skip to content

Integrating gqlgen into a Feature-Based Project Structure #3761

@datznt

Description

@datznt

I'm working on a Go project that utilizes a Feature-Based (also known as Domain-Driven Design or Vertical Slices) project structure. Our goal is for each feature (e.g., users, products, orders) to encapsulate all its related components, including GraphQL schema definitions, resolvers, models, and business logic.

A typical project structure for us looks like this:

.
├── go.mod
├── go.sum
├── main.go
└── internal/
    ├── app/  (main application setup)
    ├── config/
    └── features/
        ├── users/
        │   ├── graph/
        │   │   ├── users.graphqls
        │   │   ├── users.resolvers.go
        │   │   └── users.models.go
        │   ├── service/
        │   │   └── users.go
        │   └── repository/
        │       └── users.go
        ├── products/
        │   ├── graph/
        │   │   ├── products.graphqls
        │   │   ├── products.resolvers.go
        │   │   └── products.models.go
        │   ├── service/
        │   └── repository/
        └── orders/
            ├── graph/
            │   ├── orders.graphqls
            │   ├── orders.resolvers.go
            │   └── orders.models.go
            ├── service/
            └── repository/

How can gqlgen be instructed to generate resolvers and models directly into their respective feature-specific directories instead of a single top-level graph folder? For instance, I'd like users.resolvers.go and users.models.go to be generated within features/users/graph/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions