From da56a8d44f334e35795b52eed85914d407d9da33 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Thu, 3 Sep 2020 20:58:39 +0530 Subject: [PATCH 1/4] fix for deletion on interfaces with no non Id field --- graphql/schema/wrappers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphql/schema/wrappers.go b/graphql/schema/wrappers.go index ed7e4da78dd..944ad64966d 100644 --- a/graphql/schema/wrappers.go +++ b/graphql/schema/wrappers.go @@ -518,10 +518,10 @@ func mutatedTypeMapping(s *schema, } // This is a convoluted way of getting the type for mutatedTypeName. We get the definition // for UpdateTPayload and get the type from the first field. There is no direct way to get - // the type from the definition of an object. We use Update and not Add here because - // Interfaces only have Update. + // the type from the definition of an object. We use Delete and not Update or Add here because + // Interfaces can't have Add and if there is no non Id field then Update also will not be there. var def *ast.Definition - if def = s.schema.Types["Update"+mutatedTypeName+"Payload"]; def == nil { + if def = s.schema.Types["Delete"+mutatedTypeName+"Payload"]; def == nil { def = s.schema.Types["Add"+mutatedTypeName+"Payload"] } From 8c1fc8ea9487480ae8d45e25adfe02c2bdaee0d2 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Fri, 4 Sep 2020 20:14:42 +0530 Subject: [PATCH 2/4] fix for acl test failures --- graphql/schema/wrappers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/schema/wrappers.go b/graphql/schema/wrappers.go index 944ad64966d..20b0cbe573e 100644 --- a/graphql/schema/wrappers.go +++ b/graphql/schema/wrappers.go @@ -521,8 +521,8 @@ func mutatedTypeMapping(s *schema, // the type from the definition of an object. We use Delete and not Update or Add here because // Interfaces can't have Add and if there is no non Id field then Update also will not be there. var def *ast.Definition - if def = s.schema.Types["Delete"+mutatedTypeName+"Payload"]; def == nil { - def = s.schema.Types["Add"+mutatedTypeName+"Payload"] + if def = s.schema.Types["Add"+mutatedTypeName+"Payload"]; def == nil { + def = s.schema.Types["Delete"+mutatedTypeName+"Payload"] } if def == nil { From 3b860a6435315adc90c5632075b8075ac529309f Mon Sep 17 00:00:00 2001 From: Pawan Rawal Date: Sun, 6 Sep 2020 21:11:20 +0530 Subject: [PATCH 3/4] Add a unit test --- graphql/resolve/delete_mutation_test.yaml | 28 ++++++++++++++++++++++- graphql/resolve/schema.graphql | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/graphql/resolve/delete_mutation_test.yaml b/graphql/resolve/delete_mutation_test.yaml index b2e970b9ad8..bd884725eec 100644 --- a/graphql/resolve/delete_mutation_test.yaml +++ b/graphql/resolve/delete_mutation_test.yaml @@ -265,4 +265,30 @@ dgquery: |- query { x as deleteX() - } \ No newline at end of file + } + +- + name: "Deleting an interface with just a field with @id directive" + gqlmutation: | + mutation{ + deleteA(filter:{name:{eq: "xyz"}}){ + a{ + name + } + } + } + dgquery: |- + query { + x as deleteA(func: type(A)) @filter(eq(A.name, "xyz")) { + uid + } + a(func: uid(x)) { + dgraph.type + name : A.name + dgraph.uid : uid + } + } + dgmutations: + - deletejson: | + [{ "uid": "uid(x)"}] + diff --git a/graphql/resolve/schema.graphql b/graphql/resolve/schema.graphql index eef8ed55b4e..ed3211e6e93 100644 --- a/graphql/resolve/schema.graphql +++ b/graphql/resolve/schema.graphql @@ -282,3 +282,7 @@ type ThingTwo implements Thing { prop: String @dgraph(pred: "prop") owner: String } + +interface A { + name: String! @id +} \ No newline at end of file From deef1531362358f114ab6d45911482d2238d7f79 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Mon, 7 Sep 2020 10:42:59 +0530 Subject: [PATCH 4/4] modify comment --- graphql/schema/wrappers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphql/schema/wrappers.go b/graphql/schema/wrappers.go index 20b0cbe573e..6e8511e74fe 100644 --- a/graphql/schema/wrappers.go +++ b/graphql/schema/wrappers.go @@ -517,9 +517,9 @@ func mutatedTypeMapping(s *schema, default: } // This is a convoluted way of getting the type for mutatedTypeName. We get the definition - // for UpdateTPayload and get the type from the first field. There is no direct way to get - // the type from the definition of an object. We use Delete and not Update or Add here because - // Interfaces can't have Add and if there is no non Id field then Update also will not be there. + // for AddTPayload and get the type from the first field. There is no direct way to get + // the type from the definition of an object. Interfaces can't have Add and if there is no non Id + // field then Update also will not be there, so we use Delete if there is no AddTPayload. var def *ast.Definition if def = s.schema.Types["Add"+mutatedTypeName+"Payload"]; def == nil { def = s.schema.Types["Delete"+mutatedTypeName+"Payload"]