Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GraphQL): fix for deletion on interfaces with no non Id field #6387

Merged
merged 4 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion graphql/resolve/delete_mutation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,30 @@
dgquery: |-
query {
x as deleteX()
}
}

-
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)"}]

4 changes: 4 additions & 0 deletions graphql/resolve/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,7 @@ type ThingTwo implements Thing {
prop: String @dgraph(pred: "prop")
owner: String
}

interface A {
name: String! @id
}
8 changes: 4 additions & 4 deletions graphql/schema/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ 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 {
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 {
Expand Down