-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package stubgen | ||
|
||
import ( | ||
"github.com/99designs/gqlgen/codegen" | ||
"github.com/99designs/gqlgen/codegen/templates" | ||
"github.com/99designs/gqlgen/plugin" | ||
) | ||
|
||
func New(filename string, typename string) plugin.Plugin { | ||
return &Plugin{filename: filename, typeName: typename} | ||
} | ||
|
||
type Plugin struct { | ||
filename string | ||
typeName string | ||
} | ||
|
||
var _ plugin.CodeGenerator = &Plugin{} | ||
|
||
func (m *Plugin) Name() string { | ||
return "stubgen" | ||
} | ||
func (m *Plugin) GenerateCode(data *codegen.Data) error { | ||
return templates.Render(templates.Options{ | ||
PackageName: data.Config.Resolver.Package, | ||
Filename: m.filename, | ||
Data: &ResolverBuild{ | ||
Data: data, | ||
TypeName: m.typeName, | ||
}, | ||
GeneratedHeader: false, | ||
}) | ||
} | ||
|
||
type ResolverBuild struct { | ||
*codegen.Data | ||
|
||
TypeName string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{ 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" }} | ||
|
||
{{ $root := . }} | ||
|
||
type {{$root.TypeName}} struct { | ||
{{ range $object := .Objects }} | ||
{{- if $object.HasResolvers }} | ||
{{$object.Name}}Resolver struct { | ||
{{- range $field := $object.Fields }} | ||
{{- if $field.IsResolver }} | ||
{{- $field.GoFieldName}} func{{ $field.ShortResolverDeclaration }} | ||
{{ end }} | ||
{{- end }} | ||
} | ||
{{- end }} | ||
{{- end }} | ||
} | ||
|
||
{{ range $object := .Objects -}} | ||
{{- if $object.HasResolvers -}} | ||
func (r *{{$.TypeName}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} { | ||
return &{{lcFirst $root.TypeName}}{{$object.Name}}{r} | ||
} | ||
{{ end -}} | ||
{{ end }} | ||
|
||
{{ range $object := .Objects -}} | ||
{{- if $object.HasResolvers -}} | ||
type {{lcFirst $root.TypeName}}{{$object.Name}} struct { *{{$root.TypeName}} } | ||
|
||
{{ range $field := $object.Fields -}} | ||
{{- if $field.IsResolver -}} | ||
func (r *{{lcFirst $root.TypeName}}{{$object.Name}}) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} { | ||
return r.{{$object.Name}}Resolver.{{$field.GoFieldName}}(ctx, | ||
{{- if not $object.Root }}obj,{{end -}} | ||
{{- range $arg := $field.Args}} | ||
{{$arg.VarName}}, | ||
{{- end }} | ||
) | ||
} | ||
{{ end -}} | ||
{{ end -}} | ||
{{ end -}} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters