~edwargix/git.sr.ht

6c4a0101f1bc3ada388ed4e795a7d14f972a422a — Adnan Maolood 2 years ago b9b9f20
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.
1 files changed, 6 insertions(+), 0 deletions(-)

M api/graph/schema.resolvers.go
M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +6 -0
@@ 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)")