Skip to content

Commit

Permalink
fix(GraphQL): fix for deletion on interfaces with no non Id field (#6387
Browse files Browse the repository at this point in the history
) (#6417)

Fixes GRAPHQL-655.

For this user schema (interface have no non-Id field):

```
interface A {
   name: String! @id
}

type B implements A {
  age: Int!
}
```
the following delete mutation
```
mutation{
  deleteA(filter:{name:{eq: "xyz"}}){
    a{
      name
    }
  }
}
```
was resulting in the following error:
```
{
  "errors": [
    {
      "message": "Internal Server Error - a panic was trapped.  This indicates a bug in the GraphQL server.  A stack trace was logged.  Please let us know by filing an issue with the stack trace."
    }
  ]
}
```
This PR fixes this bug and now deleting can be performed successfully.

(cherry picked from commit 742259b)
  • Loading branch information
minhaj-shakeel authored Sep 21, 2020
1 parent e55801b commit d7feabd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
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
}
10 changes: 5 additions & 5 deletions graphql/schema/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,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 {
Expand Down

0 comments on commit d7feabd

Please sign in to comment.