Skip to content

Commit

Permalink
fix(i): Default field value overwrite on update (#3030)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #3029

## Description

This PR fixes an issue where default field values would overwrite any
missing input fields.

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

Added integration test

Specify the platform(s) on which this was tested:
- MacOS
  • Loading branch information
nasdf authored Sep 19, 2024
1 parent 5754d7d commit cddc6d6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/request/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ func (g *Generator) buildMutationInputTypes(collections []client.CollectionDefin
}

fields[field.Name] = &gql.InputObjectFieldConfig{
Type: ttype,
DefaultValue: field.DefaultValue,
Type: ttype,
}
}

Expand Down
62 changes: 62 additions & 0 deletions tests/integration/mutation/update/with_default_values_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package update

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestMutationUpdate_WithDefaultValues_DoesNotOverwrite(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple update mutation with default value does not overwrite",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
score: Int @default(int: 100)
}
`,
},
testUtils.CreateDoc{
Doc: `{
"name": "John",
"score": 0
}`,
},
testUtils.UpdateDoc{
Doc: `{
"name": "Fred"
}`,
},
testUtils.Request{
Request: `query {
Users {
name
score
}
}`,
Results: map[string]any{
"Users": []map[string]any{
{
"name": "Fred",
"score": int64(0),
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

0 comments on commit cddc6d6

Please sign in to comment.