From baa164dca3ea142e352da7d53230f849f5e491c4 Mon Sep 17 00:00:00 2001 From: vmrajas Date: Mon, 15 Mar 2021 18:09:25 +0530 Subject: [PATCH] Fix(GraphQL): Change variable name generation for interface auth rules (#7559) * Change variable name generation for interface auth rules * Add empty line at end of file --- graphql/resolve/auth_delete_test.yaml | 20 +++---- graphql/resolve/auth_query_test.yaml | 84 +++++++++++++-------------- graphql/resolve/auth_update_test.yaml | 34 +++++------ graphql/resolve/query_rewriter.go | 4 +- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/graphql/resolve/auth_delete_test.yaml b/graphql/resolve/auth_delete_test.yaml index 44ca9c8deaf..97422c5d0dc 100644 --- a/graphql/resolve/auth_delete_test.yaml +++ b/graphql/resolve/auth_delete_test.yaml @@ -671,28 +671,28 @@ "Author.posts": [ {"uid": "uid(x)"} ], - "uid": "uid(Author_5)" + "uid": "uid(Author_7)" }] dgquery: |- query { x as deletePost(func: uid(PostRoot)) { uid - Author_5 as Post.author + Author_7 as Post.author } - PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(Answer_Auth4))) + PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(Answer_Auth6))) Post_1 as var(func: uid(0x1, 0x2)) @filter(type(Post)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth4 as var(func: uid(Answer_1)) @cascade { + Answer_5 as var(func: type(Answer)) + Answer_Auth6 as var(func: uid(Answer_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name @@ -745,9 +745,9 @@ x as deleteA(func: uid(ARoot)) { uid } - ARoot as var(func: uid(A_1)) @filter((uid(B_1))) + ARoot as var(func: uid(A_1)) @filter((uid(B_2))) A_1 as var(func: uid(0x1, 0x2)) @filter(type(A)) - B_1 as var(func: type(B)) + B_2 as var(func: type(B)) } - name: "Delete Type Having Graph Traversal Auth Rules on Interface." diff --git a/graphql/resolve/auth_query_test.yaml b/graphql/resolve/auth_query_test.yaml index 65be3d5837c..b4e5dbd6f02 100644 --- a/graphql/resolve/auth_query_test.yaml +++ b/graphql/resolve/auth_query_test.yaml @@ -1457,27 +1457,27 @@ Post.text : Post.text dgraph.uid : uid } - PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(FbPost_Auth4) OR uid(Answer_Auth5))) + PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(FbPost_Auth6) OR uid(Answer_Auth8))) Post_1 as var(func: type(Post)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - FbPost_1 as var(func: type(FbPost)) - FbPost_Auth4 as var(func: uid(FbPost_1)) @cascade { + FbPost_5 as var(func: type(FbPost)) + FbPost_Auth6 as var(func: uid(FbPost_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth5 as var(func: uid(Answer_1)) @cascade { + Answer_7 as var(func: type(Answer)) + Answer_Auth8 as var(func: uid(Answer_7)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name @@ -1503,27 +1503,27 @@ Post.text : Post.text dgraph.uid : uid } - PostRoot as var(func: uid(Post_1), orderdesc: Post.text, first: 10, offset: 5) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(FbPost_Auth4) OR uid(Answer_Auth5))) + PostRoot as var(func: uid(Post_1), orderdesc: Post.text, first: 10, offset: 5) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(FbPost_Auth6) OR uid(Answer_Auth8))) Post_1 as var(func: type(Post)) @filter(eq(Post.text, "A Post")) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - FbPost_1 as var(func: type(FbPost)) - FbPost_Auth4 as var(func: uid(FbPost_1)) @cascade { + FbPost_5 as var(func: type(FbPost)) + FbPost_Auth6 as var(func: uid(FbPost_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth5 as var(func: uid(Answer_1)) @cascade { + Answer_7 as var(func: type(Answer)) + Answer_Auth8 as var(func: uid(Answer_7)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name @@ -1563,20 +1563,20 @@ Post.text : Post.text dgraph.uid : uid } - PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(Answer_Auth4))) + PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(Answer_Auth6))) Post_1 as var(func: type(Post)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth4 as var(func: uid(Answer_1)) @cascade { + Answer_5 as var(func: type(Answer)) + Answer_Auth6 as var(func: uid(Answer_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name @@ -1601,20 +1601,20 @@ Post.text : Post.text dgraph.uid : uid } - PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(Answer_Auth4))) + PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(Answer_Auth6))) Post_1 as var(func: uid(0x1)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth4 as var(func: uid(Answer_1)) @cascade { + Answer_5 as var(func: type(Answer)) + Answer_Auth6 as var(func: uid(Answer_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "Random")) { Author.name : Author.name @@ -1651,11 +1651,11 @@ A.fieldA : A.fieldA dgraph.uid : uid } - ARoot as var(func: uid(A_1)) @filter((uid(B_1) OR uid(C_Auth2))) + ARoot as var(func: uid(A_1)) @filter((uid(B_2) OR uid(C_Auth4))) A_1 as var(func: type(A)) - B_1 as var(func: type(B)) - C_1 as var(func: type(C)) - C_Auth2 as var(func: uid(C_1)) @filter(eq(C.fieldC, true)) @cascade { + B_2 as var(func: type(B)) + C_3 as var(func: type(C)) + C_Auth4 as var(func: uid(C_3)) @filter(eq(C.fieldC, true)) @cascade { C.id : uid } } @@ -1675,9 +1675,9 @@ A.fieldA : A.fieldA dgraph.uid : uid } - ARoot as var(func: uid(A_1)) @filter((uid(B_1))) + ARoot as var(func: uid(A_1)) @filter((uid(B_2))) A_1 as var(func: type(A)) - B_1 as var(func: type(B)) + B_2 as var(func: type(B)) } - @@ -1853,20 +1853,20 @@ Post.text : Post.text dgraph.uid : uid } - PostRoot as var(func: uid(Post_1)) @filter((uid(Question_Auth2) OR uid(FbPost_Auth3) OR uid(Answer_1))) + PostRoot as var(func: uid(Post_1)) @filter((uid(Question_Auth3) OR uid(FbPost_Auth5) OR uid(Answer_6))) Post_1 as var(func: uid(0x123)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid Question.text : Post.text } - FbPost_1 as var(func: type(FbPost)) - FbPost_Auth3 as var(func: uid(FbPost_1)) @cascade { + FbPost_4 as var(func: type(FbPost)) + FbPost_Auth5 as var(func: uid(FbPost_4)) @cascade { FbPost.author : Post.author @filter(eq(Author.name, "ADMIN")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) + Answer_6 as var(func: type(Answer)) checkPwd(func: uid(PostRoot)) @filter(type(Post)) { pwd as checkpwd(Post.pwd, "something") } @@ -1994,9 +1994,9 @@ Vehicle.owner : Vehicle.owner dgraph.uid : uid } - VehicleRoot as var(func: uid(Vehicle_1)) @filter((uid(Car_1))) + VehicleRoot as var(func: uid(Vehicle_1)) @filter((uid(Car_2))) Vehicle_1 as var(func: type(Vehicle)) - Car_1 as var(func: type(Car)) + Car_2 as var(func: type(Car)) } - diff --git a/graphql/resolve/auth_update_test.yaml b/graphql/resolve/auth_update_test.yaml index 29272c273cf..725444bdf3b 100644 --- a/graphql/resolve/auth_update_test.yaml +++ b/graphql/resolve/auth_update_test.yaml @@ -837,27 +837,27 @@ x as updatePost(func: uid(PostRoot)) { uid } - PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth2) AND uid(Question_Auth3)) OR uid(FbPost_Auth4) OR uid(Answer_Auth5))) + PostRoot as var(func: uid(Post_1)) @filter(((uid(Question_Auth3) AND uid(Question_Auth4)) OR uid(FbPost_Auth6) OR uid(Answer_Auth8))) Post_1 as var(func: uid(0x123, 0x456)) @filter(type(Post)) - Question_1 as var(func: type(Question)) - Question_Auth2 as var(func: uid(Question_1)) @filter(eq(Question.answered, true)) @cascade { + Question_2 as var(func: type(Question)) + Question_Auth3 as var(func: uid(Question_2)) @filter(eq(Question.answered, true)) @cascade { Question.id : uid } - Question_Auth3 as var(func: uid(Question_1)) @cascade { + Question_Auth4 as var(func: uid(Question_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name } } - FbPost_1 as var(func: type(FbPost)) - FbPost_Auth4 as var(func: uid(FbPost_1)) @cascade { + FbPost_5 as var(func: type(FbPost)) + FbPost_Auth6 as var(func: uid(FbPost_5)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth5 as var(func: uid(Answer_1)) @cascade { + Answer_7 as var(func: type(Answer)) + Answer_Auth8 as var(func: uid(Answer_7)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name @@ -892,17 +892,17 @@ x as updatePost(func: uid(PostRoot)) { uid } - PostRoot as var(func: uid(Post_1)) @filter((uid(FbPost_Auth2) OR uid(Answer_Auth3))) + PostRoot as var(func: uid(Post_1)) @filter((uid(FbPost_Auth3) OR uid(Answer_Auth5))) Post_1 as var(func: uid(0x123, 0x456)) @filter(type(Post)) - FbPost_1 as var(func: type(FbPost)) - FbPost_Auth2 as var(func: uid(FbPost_1)) @cascade { + FbPost_2 as var(func: type(FbPost)) + FbPost_Auth3 as var(func: uid(FbPost_2)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name } } - Answer_1 as var(func: type(Answer)) - Answer_Auth3 as var(func: uid(Answer_1)) @cascade { + Answer_4 as var(func: type(Answer)) + Answer_Auth5 as var(func: uid(Answer_4)) @cascade { dgraph.type Post.author : Post.author @filter(eq(Author.name, "user1")) { Author.name : Author.name @@ -964,8 +964,8 @@ x as updateA(func: uid(ARoot)) { uid } - ARoot as var(func: uid(A_1)) @filter((uid(B_1) OR uid(C_1))) + ARoot as var(func: uid(A_1)) @filter((uid(B_2) OR uid(C_3))) A_1 as var(func: uid(0x123, 0x456)) @filter(type(A)) - B_1 as var(func: type(B)) - C_1 as var(func: type(C)) - } \ No newline at end of file + B_2 as var(func: type(B)) + C_3 as var(func: type(C)) + } diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index fdcdca8526e..aae6ec8813e 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -728,8 +728,8 @@ func (authRw *authRewriter) addAuthQueries( continue } - // Form Query Like Todo1 as var(func: type(Todo)) - queryVar := object.Name() + "_1" + // Form Query Like Todo_1 as var(func: type(Todo)) + queryVar := authRw.varGen.Next(object, "", "", authRw.isWritingAuth) varQry := &gql.GraphQuery{ Attr: "var", Var: queryVar,