aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/plugin/resolvergen
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-04-09 21:45:24 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-04-09 21:45:24 +0200
commit26b5343e2160de172969e6834074cf8482ceb845 (patch)
tree04f27aa660a903d65f7b3d951bd1c6f92c59c0c3 /vendor/github.com/99designs/gqlgen/plugin/resolvergen
parent6e8496f4c1767ca8a8b95716a04f1b492bef7397 (diff)
downloadgit-bug-26b5343e2160de172969e6834074cf8482ceb845.tar.gz
Update Gopkg.*
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/plugin/resolvergen')
-rw-r--r--vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go53
-rw-r--r--vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl40
2 files changed, 93 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go
new file mode 100644
index 00000000..00a6d5c9
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go
@@ -0,0 +1,53 @@
+package resolvergen
+
+import (
+ "log"
+ "os"
+
+ "github.com/99designs/gqlgen/codegen"
+ "github.com/99designs/gqlgen/codegen/templates"
+ "github.com/99designs/gqlgen/plugin"
+ "github.com/pkg/errors"
+)
+
+func New() plugin.Plugin {
+ return &Plugin{}
+}
+
+type Plugin struct{}
+
+var _ plugin.CodeGenerator = &Plugin{}
+
+func (m *Plugin) Name() string {
+ return "resovlergen"
+}
+func (m *Plugin) GenerateCode(data *codegen.Data) error {
+ if !data.Config.Resolver.IsDefined() {
+ return nil
+ }
+
+ resolverBuild := &ResolverBuild{
+ Data: data,
+ PackageName: data.Config.Resolver.Package,
+ ResolverType: data.Config.Resolver.Type,
+ }
+ filename := data.Config.Resolver.Filename
+
+ if _, err := os.Stat(filename); os.IsNotExist(errors.Cause(err)) {
+ return templates.Render(templates.Options{
+ PackageName: data.Config.Resolver.Package,
+ Filename: data.Config.Resolver.Filename,
+ Data: resolverBuild,
+ })
+ }
+
+ log.Printf("Skipped resolver: %s already exists\n", filename)
+ return nil
+}
+
+type ResolverBuild struct {
+ *codegen.Data
+
+ PackageName string
+ ResolverType string
+}
diff --git a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl
new file mode 100644
index 00000000..7d95e690
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl
@@ -0,0 +1,40 @@
+// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.
+
+{{ reserveImport "context" }}
+{{ reserveImport "fmt" }}
+{{ reserveImport "io" }}
+{{ reserveImport "strconv" }}
+{{ reserveImport "time" }}
+{{ reserveImport "sync" }}
+{{ reserveImport "errors" }}
+{{ reserveImport "bytes" }}
+
+{{ reserveImport "github.com/99designs/gqlgen/handler" }}
+{{ reserveImport "github.com/vektah/gqlparser" }}
+{{ reserveImport "github.com/vektah/gqlparser/ast" }}
+{{ reserveImport "github.com/99designs/gqlgen/graphql" }}
+{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }}
+
+type {{.ResolverType}} struct {}
+
+{{ range $object := .Objects -}}
+ {{- if $object.HasResolvers -}}
+ func (r *{{$.ResolverType}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} {
+ return &{{lcFirst $object.Name}}Resolver{r}
+ }
+ {{ end -}}
+{{ end }}
+
+{{ range $object := .Objects -}}
+ {{- if $object.HasResolvers -}}
+ type {{lcFirst $object.Name}}Resolver struct { *Resolver }
+
+ {{ range $field := $object.Fields -}}
+ {{- if $field.IsResolver -}}
+ func (r *{{lcFirst $object.Name}}Resolver) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} {
+ panic("not implemented")
+ }
+ {{ end -}}
+ {{ end -}}
+ {{ end -}}
+{{ end }}