@@ -2,10 +2,11 @@ package resolver
2
2
3
3
import (
4
4
"errors"
5
- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
6
5
"maps"
7
6
"strings"
8
7
8
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
9
+
9
10
"github.com/graphql-go/graphql"
10
11
"github.com/rs/zerolog/log"
11
12
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -18,6 +19,7 @@ const (
18
19
ObjectArg = "object"
19
20
SubscribeToAllArg = "subscribeToAll"
20
21
SortByArg = "sortBy"
22
+ DryRunArg = "dryRun"
21
23
)
22
24
23
25
// FieldConfigArgumentsBuilder helps construct GraphQL field config arguments
@@ -65,6 +67,14 @@ func (b *FieldConfigArgumentsBuilder) WithObject(resourceInputType *graphql.Inpu
65
67
return b
66
68
}
67
69
70
+ func (b * FieldConfigArgumentsBuilder ) WithDryRun () * FieldConfigArgumentsBuilder {
71
+ b .arguments [DryRunArg ] = & graphql.ArgumentConfig {
72
+ Type : graphql .NewList (graphql .String ),
73
+ Description : "If true, the object will not be persisted" ,
74
+ }
75
+ return b
76
+ }
77
+
68
78
func (b * FieldConfigArgumentsBuilder ) WithSubscribeToAll () * FieldConfigArgumentsBuilder {
69
79
b .arguments [SubscribeToAllArg ] = & graphql.ArgumentConfig {
70
80
Type : graphql .Boolean ,
@@ -160,3 +170,36 @@ func validateSortBy(items []unstructured.Unstructured, fieldPath string) error {
160
170
161
171
return nil
162
172
}
173
+
174
+ func getDryRunArg (args map [string ]interface {}, key string , required bool ) ([]string , error ) {
175
+ val , exists := args [key ]
176
+ if ! exists {
177
+ if required {
178
+ err := errors .New ("missing required argument: " + key )
179
+ log .Error ().Err (err ).Msg (key + " argument is required" )
180
+ return nil , err
181
+ }
182
+ return nil , nil
183
+ }
184
+
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" )
203
+ return nil , err
204
+ }
205
+ }
0 commit comments