Ai
1 Star 0 Fork 0

idsutong/gqlgen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
directive_build.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
Mathew Byrne 提交于 2018-10-01 14:47 +08:00 . Do not strip ptr for args with defaults
package codegen
import (
"sort"
"github.com/pkg/errors"
)
func (cfg *Config) buildDirectives(types NamedTypes) ([]*Directive, error) {
var directives []*Directive
for name, dir := range cfg.schema.Directives {
if name == "skip" || name == "include" || name == "deprecated" {
continue
}
var args []FieldArgument
for _, arg := range dir.Arguments {
newArg := FieldArgument{
GQLName: arg.Name,
Type: types.getType(arg.Type),
GoVarName: sanitizeArgName(arg.Name),
}
if !newArg.Type.IsInput && !newArg.Type.IsScalar {
return nil, errors.Errorf("%s cannot be used as argument of directive %s(%s) only input and scalar types are allowed", arg.Type, dir.Name, arg.Name)
}
if arg.DefaultValue != nil {
var err error
newArg.Default, err = arg.DefaultValue.Value(nil)
if err != nil {
return nil, errors.Errorf("default value for directive argument %s(%s) is not valid: %s", dir.Name, arg.Name, err.Error())
}
}
args = append(args, newArg)
}
directives = append(directives, &Directive{
Name: name,
Args: args,
})
}
sort.Slice(directives, func(i, j int) bool { return directives[i].Name < directives[j].Name })
return directives, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/idsutong/gqlgen.git
git@gitee.com:idsutong/gqlgen.git
idsutong
gqlgen
gqlgen
v0.7.2

搜索帮助