Simple Dgraph schema to GraphQL schema mapping doesn't work

I missed that in your OP. sorry.

So, from my understanding, using the @dgraph mapping will take care of not needing the Type.field in Dgraph schema, but you still need the node type.

Try this:

{
  "set": [
    {
      "dgraph.type": "Person",
      "name": "Karthic",
      "age": 28,
      "follows": {
        "dgraph.type": "Person",
        "name": "Jessica",
        "age": 31
      }
    }
  ]
}

If you already have existing schema and data, you will need to apply types to the nodes themselves but you can leave the existing predicates alone. You could follow the Bulk Upsert Exampled here to achieve this:

upsert {
  query {
    v as var(func: has(name)) { # a filter to find the nodes that should be a Person
      getValues as name #we won't be using this part...
    }
  }

  mutation {
    set {
       uid(v) <dgraph.type> "Person" .
    }
  }
}

Of course you would have to be careful with your filter to make sure that it only gets Person types. An instance where this would not work very well is if your schema uses many of the same predicates for different types (ie: If you have other nodes with name and age is an optional predicate then the only way to set the dgraph.type would be through listing the specific uids that need to be that type.

2 Likes