From 09f20e63bf60de95787ec5e787ecca5d9fd936df Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Mon, 12 Oct 2020 22:49:20 +0530 Subject: [PATCH 1/4] added fix and tests --- graphql/resolve/query_rewriter.go | 13 +- graphql/resolve/query_test.yaml | 262 +++++++++++------------------- 2 files changed, 106 insertions(+), 169 deletions(-) diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index 05facaa2eb5..9359a9d5296 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -1020,6 +1020,9 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree // Each key in filter is either "and", "or", "not" or the field name it // applies to such as "title" in: `title: { anyofterms: "GraphQL" }`` for _, field := range keys { + if filter[field] != nil { + continue + } switch field { // In 'and', 'or' and 'not' cases, filter[field] must be a map[string]interface{} @@ -1076,7 +1079,7 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree for _, v := range vals { args = append(args, gql.Arg{Value: maybeQuoteArg(fn, v)}) } - + case "near": // For Geo type we have `near` filter which is written as follows: // { near: { distance: 33.33, coordinate: { latitude: 11.11, longitude: 22.22 } } } @@ -1087,10 +1090,10 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree lat := coordinate["latitude"] long := coordinate["longitude"] - args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}) - args = append(args, gql.Arg{Value: fmt.Sprintf("%v", distance)}) + args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}) + args = append(args, gql.Arg{Value: fmt.Sprintf("%v", distance)}) - default: + default: args = append(args, gql.Arg{Value: maybeQuoteArg(fn, val)}) } ands = append(ands, &gql.FilterTree{ @@ -1098,7 +1101,7 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree Name: fn, Args: args, }, - }) + }) case []interface{}: // ids: [ 0x123, 0x124 ] -> uid(0x123, 0x124) ids := convertIDs(dgFunc) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index 1ef5bf57ee4..d249d371a46 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1,5 +1,4 @@ -- - name: "in filter" +- name: "in filter" gqlquery: | query { queryState(filter: {code: {in: ["abc", "def", "ghi"]}}) { @@ -15,9 +14,8 @@ dgraph.uid : uid } } - -- - name: "Geo query" + +- name: "Geo query" gqlquery: | query { queryHotel(filter: { location: { near: { distance: 33.33, coordinate: { latitude: 11.11, longitude: 22.22} } } }) { @@ -37,8 +35,7 @@ } } -- - name: "ID query" +- name: "ID query" gqlquery: | query { getAuthor(id: "0x1") { @@ -53,8 +50,7 @@ } } -- - name: "Alias is ignored in query rewriting - get" +- name: "Alias is ignored in query rewriting - get" gqlquery: | query { author : getAuthor(id: "0x1") { @@ -76,8 +72,7 @@ } } -- - name: "Alias is ignored in query rewriting - query" +- name: "Alias is ignored in query rewriting - query" gqlquery: | query { author : queryAuthor { @@ -99,8 +94,7 @@ } } -- - name: "ID field gets transformed to uid" +- name: "ID field gets transformed to uid" gqlquery: | query { getAuthor(id: "0x1") { @@ -116,8 +110,7 @@ } } -- - name: "ID query with depth" +- name: "ID query with depth" gqlquery: | query { getAuthor(id: "0x1") { @@ -141,8 +134,7 @@ } } -- - name: "ID query deep" +- name: "ID query deep" gqlquery: | query { getAuthor(id: "0x1") { @@ -174,8 +166,7 @@ } } -- - name: "Query with no args is query for everything of that type" +- name: "Query with no args is query for everything of that type" gqlquery: | query { queryAuthor { @@ -190,8 +181,7 @@ } } -- - name: "Filter gets rewritten as @filter" +- name: "Filter gets rewritten as @filter" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }) { @@ -205,9 +195,24 @@ dgraph.uid : uid } } +- name: "Filter connectives with null values gets skipped " + gqlquery: | + query { + queryAuthor(filter: { name: { eq: "A. N. Author" },not:null }) { + name + } + } + dgquery: |- + query { + queryAuthor(func: type(Author)) @filter(eq(Author.name, "A. N. Author")) { + name : Author.name + dgraph.uid : uid + } + } - - name: "Query with has Filter" + +- name: "Query with has Filter" gqlquery: | query { queryTeacher(filter: {has: subject}) { @@ -222,8 +227,7 @@ } } -- - name: "has Filter with not" +- name: "has Filter with not" gqlquery: | query { queryTeacher(filter: { not : {has: subject } }) { @@ -238,8 +242,7 @@ } } -- - name: "has Filter with and" +- name: "has Filter with and" gqlquery: | query { queryTeacher(filter: {has: subject, and: {has: teaches } } ) { @@ -254,8 +257,7 @@ } } -- - name: "Filters in same input object implies AND" +- name: "Filters in same input object implies AND" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, dob: { le: "2001-01-01" }, reputation: { gt: 2.5 } } ) { @@ -270,8 +272,7 @@ } } -- - name: "Filter with nested 'and'" +- name: "Filter with nested 'and'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { dob: { le: "2001-01-01" }, and: { reputation: { gt: 2.5 } } } } ) { @@ -286,8 +287,7 @@ } } -- - name: "has Filter with nested 'and'" +- name: "has Filter with nested 'and'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { dob: { le: "2001-01-01" }, and: { has: country } } } ) { @@ -302,8 +302,7 @@ } } -- - name: "Filter with 'or'" +- name: "Filter with 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { dob: { le: "2001-01-01" } } } ) { @@ -319,8 +318,7 @@ } -- - name: "Filter with implied and as well as 'or'" +- name: "Filter with implied and as well as 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, reputation: { gt: 2.5 }, or: { dob: { le: "2001-01-01" } } } ) { @@ -335,8 +333,7 @@ } } -- - name: "Filter with implied and nested in 'or'" +- name: "Filter with implied and nested in 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { reputation: { gt: 2.5 }, dob: { le: "2001-01-01" } } } ) { @@ -351,8 +348,7 @@ } } -- - name: "Filter nested 'or'" +- name: "Filter nested 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { reputation: { gt: 2.5 }, or: { dob: { le: "2001-01-01" } } } } ) { @@ -367,8 +363,7 @@ } } -- - name: "Filter with 'not" +- name: "Filter with 'not" gqlquery: | query { queryAuthor(filter: { not: { reputation: { gt: 2.5 } } } ) { @@ -383,8 +378,7 @@ } } -- - name: "Filter with first" +- name: "Filter with first" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, first: 10) { @@ -399,8 +393,7 @@ } } -- - name: "Filter with first and offset" +- name: "Filter with first and offset" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, first: 10, offset: 10) { @@ -415,8 +408,7 @@ } } -- - name: "Filter with order asc" +- name: "Filter with order asc" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { asc: reputation }) { @@ -431,8 +423,7 @@ } } -- - name: "Filter with order desc" +- name: "Filter with order desc" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation }) { @@ -448,8 +439,7 @@ } -- - name: "Filter with nested order" +- name: "Filter with nested order" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation, then: { asc: dob } }) { @@ -464,8 +454,7 @@ } } -- - name: "Filter with order, first and offset" +- name: "Filter with order, first and offset" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation }, first: 10, offset: 10) { @@ -480,8 +469,7 @@ } } -- - name: "Deep filter" +- name: "Deep filter" gqlquery: | query { queryAuthor { @@ -504,8 +492,7 @@ } -- - name: "Deep filter with has filter" +- name: "Deep filter with has filter" gqlquery: | query { queryAuthor { @@ -527,8 +514,7 @@ } } -- - name: "Deep filter with has and other filters" +- name: "Deep filter with has and other filters" gqlquery: | query { queryAuthor { @@ -549,8 +535,7 @@ dgraph.uid : uid } } -- - name: "Deep filter with first" +- name: "Deep filter with first" gqlquery: | query { queryAuthor { @@ -572,8 +557,7 @@ } } -- - name: "Deep filter with order, first and offset" +- name: "Deep filter with order, first and offset" gqlquery: | query { queryAuthor { @@ -596,8 +580,7 @@ } -- - name: "All Float filters work" +- name: "All Float filters work" gqlquery: | query { queryAuthor(filter: { reputation: { gt: 1.1 }, or: { reputation: { ge: 1.1 }, or: { reputation: { lt: 1.1 }, or: { reputation: { le: 1.1 }, or: { reputation: { eq: 1.1 } } } } } } ) { @@ -612,8 +595,7 @@ } } -- - name: "All DateTime filters work" +- name: "All DateTime filters work" gqlquery: | query { queryAuthor(filter: { dob: { gt: "2000-01-01" }, or: { dob: { ge: "2000-01-01" }, or: { dob: { lt: "2000-01-01" }, or: { dob: { le: "2000-01-01" }, or: { dob: { eq: "2000-01-01" } } } } } } ) { @@ -628,8 +610,7 @@ } } -- - name: "All Int filters work" +- name: "All Int filters work" gqlquery: | query { queryPost(filter: { numLikes: { gt: 10 }, or: { numLikes: { ge: 10 }, or: { numLikes: { lt: 10 }, or: { numLikes: { le: 10 }, or: { numLikes: { eq: 10 } } } } } } ) { @@ -644,8 +625,7 @@ } } -- - name: "All String hash filters work" +- name: "All String hash filters work" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } } ) { @@ -660,8 +640,7 @@ } } -- - name: "All String exact filters work" +- name: "All String exact filters work" gqlquery: | query { queryCountry(filter: { name: { gt: "AAA" }, or: { name: { ge: "AAA" }, or: { name: { lt: "AAA" }, or: { name: { le: "AAA" }, or: { name: { eq: "AAA" } } } } } } ) { @@ -676,8 +655,7 @@ } } -- - name: "All String term filters work" +- name: "All String term filters work" gqlquery: | query { queryPost(filter: { title: { anyofterms: "GraphQL"}, or: { title: { allofterms: "GraphQL" } } } ) { @@ -693,8 +671,7 @@ } -- - name: "All String fulltext filters work" +- name: "All String fulltext filters work" gqlquery: | query { queryPost(filter: { text: { anyoftext: "GraphQL"}, or: { text: { alloftext: "GraphQL" } } } ) { @@ -709,8 +686,7 @@ } } -- - name: "All String regexp filters work" +- name: "All String regexp filters work" gqlquery: | query { queryCountry(filter: { name: { regexp: "/.*ust.*/" }}) { @@ -725,8 +701,7 @@ } } -- - name: "Skip directive" +- name: "Skip directive" variables: skipTrue: true skipFalse: false @@ -748,8 +723,7 @@ } } -- - name: "Include directive" +- name: "Include directive" variables: includeTrue: true includeFalse: false @@ -770,8 +744,7 @@ } } -- - name: "Include only fields for which skip is !false or include is true" +- name: "Include only fields for which skip is !false or include is true" variables: includeFalse: false includeTrue: true @@ -799,8 +772,7 @@ } } -- - name: "Cascade directive on get query" +- name: "Cascade directive on get query" gqlquery: | query { getAuthor(id: "0x1") @cascade { @@ -822,8 +794,7 @@ } } -- - name: "Cascade directive on filter query" +- name: "Cascade directive on filter query" gqlquery: | query { queryAuthor @cascade { @@ -845,8 +816,7 @@ } } -- - name: "Cascade directive on query field" +- name: "Cascade directive on query field" gqlquery: | query { queryAuthor { @@ -868,8 +838,7 @@ } } -- - name: "Cascade directive on root query and query field" +- name: "Cascade directive on root query and query field" gqlquery: | query { queryAuthor @cascade { @@ -891,8 +860,7 @@ } } -- - name: "Parameterized Cascade directive on filter query" +- name: "Parameterized Cascade directive on filter query" gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -916,8 +884,7 @@ } } -- - name: "Parameterized Cascade directive on get query" +- name: "Parameterized Cascade directive on get query" gqlquery: | query { getAuthor(id: "0x1") @cascade(fields:["dob"]) { @@ -941,8 +908,7 @@ } } -- - name: "Parameterized Cascade directive on query field" +- name: "Parameterized Cascade directive on query field" gqlquery: | query { queryAuthor { @@ -966,8 +932,7 @@ } } -- - name: "Parameterized Cascade directive on root and query field" +- name: "Parameterized Cascade directive on root and query field" gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -993,8 +958,7 @@ } } -- - name: "Parameterized Cascade directive with multiple parameters on root and query field" +- name: "Parameterized Cascade directive with multiple parameters on root and query field" gqlquery: | query { queryAuthor @cascade(fields:["dob","reputation","id"]) { @@ -1020,8 +984,7 @@ } } -- - name: "Parameterized Cascade directive with argument at outer level which is not present in inner level " +- name: "Parameterized Cascade directive with argument at outer level which is not present in inner level " gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -1047,8 +1010,7 @@ } } -- - name: "parameterized cascade with interface implementation Human" +- name: "parameterized cascade with interface implementation Human" gqlquery: | query { queryHuman @cascade(fields:["id","name","ename","dob"]) { @@ -1070,8 +1032,7 @@ } } -- - name: "parameterized cascade with interface Character" +- name: "parameterized cascade with interface Character" gqlquery: | query { queryCharacter @cascade(fields:["id","name"]) { @@ -1088,8 +1049,7 @@ } } -- - name: "getHuman which implements an interface" +- name: "getHuman which implements an interface" gqlquery: | query { getHuman(id: "0x1") { @@ -1111,8 +1071,7 @@ } } -- - name: "queryHuman which implements an interface" +- name: "queryHuman which implements an interface" gqlquery: | query { queryHuman { @@ -1134,8 +1093,7 @@ } } -- - name: "Get Query on interface whose implementation contains Auth rules." +- name: "Get Query on interface whose implementation contains Auth rules." gqlquery: | query { getX(id: "0x1") { @@ -1148,8 +1106,7 @@ getX() } -- - name: "Query on interface whose implementation contains Auth rules." +- name: "Query on interface whose implementation contains Auth rules." gqlquery: | query { queryX { @@ -1162,8 +1119,7 @@ queryX() } -- - name: "filter with order for type which implements an interface" +- name: "filter with order for type which implements an interface" gqlquery: | query { queryHuman (filter: { name: { anyofterms: "GraphQL" } }, order: { asc: ename }) { @@ -1183,8 +1139,7 @@ } } -- - name: "queryCharacter with fragment for human" +- name: "queryCharacter with fragment for human" gqlquery: | query { queryCharacter { @@ -1207,8 +1162,7 @@ } } -- - name: "queryCharacter with fragment on multiple types" +- name: "queryCharacter with fragment on multiple types" gqlquery: | query { queryCharacter { @@ -1235,8 +1189,7 @@ } } -- - name: "Filter with id uses uid func at root." +- name: "Filter with id uses uid func at root." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"], and: { name: { eq: "A. N. Author" } }}) { @@ -1251,8 +1204,7 @@ } } -- - name: "Filter with id inside and argument doesn't use uid func at root." +- name: "Filter with id inside and argument doesn't use uid func at root." gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { id: ["0x1", "0x2"] }}) { @@ -1267,8 +1219,7 @@ } } -- - name: "Filter with id and not translates correctly.." +- name: "Filter with id and not translates correctly.." gqlquery: | query { queryAuthor(filter: { not: { id: ["0x1", "0x2"] }}) { @@ -1283,8 +1234,7 @@ } } -- - name: "Deep filter with id" +- name: "Deep filter with id" gqlquery: | query { queryAuthor { @@ -1306,8 +1256,7 @@ } } -- - name: "Deep filter with id in not key" +- name: "Deep filter with id in not key" gqlquery: | query { queryAuthor { @@ -1329,8 +1278,7 @@ } } -- - name: "Pagination and Order at root node with UID." +- name: "Pagination and Order at root node with UID." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"] }, order: {asc: name}, first: 0, offset: 1 ) { @@ -1345,8 +1293,7 @@ } } -- - name: "Order at root node with UID." +- name: "Order at root node with UID." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"] }, order: {asc: name}) { @@ -1361,8 +1308,7 @@ } } -- - name: "Order at root node without UID." +- name: "Order at root node without UID." gqlquery: | query { queryAuthor(order: {asc: name}) { @@ -1377,8 +1323,7 @@ } } -- - name: "Order and Pagination at root node without UID." +- name: "Order and Pagination at root node without UID." gqlquery: | query { queryAuthor(order: {asc: name}, first: 2, offset: 3) { @@ -1394,8 +1339,7 @@ } -- - name: "Filter with no valid id construct the right query with type func at root." +- name: "Filter with no valid id construct the right query with type func at root." gqlquery: | query { queryAuthor(filter: { id: ["alice", "bob"], and: { name: { eq: "A. N. Author" } }}) { @@ -1410,8 +1354,7 @@ } } -- - name: "Filter with id only includes valid id in dgquery." +- name: "Filter with id only includes valid id in dgquery." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "bob"], and: { name: { eq: "A. N. Author" } }}) { @@ -1426,8 +1369,7 @@ } } -- - name: "Get editor without supplying anything" +- name: "Get editor without supplying anything" gqlquery: | query { getEditor { @@ -1442,8 +1384,7 @@ } } -- - name: "Get editor using code" +- name: "Get editor using code" gqlquery: | query { getEditor(code: "tolstoy") { @@ -1458,8 +1399,7 @@ } } -- - name: "Get editor using both code and id" +- name: "Get editor using both code and id" gqlquery: | query { getEditor(code: "tolstoy", id: "0x1") { @@ -1474,8 +1414,7 @@ } } -- - name: "Get with XID where no ID in type" +- name: "Get with XID where no ID in type" gqlquery: | query { getState(code: "NSW") { @@ -1490,8 +1429,7 @@ } } -- - name: "Query editor using code" +- name: "Query editor using code" gqlquery: | query { queryEditor(filter: { code: { eq: "editor" }, and: { name: { eq: "A. N. Editor" }}}) { @@ -1506,8 +1444,7 @@ } } -- - name: "Query editor using code and uid" +- name: "Query editor using code and uid" gqlquery: | query { queryEditor(filter: { id: ["0x1"], and: { code: { eq: "editor"}}}) { @@ -1522,8 +1459,7 @@ } } -- - name: "Query along reverse edge is converted appropriately" +- name: "Query along reverse edge is converted appropriately" gqlquery: | query { queryMovie { @@ -1545,8 +1481,7 @@ } } -- - name: "deprecated fields can be queried" +- name: "deprecated fields can be queried" gqlquery: | query { queryCategory { @@ -1562,8 +1497,7 @@ } } -- - name: "Password query" +- name: "Password query" gqlquery: | query { checkUserPassword(name: "user1", pwd: "Password") { From 60ec230f95accb0c6a411d2e240d5cdbb0a0ee71 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 13 Oct 2020 10:51:19 +0530 Subject: [PATCH 2/4] fixed tests --- graphql/resolve/query_rewriter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index 9359a9d5296..9ec40e0f70d 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -1020,7 +1020,7 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree // Each key in filter is either "and", "or", "not" or the field name it // applies to such as "title" in: `title: { anyofterms: "GraphQL" }`` for _, field := range keys { - if filter[field] != nil { + if filter[field] == nil { continue } switch field { From a058d654993f8b31320f46793b24e945eeb7e9a8 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 13 Oct 2020 12:24:34 +0530 Subject: [PATCH 3/4] fixed formatting issue in test --- graphql/resolve/query_test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index d249d371a46..4600a5fdb8b 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -195,6 +195,7 @@ dgraph.uid : uid } } + - name: "Filter connectives with null values gets skipped " gqlquery: | query { @@ -210,8 +211,6 @@ } } -- - - name: "Query with has Filter" gqlquery: | query { From 222b43ff780c6fff880db7fab4bb836fbe2df072 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 13 Oct 2020 19:17:24 +0530 Subject: [PATCH 4/4] fixed formatting --- graphql/resolve/query_rewriter.go | 6 +- graphql/resolve/query_test.yaml | 249 ++++++++++++++++++++---------- 2 files changed, 168 insertions(+), 87 deletions(-) diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index 9ec40e0f70d..eacbff4de76 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -1079,7 +1079,6 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree for _, v := range vals { args = append(args, gql.Arg{Value: maybeQuoteArg(fn, v)}) } - case "near": // For Geo type we have `near` filter which is written as follows: // { near: { distance: 33.33, coordinate: { latitude: 11.11, longitude: 22.22 } } } @@ -1089,9 +1088,8 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree coordinate, _ := geoParams["coordinate"].(map[string]interface{}) lat := coordinate["latitude"] long := coordinate["longitude"] - - args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}) - args = append(args, gql.Arg{Value: fmt.Sprintf("%v", distance)}) + args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}, + gql.Arg{Value: fmt.Sprintf("%v", distance)}) default: args = append(args, gql.Arg{Value: maybeQuoteArg(fn, val)}) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index 4600a5fdb8b..a3efd655ba7 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1,4 +1,5 @@ -- name: "in filter" +- + name: "in filter" gqlquery: | query { queryState(filter: {code: {in: ["abc", "def", "ghi"]}}) { @@ -15,7 +16,8 @@ } } -- name: "Geo query" +- + name: "Geo query" gqlquery: | query { queryHotel(filter: { location: { near: { distance: 33.33, coordinate: { latitude: 11.11, longitude: 22.22} } } }) { @@ -35,7 +37,8 @@ } } -- name: "ID query" +- + name: "ID query" gqlquery: | query { getAuthor(id: "0x1") { @@ -50,7 +53,8 @@ } } -- name: "Alias is ignored in query rewriting - get" +- + name: "Alias is ignored in query rewriting - get" gqlquery: | query { author : getAuthor(id: "0x1") { @@ -72,7 +76,8 @@ } } -- name: "Alias is ignored in query rewriting - query" +- + name: "Alias is ignored in query rewriting - query" gqlquery: | query { author : queryAuthor { @@ -94,7 +99,8 @@ } } -- name: "ID field gets transformed to uid" +- + name: "ID field gets transformed to uid" gqlquery: | query { getAuthor(id: "0x1") { @@ -110,7 +116,8 @@ } } -- name: "ID query with depth" +- + name: "ID query with depth" gqlquery: | query { getAuthor(id: "0x1") { @@ -134,7 +141,8 @@ } } -- name: "ID query deep" +- + name: "ID query deep" gqlquery: | query { getAuthor(id: "0x1") { @@ -166,7 +174,8 @@ } } -- name: "Query with no args is query for everything of that type" +- + name: "Query with no args is query for everything of that type" gqlquery: | query { queryAuthor { @@ -181,7 +190,8 @@ } } -- name: "Filter gets rewritten as @filter" +- + name: "Filter gets rewritten as @filter" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }) { @@ -196,7 +206,8 @@ } } -- name: "Filter connectives with null values gets skipped " +- + name: "Filter connectives with null values gets skipped " gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" },not:null }) { @@ -211,7 +222,8 @@ } } -- name: "Query with has Filter" +- + name: "Query with has Filter" gqlquery: | query { queryTeacher(filter: {has: subject}) { @@ -226,7 +238,8 @@ } } -- name: "has Filter with not" +- + name: "has Filter with not" gqlquery: | query { queryTeacher(filter: { not : {has: subject } }) { @@ -241,7 +254,8 @@ } } -- name: "has Filter with and" +- + name: "has Filter with and" gqlquery: | query { queryTeacher(filter: {has: subject, and: {has: teaches } } ) { @@ -256,7 +270,8 @@ } } -- name: "Filters in same input object implies AND" +- + name: "Filters in same input object implies AND" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, dob: { le: "2001-01-01" }, reputation: { gt: 2.5 } } ) { @@ -271,7 +286,8 @@ } } -- name: "Filter with nested 'and'" +- + name: "Filter with nested 'and'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { dob: { le: "2001-01-01" }, and: { reputation: { gt: 2.5 } } } } ) { @@ -286,7 +302,8 @@ } } -- name: "has Filter with nested 'and'" +- + name: "has Filter with nested 'and'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { dob: { le: "2001-01-01" }, and: { has: country } } } ) { @@ -301,7 +318,8 @@ } } -- name: "Filter with 'or'" +- + name: "Filter with 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { dob: { le: "2001-01-01" } } } ) { @@ -317,7 +335,8 @@ } -- name: "Filter with implied and as well as 'or'" +- + name: "Filter with implied and as well as 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, reputation: { gt: 2.5 }, or: { dob: { le: "2001-01-01" } } } ) { @@ -332,7 +351,8 @@ } } -- name: "Filter with implied and nested in 'or'" +- + name: "Filter with implied and nested in 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { reputation: { gt: 2.5 }, dob: { le: "2001-01-01" } } } ) { @@ -347,7 +367,8 @@ } } -- name: "Filter nested 'or'" +- + name: "Filter nested 'or'" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, or: { reputation: { gt: 2.5 }, or: { dob: { le: "2001-01-01" } } } } ) { @@ -362,7 +383,8 @@ } } -- name: "Filter with 'not" +- + name: "Filter with 'not" gqlquery: | query { queryAuthor(filter: { not: { reputation: { gt: 2.5 } } } ) { @@ -377,7 +399,8 @@ } } -- name: "Filter with first" +- + name: "Filter with first" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, first: 10) { @@ -392,7 +415,8 @@ } } -- name: "Filter with first and offset" +- + name: "Filter with first and offset" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, first: 10, offset: 10) { @@ -407,7 +431,8 @@ } } -- name: "Filter with order asc" +- + name: "Filter with order asc" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { asc: reputation }) { @@ -422,7 +447,8 @@ } } -- name: "Filter with order desc" +- + name: "Filter with order desc" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation }) { @@ -438,7 +464,8 @@ } -- name: "Filter with nested order" +- + name: "Filter with nested order" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation, then: { asc: dob } }) { @@ -453,7 +480,8 @@ } } -- name: "Filter with order, first and offset" +- + name: "Filter with order, first and offset" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } }, order: { desc: reputation }, first: 10, offset: 10) { @@ -468,7 +496,8 @@ } } -- name: "Deep filter" +- + name: "Deep filter" gqlquery: | query { queryAuthor { @@ -491,7 +520,8 @@ } -- name: "Deep filter with has filter" +- + name: "Deep filter with has filter" gqlquery: | query { queryAuthor { @@ -513,7 +543,8 @@ } } -- name: "Deep filter with has and other filters" +- + name: "Deep filter with has and other filters" gqlquery: | query { queryAuthor { @@ -534,7 +565,8 @@ dgraph.uid : uid } } -- name: "Deep filter with first" +- + name: "Deep filter with first" gqlquery: | query { queryAuthor { @@ -556,7 +588,8 @@ } } -- name: "Deep filter with order, first and offset" +- + name: "Deep filter with order, first and offset" gqlquery: | query { queryAuthor { @@ -579,7 +612,8 @@ } -- name: "All Float filters work" +- + name: "All Float filters work" gqlquery: | query { queryAuthor(filter: { reputation: { gt: 1.1 }, or: { reputation: { ge: 1.1 }, or: { reputation: { lt: 1.1 }, or: { reputation: { le: 1.1 }, or: { reputation: { eq: 1.1 } } } } } } ) { @@ -594,7 +628,8 @@ } } -- name: "All DateTime filters work" +- + name: "All DateTime filters work" gqlquery: | query { queryAuthor(filter: { dob: { gt: "2000-01-01" }, or: { dob: { ge: "2000-01-01" }, or: { dob: { lt: "2000-01-01" }, or: { dob: { le: "2000-01-01" }, or: { dob: { eq: "2000-01-01" } } } } } } ) { @@ -609,7 +644,8 @@ } } -- name: "All Int filters work" +- + name: "All Int filters work" gqlquery: | query { queryPost(filter: { numLikes: { gt: 10 }, or: { numLikes: { ge: 10 }, or: { numLikes: { lt: 10 }, or: { numLikes: { le: 10 }, or: { numLikes: { eq: 10 } } } } } } ) { @@ -624,7 +660,8 @@ } } -- name: "All String hash filters work" +- + name: "All String hash filters work" gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" } } ) { @@ -639,7 +676,8 @@ } } -- name: "All String exact filters work" +- + name: "All String exact filters work" gqlquery: | query { queryCountry(filter: { name: { gt: "AAA" }, or: { name: { ge: "AAA" }, or: { name: { lt: "AAA" }, or: { name: { le: "AAA" }, or: { name: { eq: "AAA" } } } } } } ) { @@ -654,7 +692,8 @@ } } -- name: "All String term filters work" +- + name: "All String term filters work" gqlquery: | query { queryPost(filter: { title: { anyofterms: "GraphQL"}, or: { title: { allofterms: "GraphQL" } } } ) { @@ -670,7 +709,8 @@ } -- name: "All String fulltext filters work" +- + name: "All String fulltext filters work" gqlquery: | query { queryPost(filter: { text: { anyoftext: "GraphQL"}, or: { text: { alloftext: "GraphQL" } } } ) { @@ -685,7 +725,8 @@ } } -- name: "All String regexp filters work" +- + name: "All String regexp filters work" gqlquery: | query { queryCountry(filter: { name: { regexp: "/.*ust.*/" }}) { @@ -700,7 +741,8 @@ } } -- name: "Skip directive" +- + name: "Skip directive" variables: skipTrue: true skipFalse: false @@ -722,7 +764,8 @@ } } -- name: "Include directive" +- + name: "Include directive" variables: includeTrue: true includeFalse: false @@ -743,7 +786,8 @@ } } -- name: "Include only fields for which skip is !false or include is true" +- + name: "Include only fields for which skip is !false or include is true" variables: includeFalse: false includeTrue: true @@ -771,7 +815,8 @@ } } -- name: "Cascade directive on get query" +- + name: "Cascade directive on get query" gqlquery: | query { getAuthor(id: "0x1") @cascade { @@ -793,7 +838,8 @@ } } -- name: "Cascade directive on filter query" +- + name: "Cascade directive on filter query" gqlquery: | query { queryAuthor @cascade { @@ -815,7 +861,8 @@ } } -- name: "Cascade directive on query field" +- + name: "Cascade directive on query field" gqlquery: | query { queryAuthor { @@ -837,7 +884,8 @@ } } -- name: "Cascade directive on root query and query field" +- + name: "Cascade directive on root query and query field" gqlquery: | query { queryAuthor @cascade { @@ -859,7 +907,8 @@ } } -- name: "Parameterized Cascade directive on filter query" +- + name: "Parameterized Cascade directive on filter query" gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -883,7 +932,8 @@ } } -- name: "Parameterized Cascade directive on get query" +- + name: "Parameterized Cascade directive on get query" gqlquery: | query { getAuthor(id: "0x1") @cascade(fields:["dob"]) { @@ -907,7 +957,8 @@ } } -- name: "Parameterized Cascade directive on query field" +- + name: "Parameterized Cascade directive on query field" gqlquery: | query { queryAuthor { @@ -931,7 +982,8 @@ } } -- name: "Parameterized Cascade directive on root and query field" +- + name: "Parameterized Cascade directive on root and query field" gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -957,7 +1009,8 @@ } } -- name: "Parameterized Cascade directive with multiple parameters on root and query field" +- + name: "Parameterized Cascade directive with multiple parameters on root and query field" gqlquery: | query { queryAuthor @cascade(fields:["dob","reputation","id"]) { @@ -983,7 +1036,8 @@ } } -- name: "Parameterized Cascade directive with argument at outer level which is not present in inner level " +- + name: "Parameterized Cascade directive with argument at outer level which is not present in inner level " gqlquery: | query { queryAuthor @cascade(fields:["dob"]) { @@ -1009,7 +1063,8 @@ } } -- name: "parameterized cascade with interface implementation Human" +- + name: "parameterized cascade with interface implementation Human" gqlquery: | query { queryHuman @cascade(fields:["id","name","ename","dob"]) { @@ -1031,7 +1086,8 @@ } } -- name: "parameterized cascade with interface Character" +- + name: "parameterized cascade with interface Character" gqlquery: | query { queryCharacter @cascade(fields:["id","name"]) { @@ -1048,7 +1104,8 @@ } } -- name: "getHuman which implements an interface" +- + name: "getHuman which implements an interface" gqlquery: | query { getHuman(id: "0x1") { @@ -1070,7 +1127,8 @@ } } -- name: "queryHuman which implements an interface" +- + name: "queryHuman which implements an interface" gqlquery: | query { queryHuman { @@ -1092,7 +1150,8 @@ } } -- name: "Get Query on interface whose implementation contains Auth rules." +- + name: "Get Query on interface whose implementation contains Auth rules." gqlquery: | query { getX(id: "0x1") { @@ -1105,7 +1164,8 @@ getX() } -- name: "Query on interface whose implementation contains Auth rules." +- + name: "Query on interface whose implementation contains Auth rules." gqlquery: | query { queryX { @@ -1118,7 +1178,8 @@ queryX() } -- name: "filter with order for type which implements an interface" +- + name: "filter with order for type which implements an interface" gqlquery: | query { queryHuman (filter: { name: { anyofterms: "GraphQL" } }, order: { asc: ename }) { @@ -1138,7 +1199,8 @@ } } -- name: "queryCharacter with fragment for human" +- + name: "queryCharacter with fragment for human" gqlquery: | query { queryCharacter { @@ -1161,7 +1223,8 @@ } } -- name: "queryCharacter with fragment on multiple types" +- + name: "queryCharacter with fragment on multiple types" gqlquery: | query { queryCharacter { @@ -1188,7 +1251,8 @@ } } -- name: "Filter with id uses uid func at root." +- + name: "Filter with id uses uid func at root." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"], and: { name: { eq: "A. N. Author" } }}) { @@ -1203,7 +1267,8 @@ } } -- name: "Filter with id inside and argument doesn't use uid func at root." +- + name: "Filter with id inside and argument doesn't use uid func at root." gqlquery: | query { queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { id: ["0x1", "0x2"] }}) { @@ -1218,7 +1283,8 @@ } } -- name: "Filter with id and not translates correctly.." +- + name: "Filter with id and not translates correctly.." gqlquery: | query { queryAuthor(filter: { not: { id: ["0x1", "0x2"] }}) { @@ -1233,7 +1299,8 @@ } } -- name: "Deep filter with id" +- + name: "Deep filter with id" gqlquery: | query { queryAuthor { @@ -1255,7 +1322,8 @@ } } -- name: "Deep filter with id in not key" +- + name: "Deep filter with id in not key" gqlquery: | query { queryAuthor { @@ -1277,7 +1345,8 @@ } } -- name: "Pagination and Order at root node with UID." +- + name: "Pagination and Order at root node with UID." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"] }, order: {asc: name}, first: 0, offset: 1 ) { @@ -1292,7 +1361,8 @@ } } -- name: "Order at root node with UID." +- + name: "Order at root node with UID." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "0x2"] }, order: {asc: name}) { @@ -1307,7 +1377,8 @@ } } -- name: "Order at root node without UID." +- + name: "Order at root node without UID." gqlquery: | query { queryAuthor(order: {asc: name}) { @@ -1322,7 +1393,8 @@ } } -- name: "Order and Pagination at root node without UID." +- + name: "Order and Pagination at root node without UID." gqlquery: | query { queryAuthor(order: {asc: name}, first: 2, offset: 3) { @@ -1338,7 +1410,8 @@ } -- name: "Filter with no valid id construct the right query with type func at root." +- + name: "Filter with no valid id construct the right query with type func at root." gqlquery: | query { queryAuthor(filter: { id: ["alice", "bob"], and: { name: { eq: "A. N. Author" } }}) { @@ -1353,7 +1426,8 @@ } } -- name: "Filter with id only includes valid id in dgquery." +- + name: "Filter with id only includes valid id in dgquery." gqlquery: | query { queryAuthor(filter: { id: ["0x1", "bob"], and: { name: { eq: "A. N. Author" } }}) { @@ -1368,7 +1442,8 @@ } } -- name: "Get editor without supplying anything" +- + name: "Get editor without supplying anything" gqlquery: | query { getEditor { @@ -1383,7 +1458,8 @@ } } -- name: "Get editor using code" +- + name: "Get editor using code" gqlquery: | query { getEditor(code: "tolstoy") { @@ -1398,7 +1474,8 @@ } } -- name: "Get editor using both code and id" +- + name: "Get editor using both code and id" gqlquery: | query { getEditor(code: "tolstoy", id: "0x1") { @@ -1413,7 +1490,8 @@ } } -- name: "Get with XID where no ID in type" +- + name: "Get with XID where no ID in type" gqlquery: | query { getState(code: "NSW") { @@ -1428,7 +1506,8 @@ } } -- name: "Query editor using code" +- + name: "Query editor using code" gqlquery: | query { queryEditor(filter: { code: { eq: "editor" }, and: { name: { eq: "A. N. Editor" }}}) { @@ -1443,7 +1522,8 @@ } } -- name: "Query editor using code and uid" +- + name: "Query editor using code and uid" gqlquery: | query { queryEditor(filter: { id: ["0x1"], and: { code: { eq: "editor"}}}) { @@ -1458,7 +1538,8 @@ } } -- name: "Query along reverse edge is converted appropriately" +- + name: "Query along reverse edge is converted appropriately" gqlquery: | query { queryMovie { @@ -1480,7 +1561,8 @@ } } -- name: "deprecated fields can be queried" +- + name: "deprecated fields can be queried" gqlquery: | query { queryCategory { @@ -1496,7 +1578,8 @@ } } -- name: "Password query" +- + name: "Password query" gqlquery: | query { checkUserPassword(name: "user1", pwd: "Password") {