...

Text file src/github.com/99designs/gqlgen/codegen/args.gotpl

Documentation: github.com/99designs/gqlgen/codegen

     1{{ range $name, $args := .Args }}
     2func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
     3	var err error
     4	args := map[string]interface{}{}
     5	{{- range $i, $arg := . }}
     6		var arg{{$i}} {{ $arg.TypeReference.GO | ref}}
     7		if tmp, ok := rawArgs[{{$arg.Name|quote}}]; ok {
     8			ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField({{$arg.Name|quote}}))
     9			{{- if $arg.ImplDirectives }}
    10				directive0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp) }
    11				{{ template "implDirectives" $arg }}
    12				tmp, err = directive{{$arg.ImplDirectives|len}}(ctx)
    13				if err != nil {
    14					return nil, graphql.ErrorOnPath(ctx, err)
    15				}
    16				if data, ok := tmp.({{ $arg.TypeReference.GO | ref }}) ; ok {
    17					arg{{$i}} = data
    18				{{- if $arg.TypeReference.IsNilable }}
    19					} else if tmp == nil {
    20						arg{{$i}} = nil
    21				{{- end }}
    22				} else {
    23					return nil, graphql.ErrorOnPath(ctx, fmt.Errorf(`unexpected type %T from directive, should be {{ $arg.TypeReference.GO }}`, tmp))
    24				}
    25			{{- else }}
    26				arg{{$i}}, err = ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp)
    27				if err != nil {
    28					return nil, err
    29				}
    30			{{- end }}
    31		}
    32		args[{{$arg.Name|quote}}] = arg{{$i}}
    33	{{- end }}
    34	return args, nil
    35}
    36{{ end }}

View as plain text