-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Treat explicitly set nil values like omitted values (#3101)
## Relevant issue(s) Resolves #3100 ## Description Treat explicitly set nil values like omitted values.
- Loading branch information
1 parent
4e5470c
commit 01030fd
Showing
6 changed files
with
263 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
tests/integration/mutation/create/field_kinds/one_to_one/with_null_value_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// 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 one_to_one | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestMutationCreateOneToOne_WithExplicitNullOnPrimarySide(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Book { | ||
name: String | ||
author: Author @primary | ||
} | ||
type Author { | ||
name: String | ||
published: Book | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "How to Be a Canadian", | ||
"author": null | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Secrets at Maple Syrup Farm", | ||
"author": null | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
DocMap: map[string]any{ | ||
"name": "Will Ferguson", | ||
"published": testUtils.NewDocIndex(0, 0), | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
Book { | ||
name | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Book": []map[string]any{ | ||
{ | ||
"name": "Secrets at Maple Syrup Farm", | ||
"author": nil, | ||
}, | ||
{ | ||
"name": "How to Be a Canadian", | ||
"author": map[string]any{ | ||
"name": "Will Ferguson", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreateOneToOne_WithExplicitNullOnSecondarySide(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Book { | ||
name: String | ||
author: Author | ||
} | ||
type Author { | ||
name: String | ||
published: Book @primary | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "How to Be a Canadian", | ||
"author": null | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "Secrets at Maple Syrup Farm", | ||
"author": null | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
DocMap: map[string]any{ | ||
"name": "Will Ferguson", | ||
"published": testUtils.NewDocIndex(0, 0), | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
Book { | ||
name | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Book": []map[string]any{ | ||
{ | ||
"name": "Secrets at Maple Syrup Farm", | ||
"author": nil, | ||
}, | ||
{ | ||
"name": "How to Be a Canadian", | ||
"author": map[string]any{ | ||
"name": "Will Ferguson", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 create | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestMutationCreate_WithOmittedValueAndExplicitNullValue(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ | ||
// Collection.Save would treat the second create as an update, and so | ||
// is excluded from this test. | ||
testUtils.CollectionNamedMutationType, | ||
testUtils.GQLRequestMutationType, | ||
}), | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"name": "John", | ||
"age": null | ||
}`, | ||
ExpectedError: "a document with the given ID already exist", | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |