Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 2.08 KB

README.md

File metadata and controls

59 lines (45 loc) · 2.08 KB

Go Report Card Build status Quality Gate Status License: Apache 2.0

gqlgen-plugins

gqlgen provides a way to hook into the gqlgen code generation lifecycle. This repo contains several hooks that can be used:

  • bulkgen
  • resovlergen
  • searchgen

ResolverGen

This hook will override the default generated resolver functions with the templates for CRUD operations.

BulkGen

Creates resolvers to do bulk operations for a schema for both bulk input or a csv file upload input.

SearchGen

Creates search resolvers to search on fields within the ent schema. You must pass in the package import name of the generated ent code, e.g. github.com/theopenlane/core/internal/ent/generated. If the package is not named generated it is added as an alias.

api.AddPlugin(searchgen.New("github.com/theopenlane/core/internal/ent/generated")), // add the search plugin

Usage

Add the plugins to the generate.go main function to be included in the setup:

func main() {
	cfg, err := config.LoadConfigFromDefaultLocations()
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
		os.Exit(2)
	}

	if err := api.Generate(cfg,
		api.ReplacePlugin(resolvergen.New()), // replace the resolvergen plugin
		api.AddPlugin(bulkgen.New()),         // add the bulkgen plugin
		api.AddPlugin(searchgen.New("github.com/theopenlane/core/internal/ent/generated")), // add the search plugin
	); err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(3)
	}
}