Have many `schema`s

I wanted to try out Node types and got this documentation https://docs.dgraph.io/howto/#giving-nodes-a-type

And ended up with this Python code that seems to work.

import pydgraph
import json

client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)

# Create Schema
schema = """type: string @index(exact) .
            name: string ."""
op = pydgraph.Operation(schema=schema)

# Data
txn = client.txn()
p = {
    "type": "People",
    "name": "Alpha",
assigned = txn.mutate(set_obj=p)

q = {
    "type": "People",
    "name": "Beta",
assigned = txn.mutate(set_obj=q)

# Fetch type people
# Fetch Data
query = """query all($a: string) {
    all(func: eq(type, $a)) {
        expand(_all_) {}
variables = {'$a': 'People'}

# Print
res = client.query(query, variables=variables)
ppls = json.loads(res.json.decode('utf-8'))

for ppl in ppls["all"]:

But I want to have isolated/different Schema for different node types, with different properties. (ie. instead of one big schema with 1000 properties, have 100 separate schema with 10 properties each)

I saw this post, but didn’t find a working sample Dgraph schema system

1 Like

I also have same question here

1 Like

This separation does not exist. Generally many nodes share the same predicate. E.g: Name.
If you want extraordinarily separate you can create specific predicates like:


your code is different from the one shown in the documentation. The documentation approach is about giving nodes types via unique predicates. And not a single predicate named “Type” indexed. This is another possible approach, but not specifically recommended.

In the case of the recommended approach your code should look like this:

p = {
    "_People": "*",
    "name": "Alpha",

And your query:

  q(func: has(_People)) {
1 Like

If i have more then 10 node types, then how we get the list of distinct node type?

Usually you create a pattern of Kinds. You can query for predicates like this:
schema {}

or use Ratel and filter by the pattern you used.

Let’s say that your Kinds pattern starts with has (type_person)
In Ratel you would write in the filter “type_” and a list of predicates would appear with


thank you, if this was documented in a tutorial it would have been much better

1 Like