Nested Mutation do not create links after the first level of nesting

Given the schema

interface Metadata {
  id: String! @id @search(by: [hash])
}

interface WithName {
  names: [TextWrapper!]!
}

type TextWrapper implements Metadata {
  text: Text! 
  localization: String!
  isName: [WithName!]! @hasInverse(field: names)
}

type Text implements Metadata {
  string: String! @search(by: [trigram, term, fulltext])
}

type Person implements Metadata & WithName {
    age: Int!
    parents: [Person!]!
}

type Company implements Metadata & WithName {
    address: String!
}

and performing the mutation

mutation {
  addPerson(input:[{
    id: "aaaa",
    age: 23,
    names: [
      {
      id: "bbbb",
      text: {id: "cccc", string: "Mario"},
      localization: "it",
    },
    {
      id: "dddd",
      text: {id: "eeee", string: "マリオ"},
      localization: "ja",
    }
    ],
    parents:[{
    id: "ffff",
    age: 50,
    names: [{
      id: "gggg",
      text: {id: "hhhh", string: "Leonardo"},
      localization: "it",
    },
    {
      id: "iiiii",
      text: {id: "jjjjj", string: "レオナルド"},
      localization: "ja",
    }],
      parents:[],
    }]
    }]
  ) {
    numUids
  }
  addCompany(input:[{
    names: [{
      id: "dfsdf",
      text: {id: "qwer", string: "Shueisha"},
      localization: "it"
    }],
    id: "shu",
    address: "via Roma"
  }]) {
    numUids
  }
}

Dgraph do not create the relation TextWrapper.text between the node TextWrapper and Text as shown in the GraphQl± query bellow:

{
    q(func: eq(Metadata.id, "aaaa")) {
   expand(_all_){
      expand(_all_) {
         expand(_all_)
      }
    }
  }
}

=>

{
  "data": {
    "q": [
      {
        "Person.age": 23,
        "Person.parents": [
          {
            "Metadata.id": "ffff",
            "WithName.names": [
              {
                "TextWrapper.localization": "it",
                "Metadata.id": "gggg"
              },
              {
                "TextWrapper.localization": "ja",
                "Metadata.id": "iiiii"
              }
            ],
            "Person.age": 50
          }
        ],
        "Metadata.id": "aaaa",
        "WithName.names": [
          {
            "Metadata.id": "bbbb",
            "TextWrapper.localization": "it",
            "TextWrapper.isName": [
              {
                "Metadata.id": "aaaa",
                "Person.age": 23
              }
            ]
          },
          {
            "Metadata.id": "dddd",
            "TextWrapper.localization": "ja",
            "TextWrapper.isName": [
              {
                "Metadata.id": "aaaa",
                "Person.age": 23
              }
            ]
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 53100,
      "processing_ns": 4460900,
      "encoding_ns": 86600,
      "assign_timestamp_ns": 574100,
      "total_ns": 5224400
    },
    "txn": {
      "start_ts": 17
    },
    "metrics": {
      "num_uids": {
        "Metadata.id": 7,
        "Person.age": 3,
        "Person.parents": 3,
        "TextWrapper.isName": 4,
        "TextWrapper.localization": 4,
        "TextWrapper.text": 4,
        "WithName.names": 3,
        "_total": 28
      }
    }
  }
}

while the note text have been successfully created

{
    q(func: eq(Metadata.id, "eeee")) {
   expand(_all_){
      expand(_all_) {
         expand(_all_)
      }
    }
  }
}
{
  "data": {
    "q": [
      {
        "Text.string": "マリオ",
        "Metadata.id": "eeee"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 47300,
      "processing_ns": 6290400,
      "encoding_ns": 20100,
      "assign_timestamp_ns": 484300,
      "total_ns": 6878300
    },
    "txn": {
      "start_ts": 23
    },
    "metrics": {
      "num_uids": {
        "Metadata.id": 1,
        "Text.string": 1,
        "_total": 2
      }
    }
  }
}

running the mutation separatelly, firstly creating the text nodes and then the Person and Company nodes solves the bug

mutation {
  addText(input:[
  {id: "cccc", string: "Mario"},
     {id: "eeee", string: "マリオ"},
    {id: "hhhh", string: "Leonardo"},
    {id: "jjjjj", string: "レオナルド"},
    {id: "qwer", string: "Shueisha"},
  ]) {
    numUids
  }
  addPerson(input:[{
    id: "aaaa",
    age: 23,
    names: [
      {
      id: "bbbb",
      text: {id: "cccc"},
      localization: "it",
    },
    {
      id: "dddd",
      text: {id: "eeee"},
      localization: "ja",
    }
    ],
    parents:[{
    id: "ffff",
    age: 50,
    names: [{
      id: "gggg",
      text: {id: "hhhh"},
      localization: "it",
    },
    {
      id: "iiiii",
      text: {id: "jjjjj"},
      localization: "ja",
    }],
      parents:[],
    }]
    }]
  ) {
    numUids
  }
  addCompany(input:[{
    names: [{
      id: "dfsdf",
      text: {id: "qwer"},
      localization: "it"
    }],
    id: "shu",
    address: "via Roma"
  }]) {
    numUids
  }
}
1 Like

Hey @Luscha

This is a known regression. @amaster507 also pointed it out last week. We are working on it and should have a fix this week.

3 Likes

Thank you!
Sorry for double report, didn’t see the other post

A fix for the issue was merged to master and would be part of the 20.07.1 release. You can check it out on the docker image for master. The fix should also be part of the next Slash GraphQL release.