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/resolver.goAdds productService field and constructor parameter

Resolver Patch

The resolver struct is updated to include the new service dependency:

// app/graphql/resolver.go package graphql import ( svcInterfaces "myapp/app/services/interfaces" ) type Resolver struct { userService svcInterfaces.UserService productService svcInterfaces.ProductService // 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