Skip to content

Commit

Permalink
use arg value for the ResolveArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
asamusev committed Dec 4, 2018
1 parent e201bcb commit d586bb6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
3 changes: 0 additions & 3 deletions codegen/templates/args.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
{{- range $dArg := $directive.Args }}
{{- if $dArg.IsPtr }}
{{- $argValue := $dArg.Value | dump -}}
{{- $argDefault := $dArg.Default | dump -}}
{{- if not (eq $argValue "nil") }}
{{ $dArg.GoVarName }} := {{ $argValue }}
{{- else if not (eq $argDefault "nil") }}
{{ $dArg.GoVarName }} := {{ $argDefault }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions codegen/templates/data.go

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions codegen/templates/input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
{{- range $arg := $directive.Args }}
{{- if $arg.IsPtr }}
{{- $argValue := $arg.Value | dump -}}
{{- $argDefault := $arg.Default | dump -}}
{{- if not (eq $argValue "nil") }}
{{ $arg.GoVarName }} := {{ $argValue }}
{{ else if not (eq $argDefault "nil") }}
{{$arg.GoVarName}} := {{ $argDefault }}
{{ end -}}
{{- end }}
{{- end }}
Expand Down Expand Up @@ -72,11 +69,8 @@
{{- range $arg := $directive.Args }}
{{- if $arg.IsPtr }}
{{- $argValue := $arg.Value | dump -}}
{{- $argDefault := $arg.Default | dump -}}
{{- if not (eq $argValue "nil") }}
{{ $arg.GoVarName }} := {{ $argValue }}
{{ else if not (eq $argDefault "nil") }}
{{ $arg.GoVarName }} := {{ $argDefault }}
{{ end -}}
{{- end }}
{{- end }}
Expand Down
43 changes: 37 additions & 6 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ func (r *testQueryResolver) DirectiveArg(ctx context.Context, arg string) (*stri
return &s, nil
}

func (r *testQueryResolver) DirectiveNullableArg(ctx context.Context, arg *int) (*string, error) {
func (r *testQueryResolver) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) {
s := "Ok"
return &s, nil
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, err
func (r *queryResolver) DirectiveArg(ctx context.Context, arg string) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) DirectiveNullableArg(ctx context.Context, arg *int) (*string, error) {
func (r *queryResolver) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) {
Expand Down
4 changes: 2 additions & 2 deletions codegen/testserver/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Query {
user(id: Int!): User!
nullableArg(arg: Int = 123): String
directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String
directiveNullableArg(arg: Int @range(min:0)): String
directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String
directiveInputNullable(arg: InputDirectives): String
directiveInput(arg: InputDirectives!): String
}
Expand Down Expand Up @@ -166,4 +166,4 @@ type EmbeddedPointer {
}

directive @length(min: Int!, max: Int, message: String!) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
directive @range(min: Int, max: Int, message: String) on ARGUMENT_DEFINITION
directive @range(min: Int = 0, max: Int, message: String) on ARGUMENT_DEFINITION

0 comments on commit d586bb6

Please sign in to comment.