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 diff --git a/graphql/schema/wrappers.go b/graphql/schema/wrappers.go index ed7e4da78dd..6e8511e74fe 100644 --- a/graphql/schema/wrappers.go +++ b/graphql/schema/wrappers.go @@ -517,12 +517,12 @@ 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 Update and not Add here because - // Interfaces only have Update. + // 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["Update"+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 {