Skip to content

Commit b5f2016

Browse files
committed
fix: getDryRunArg uses bool instead of strings now
1 parent 278e353 commit b5f2016

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

gateway/resolver/arguments.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (b *FieldConfigArgumentsBuilder) WithObject(resourceInputType *graphql.Inpu
6969

7070
func (b *FieldConfigArgumentsBuilder) WithDryRun() *FieldConfigArgumentsBuilder {
7171
b.arguments[DryRunArg] = &graphql.ArgumentConfig{
72-
Type: graphql.NewList(graphql.String),
73-
Description: "If true, the object will not be persisted",
72+
Type: graphql.Boolean,
73+
Description: "If true, the operation will be performed in dry-run mode",
7474
}
7575
return b
7676
}
@@ -182,24 +182,15 @@ func getDryRunArg(args map[string]interface{}, key string, required bool) ([]str
182182
return nil, nil
183183
}
184184

185-
switch v := val.(type) {
186-
case []interface{}:
187-
result := make([]string, len(v))
188-
for i, item := range v {
189-
str, ok := item.(string)
190-
if !ok {
191-
err := errors.New("invalid type in dryRun list: expected string")
192-
log.Error().Err(err).Msg("dryRun argument must be a list of strings")
193-
return nil, err
194-
}
195-
result[i] = str
196-
}
197-
return result, nil
198-
case nil:
199-
return nil, nil
200-
default:
201-
err := errors.New("invalid type for dryRun argument: expected list of strings")
202-
log.Error().Err(err).Msg("dryRun argument must be a list of strings")
185+
dryRun, ok := val.(bool)
186+
if !ok {
187+
err := errors.New("invalid type for dryRun argument: expected boolean")
188+
log.Error().Err(err).Msg("dryRun argument must be a boolean")
203189
return nil, err
204190
}
191+
192+
if dryRun {
193+
return []string{"All"}, nil
194+
}
195+
return nil, nil
205196
}

gateway/resolver/resolver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestCreateItem(t *testing.T) {
345345
args: map[string]interface{}{
346346
resolver.NameArg: "test-object",
347347
resolver.NamespaceArg: "test-namespace",
348-
resolver.DryRunArg: []interface{}{"All"},
348+
resolver.DryRunArg: true,
349349
"object": map[string]interface{}{
350350
"metadata": map[string]interface{}{
351351
"name": "test-object",
@@ -514,7 +514,7 @@ func TestUpdateItem(t *testing.T) {
514514
args: map[string]interface{}{
515515
resolver.NameArg: "test-object",
516516
resolver.NamespaceArg: "test-namespace",
517-
resolver.DryRunArg: []interface{}{"All"},
517+
resolver.DryRunArg: true,
518518
"object": map[string]interface{}{
519519
"metadata": map[string]interface{}{
520520
"name": "test-object",

0 commit comments

Comments
 (0)