forked from hypermodeinc/dgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add feature flag normalize-compatibility-mode (hypermode…
…inc#8845) (hypermodeinc#8929) This feature flag allows configuring @normalize in the query language such that if there are multiple fields with same alias, they could be returned as a list or non-list. There was a breaking change at some point with the PR hypermodeinc#7639. Some customers do not prefer a list response in case of @normalize. We would like to not make any breaking changes going forward, and hence, introducing this feature flag enables users to make that choice.
- Loading branch information
1 parent
d8d661f
commit 3d5080f
Showing
8 changed files
with
159 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
//go:build integration | ||
|
||
package zero | ||
|
||
import ( | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
//go:build integration2 | ||
|
||
/* | ||
* Copyright 2023 Dgraph Labs, Inc. and Contributors * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package query | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/dgraph-io/dgo/v230/protos/api" | ||
"github.com/dgraph-io/dgraph/dgraphtest" | ||
) | ||
|
||
func TestNormalizeDirectiveWithNoListResponse(t *testing.T) { | ||
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1). | ||
WithReplicas(1).WithNormalizeCompatibilityMode("v20") | ||
c, err := dgraphtest.NewLocalCluster(conf) | ||
require.NoError(t, err) | ||
defer func() { c.Cleanup(t.Failed()) }() | ||
require.NoError(t, c.Start()) | ||
|
||
gc, cleanup, err := c.Client() | ||
require.NoError(t, err) | ||
defer cleanup() | ||
require.NoError(t, c.AssignUids(gc.Dgraph, 100)) | ||
|
||
const dataSchema = ` | ||
friend : [uid] @reverse @count . | ||
name : string @index(term, exact, trigram) @count @lang . | ||
dob : dateTime @index(year) .` | ||
require.NoError(t, gc.SetupSchema(dataSchema)) | ||
|
||
triples := []byte(` | ||
<1> <friend> <23> . | ||
<1> <friend> <24> . | ||
<1> <friend> <25> . | ||
<1> <friend> <31> . | ||
<1> <friend> <101>. | ||
<23> <friend> <1> . | ||
<31> <friend> <1> . | ||
<31> <friend> <25> . | ||
<1> <dob> "1910-01-01" . | ||
<23> <dob> "1910-01-02" . | ||
<24> <dob> "1909-05-05" . | ||
<25> <dob> "1909-01-10" . | ||
<31> <dob> "1901-01-15" . | ||
<1> <name> "Michonne" . | ||
<23> <name> "Rick Grimes" . | ||
<24> <name> "Glenn Rhee" .`) | ||
_, err = gc.Mutate(&api.Mutation{SetNquads: triples, CommitNow: true}) | ||
require.NoError(t, err) | ||
|
||
query := ` | ||
{ | ||
me(func: uid(0x01)) @recurse @normalize { | ||
n: name | ||
d: dob | ||
friend | ||
} | ||
}` | ||
js, err := gc.Query(query) | ||
require.NoError(t, err) | ||
require.JSONEq(t, ` | ||
{ | ||
"me": [ | ||
{ | ||
"n": "Michonne", | ||
"d": "1910-01-01T00:00:00Z", | ||
"n": "Rick Grimes", | ||
"d": "1910-01-02T00:00:00Z", | ||
"n": "Michonne", | ||
"d": "1910-01-01T00:00:00Z" | ||
}, | ||
{ | ||
"n": "Michonne", | ||
"d": "1910-01-01T00:00:00Z", | ||
"n": "Glenn Rhee", | ||
"d": "1909-05-05T00:00:00Z" | ||
}, | ||
{ | ||
"n": "Michonne", | ||
"d": [ | ||
"1910-01-01T00:00:00Z", | ||
"1909-01-10T00:00:00Z" | ||
] | ||
}, | ||
{ | ||
"n": "Michonne", | ||
"d": [ | ||
"1910-01-01T00:00:00Z", | ||
"1901-01-15T00:00:00Z" | ||
], | ||
"n": "Michonne", | ||
"d": "1910-01-01T00:00:00Z" | ||
}, | ||
{ | ||
"n": "Michonne", | ||
"d": [ | ||
"1910-01-01T00:00:00Z", | ||
"1901-01-15T00:00:00Z", | ||
"1909-01-10T00:00:00Z" | ||
] | ||
} | ||
] | ||
}`, string(js.Json)) | ||
} |
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