aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/api/generate.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-05 22:03:19 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-05 22:33:03 +0100
commit1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6 (patch)
treee088b0fa43058afde1db71541d8fcb4b94905d6e /vendor/github.com/99designs/gqlgen/api/generate.go
parentf093be96e98284580d61664adecd0a2ff8b354e4 (diff)
downloadgit-bug-1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6.tar.gz
migrate to go modules
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/api/generate.go')
-rw-r--r--vendor/github.com/99designs/gqlgen/api/generate.go78
1 files changed, 0 insertions, 78 deletions
diff --git a/vendor/github.com/99designs/gqlgen/api/generate.go b/vendor/github.com/99designs/gqlgen/api/generate.go
deleted file mode 100644
index 3256bdc3..00000000
--- a/vendor/github.com/99designs/gqlgen/api/generate.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package api
-
-import (
- "syscall"
-
- "github.com/99designs/gqlgen/codegen"
- "github.com/99designs/gqlgen/codegen/config"
- "github.com/99designs/gqlgen/plugin"
- "github.com/99designs/gqlgen/plugin/modelgen"
- "github.com/99designs/gqlgen/plugin/resolvergen"
- "github.com/99designs/gqlgen/plugin/schemaconfig"
- "github.com/pkg/errors"
- "golang.org/x/tools/go/packages"
-)
-
-func Generate(cfg *config.Config, option ...Option) error {
- _ = syscall.Unlink(cfg.Exec.Filename)
- _ = syscall.Unlink(cfg.Model.Filename)
-
- plugins := []plugin.Plugin{
- schemaconfig.New(),
- modelgen.New(),
- resolvergen.New(),
- }
-
- for _, o := range option {
- o(cfg, &plugins)
- }
-
- for _, p := range plugins {
- if mut, ok := p.(plugin.ConfigMutator); ok {
- err := mut.MutateConfig(cfg)
- if err != nil {
- return errors.Wrap(err, p.Name())
- }
- }
- }
- // Merge again now that the generated models have been injected into the typemap
- data, err := codegen.BuildData(cfg)
- if err != nil {
- return errors.Wrap(err, "merging failed")
- }
-
- if err = codegen.GenerateCode(data); err != nil {
- return errors.Wrap(err, "generating core failed")
- }
-
- for _, p := range plugins {
- if mut, ok := p.(plugin.CodeGenerator); ok {
- err := mut.GenerateCode(data)
- if err != nil {
- return errors.Wrap(err, p.Name())
- }
- }
- }
-
- if err := validate(cfg); err != nil {
- return errors.Wrap(err, "validation failed")
- }
-
- return nil
-}
-
-func validate(cfg *config.Config) error {
- roots := []string{cfg.Exec.ImportPath()}
- if cfg.Model.IsDefined() {
- roots = append(roots, cfg.Model.ImportPath())
- }
-
- if cfg.Resolver.IsDefined() {
- roots = append(roots, cfg.Resolver.ImportPath())
- }
- _, err := packages.Load(&packages.Config{Mode: packages.LoadTypes | packages.LoadSyntax}, roots...)
- if err != nil {
- return errors.Wrap(err, "validation failed")
- }
- return nil
-}