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--graphqlflag, theapp/graphql/directory andgqlgen.ymlwill 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 ProductWhat It Does
Running gofasta g resolver Product patches the existing GraphQL resolver file to add the Product service as a dependency:
| File | Change |
|---|---|
app/graphql/resolver.go | Adds 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.
Related
- gofasta g scaffold — generate all layers including GraphQL
- gofasta g service — generate the service the resolver calls
- gofasta g dto — generate DTOs used by the resolver