Skip to Content

gofasta g resolver

Patches the GraphQL resolver to add a service dependency for the given resource. This is used when you want to wire an existing service into the GraphQL layer.

Note: This command requires a GraphQL-enabled project (created with gofasta new --graphql). If your project was created without the --graphql flag, the app/graphql/ directory and gqlgen.yml will not exist, and this command will have nothing to patch.

Usage

gofasta g resolver <Name>

This command has no flags.

Examples

Add Product service dependency to the resolver:

gofasta g resolver Product

What It Does

Running gofasta g resolver Product patches the existing GraphQL resolver file to add the Product service as a dependency:

FileChange
app/graphql/resolvers/resolver.goAdds ProductService field, constructor parameter, and constructor assignment
gqlgen.yml(feature layout only) Adds "<mod>/app/product" to the autobind list so gqlgen binds the schema types against the feature package’s DTOs

Resolver Patch

The resolver struct is updated to include the new service dependency. The qualifier follows the project layout (read from config.yaml’s project.layout):

// app/graphql/resolvers/resolver.go — layered layout package resolvers import ( svcInterfaces "myapp/app/services/interfaces" ) type Resolver struct { UserService svcInterfaces.UserServiceInterface ProductService svcInterfaces.ProductServiceInterface // Added by gofasta g resolver }
// app/graphql/resolvers/resolver.go — feature layout package resolvers import ( userpkg "myapp/app/user" productpkg "myapp/app/product" // Added by gofasta g resolver ) type Resolver struct { UserService userpkg.UserServiceInterface ProductService productpkg.ProductServiceInterface // Added by gofasta g resolver }

When to Use

Use gofasta g resolver when you have already generated the service and GraphQL schema separately and need to wire them together. When using gofasta g scaffold --graphql or gofasta g service --graphql, the resolver patching is handled automatically.

Last updated on