diff options
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/directive_build.go')
-rw-r--r-- | vendor/github.com/99designs/gqlgen/codegen/directive_build.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/directive_build.go b/vendor/github.com/99designs/gqlgen/codegen/directive_build.go new file mode 100644 index 00000000..32828841 --- /dev/null +++ b/vendor/github.com/99designs/gqlgen/codegen/directive_build.go @@ -0,0 +1,49 @@ +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()) + } + newArg.StripPtr() + } + 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 +} |