github.com/fortexxx/gqlgen@v0.10.3-0.20191216030626-ca5ea8b21ead/plugin/stubgen/stubs.gotpl (about)

     1  {{ reserveImport "context"  }}
     2  {{ reserveImport "fmt"  }}
     3  {{ reserveImport "io"  }}
     4  {{ reserveImport "strconv"  }}
     5  {{ reserveImport "time"  }}
     6  {{ reserveImport "sync"  }}
     7  {{ reserveImport "errors"  }}
     8  {{ reserveImport "bytes"  }}
     9  
    10  {{ reserveImport "github.com/vektah/gqlparser" }}
    11  {{ reserveImport "github.com/vektah/gqlparser/ast" }}
    12  {{ reserveImport "github.com/99designs/gqlgen/graphql" }}
    13  {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }}
    14  
    15  {{ $root := . }}
    16  
    17  type {{$root.TypeName}} struct {
    18  	{{ range $object := .Objects }}
    19  		{{- if $object.HasResolvers }}
    20  			{{$object.Name}}Resolver struct {
    21  				{{- range $field := $object.Fields }}
    22  					{{- if $field.IsResolver }}
    23  						{{- $field.GoFieldName}} func{{ $field.ShortResolverDeclaration }}
    24  					{{ end }}
    25  				{{- end }}
    26  			}
    27  		{{- end }}
    28  	{{- end }}
    29  }
    30  
    31  {{ range $object := .Objects -}}
    32  	{{- if $object.HasResolvers -}}
    33  		func (r *{{$.TypeName}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} {
    34  			return &{{lcFirst $root.TypeName}}{{$object.Name}}{r}
    35  		}
    36  	{{ end -}}
    37  {{ end }}
    38  
    39  {{ range $object := .Objects -}}
    40  	{{- if $object.HasResolvers -}}
    41  		type {{lcFirst $root.TypeName}}{{$object.Name}} struct { *{{$root.TypeName}}  }
    42  
    43  		{{ range $field := $object.Fields -}}
    44  			{{- if $field.IsResolver -}}
    45  				func (r *{{lcFirst $root.TypeName}}{{$object.Name}}) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} {
    46  					return r.{{$object.Name}}Resolver.{{$field.GoFieldName}}(ctx,
    47  						{{- if not $object.Root }}obj,{{end -}}
    48  						{{- range $arg := $field.Args}}
    49  							{{- $arg.VarName}},
    50  						{{- end }}
    51  					)
    52  				}
    53  			{{ end -}}
    54  		{{ end -}}
    55  	{{ end -}}
    56  {{ end }}