From 6c4a0101f1bc3ada388ed4e795a7d14f972a422a Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Fri, 21 Jan 2022 19:00:32 -0500 Subject: [PATCH] api/graph: Fix panic on nil inputs Previously, a mutation which explicitly specified a null input would cause the resolver to panic: mutation { updateRepository(id: 1, input: {name: null}) { id } } Check that the input is not nil before casting it to avoid this panic. --- api/graph/schema.resolvers.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index b335f89..ee1c898 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -281,6 +281,9 @@ func (r *mutationResolver) UpdateRepository(ctx context.Context, id int, input m if val, ok := input["visibility"]; ok { delete(input, "visibility") + if val == nil { + return fmt.Errorf("Visibility cannot be null") + } vis := model.Visibility(val.(string)) if !vis.IsValid() { return fmt.Errorf("Invalid visibility '%s'", val) @@ -306,6 +309,9 @@ func (r *mutationResolver) UpdateRepository(ctx context.Context, id int, input m upstream_uri, path, owner_id`) if n, ok := input["name"]; ok { + if n == nil { + return fmt.Errorf("Name cannot be null") + } name, ok := n.(string) if !ok { return fmt.Errorf("Invalid type for 'name' field (expected string)") -- 2.38.4