gqlgen-plugins

module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: Apache-2.0

README

Go Report Card Build status Quality Gate Status

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)
	}
}

Directories

Path Synopsis
Package bulkgen provides a gqlgen plugin to generate bulk resolver functions used for mutations
Package bulkgen provides a gqlgen plugin to generate bulk resolver functions used for mutations
Package resolvergen provides the a resolver template for the gqlgen resolver plugin to override the default resolver functions
Package resolvergen provides the a resolver template for the gqlgen resolver plugin to override the default resolver functions
Package searchgen provides the the ability to generate a search resolver
Package searchgen provides the the ability to generate a search resolver

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL