1 Star 0 Fork 0

idsutong / gqlgen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
directive.go 759 Bytes
一键复制 编辑 原始数据 按行查看 历史
Evan Shaw 提交于 2018-09-03 08:01 . Refactor arg codegen
package codegen
import (
"fmt"
"strconv"
"strings"
)
type Directive struct {
Name string
Args []FieldArgument
}
func (d *Directive) ArgsFunc() string {
if len(d.Args) == 0 {
return ""
}
return "dir_" + d.Name + "_args"
}
func (d *Directive) CallArgs() string {
args := []string{"ctx", "obj", "n"}
for _, arg := range d.Args {
args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")")
}
return strings.Join(args, ", ")
}
func (d *Directive) Declaration() string {
res := ucFirst(d.Name) + " func(ctx context.Context, obj interface{}, next graphql.Resolver"
for _, arg := range d.Args {
res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature())
}
res += ") (res interface{}, err error)"
return res
}
1
https://gitee.com/idsutong/gqlgen.git
git@gitee.com:idsutong/gqlgen.git
idsutong
gqlgen
gqlgen
v0.7.2

搜索帮助