amaster507
(Anthony Master)
September 18, 2020, 9:02pm
1
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?
amaster507
(Anthony Master)
September 22, 2020, 12:54pm
2
@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
amaster507
(Anthony Master)
September 22, 2020, 8:56pm
4
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}
}
Run mutation addData
Look at the response and:
Replace 0x3
with the ID of Bob
Replace 0x4
with the ID of John
Replace 0x5
with the ID of progeny
Replace 0x6
with the ID of close (It is in the above script twice)
Run the AddRelationship
mutation as many times as you want
Run the CloseRelationships
query
Look at the respnse and
Replace 0x7
with the ID at data.getControlledSetting.usedIn[*].forRelationship.id
Run the deleteRelationship
Run the CloseRelationships
query again
ERROR
To reset, run the deleteAll
mutation and repeat steps 1-12
amaster507
(Anthony Master)
September 22, 2020, 9:37pm
5
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:
Here is my schema:
type Contact {
id: ID
name: String!
relationshipsTo: [Relationship] @hasInverse(field: of)
relationshipsOf: [Relationship] @hasInverse(field: to)
}
type Relationship {
id: ID
name: String @search(by: [hash])
of: Contact
to: Contact
meta: [RelationshipMeta]
}
type RelationshipMeta {
id: ID
name: String!
value: String!
}
I have existing contacts, that I do not want to delete, I have added a bunch of relationships and want to delete all of the relationshâŚ
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.
This was not a bug, just a consequence of malformed data.