diff --git a/tests/integration/query/one_to_one/with_fragments_test.go b/tests/integration/query/one_to_one/with_fragments_test.go new file mode 100644 index 0000000000..ee77f1fda0 --- /dev/null +++ b/tests/integration/query/one_to_one/with_fragments_test.go @@ -0,0 +1,78 @@ +// 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 TestQueryOneToOne_WithFragments_Succeeds(t *testing.T) { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + author: Author + } + + type Author { + name: String + age: Int + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 1, + Doc: `{ + "name": "John Grisham", + "age": 65 + }`, + }, + testUtils.CreateDoc{ + CollectionID: 0, + DocMap: map[string]any{ + "name": "Painted House", + "author": testUtils.NewDocIndex(1, 0), + }, + }, + testUtils.Request{ + Request: `query { + Book { + name + ...BookAuthorInfo + } + } + fragment BookAuthorInfo on Book { + author { + name + age + } + }`, + Results: map[string]any{ + "Book": []map[string]any{ + { + "name": "Painted House", + "author": map[string]any{ + "name": "John Grisham", + "age": int64(65), + }, + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +}