Trouble making inverse query when implementing interface

Schema Snippet:

type Relationship {
  id: ID!
  name: String!
  type: RelationshipCategory!
  meta: [RelationshipMeta]
  of: Contact
  to: Contact
}
type RelationshipMeta implements SettingACL {
  forRelationship: Relationship! @hasInverse(field: meta)
}
type RelationshipCategory implements Tag {
  usedIn: [Relationship] @hasInverse(field: type)
}
interface SettingACL {
  id: ID!
  name: ControlledSetting! @hasInverse(field: usedIn)
  isTrue: Boolean
}
interface Tag {
  id: ID!
  slug: String
  name: String
}
type ControlledSetting {
  id: ID!
  name: String!
  usedIn: [SettingACL]
}
type Contact {
  id: ID!
  name: String
  relationshipTo: [Relationship] @hasInverse(field: of)
  relationshipOf: [Relationship] @hasInverse(field: to)
}

I inserted some data using this mutation:

mutation {
  addRelationship(input: [{
    name: "Staff"
    type: { id: "0x225f22" }
    of: { id: "0x111" }
    to: { id: "0x222" }
    meta: [{
      name: { id: "0x20d86b" }
      isTrue: true
    }]
  }]) { numUids }
}

Now I want to find that relationship based upon the ControlledSetting "0x20d86b"

So I have tried this:

query {
  getControlledSetting(id:"0x20d86b") {
    id
    name
    usedIn {
      forRelationship {
        to {
          id
        }
      }
    }
  }
}

But this gives the error:

Cannot query field “forRelationship” on type “SettingACL”. Did you mean to use an inline fragment on “RelationshipMeta”?

So I tried to use the inline fragment instead:

{
  getControlledSetting(id:"0x20d86b") {
    id
    name
    usedIn(first: 10) {
      ...on RelationshipMeta {
        forRelationship {
          id
        }
      }
    }
  }
}

And I get the following error:

Non-nullable field ‘forRelationship’ (type Relationship!) was not present in result from Dgraph. GraphQL error propagation triggered.

This data should not be null because it should have been set in the mutation above.

Can someone point me in the direction of what I have done incorrectly here?

@pawan or any other @core-devs can you advise?

Looks like a bug to me at present. I am going to try and reproduce this tomorrow morning and confirm whether it’s a bug or not.

1 Like

Here is a way to duplicate it using the schema from the OP:

mutation AddRelationship {
  addRelationship(input: [{
    name: "Progeny"
    type: { id: "0x5" }
    of: { id: "0x3" }
    to: { id: "0x4" }
    meta: [{
      name: { id: "0x6" }
      isTrue: true
    }]
  }]) { numUids }
}

mutation AddData {
  addContact(input: [{
    name: "Bob"
  }{
    name: "John"
  }]) {
    contact {
      id
      name
    }
  }
  addRelationshipCategory(input:[{
    slug:"progeny"
    name:"Progeny"
  }]) {
    relationshipCategory {
      id
      slug
    }
  }
  addControlledSetting(input:[{
    name: "close"
  }]) {
    controlledSetting {
      id
      name
    }
  }
}
query CloseRelationships {
  getControlledSetting(id:"0x6") {
    id
    name
    usedIn {
      ...on RelationshipMeta {
      	forRelationship {
          id
        	to {
          	id
        	}
      	}
      }
    }
  }
}
mutation deleteRelationship {
  deleteRelationship(filter:{id:["0x7"]}) {
    numUids
  }
}
mutation deleteAll {
  deleteContact(filter:{}){numUids}
  deleteRelationshipCategory(filter:{}){numUids}
  deleteControlledSetting(filter:{}){numUids}
  deleteRelationshipMeta(filter:{}){numUids}
}
  1. Run mutation addData
  2. Look at the response and:
  3. Replace 0x3 with the ID of Bob
  4. Replace 0x4 with the ID of John
  5. Replace 0x5 with the ID of progeny
  6. Replace 0x6 with the ID of close (It is in the above script twice)
  7. Run the AddRelationship mutation as many times as you want
  8. Run the CloseRelationships query
  9. Look at the respnse and
  10. Replace 0x7 with the ID at data.getControlledSetting.usedIn[*].forRelationship.id
  11. Run the deleteRelationship
  12. Run the CloseRelationships query again

ERROR

  • To reset, run the deleteAll mutation and repeat steps 1-12

This might be totally on me and how I am deleting data. I have deleted Relationships that had meta edges, but those meta (RelationshipMeta) were not also deleted. So that is what is propagating the error.

So I guess this ties into my other topic:

I wasn’t thinking the orphaned data would be important and I just skipped over deleting the children. In order to delete all of them I would have to change my UI from deleting a single type by ID to now query that type by ID and get the ID of all of the children that also need deleted and then run a mutation deleting the type by ID and the children by IDs. This is what it will take to keep the UI on a GraphQL endpoint only and make a deep delete.

I guess I could remove the required field, the dilemma…

I will just remove the ! off from RelationshipMeta.forRelationship. That is the easiest fix without deep deleting children.

When has comes to slash, I should be able to use it to clean up some of the orphaned children.

What would be awesome: (I think I suggested this somewhere before too)

If the Non-nullable field ‘fieldName’ (type fieldName!) was not present in result from Dgraph. GraphQL error propagation triggered. was caught before it reached the client and it acted like a cascade instead removing any fields that were required but not present.