Dynamic Schema Generation

We want to go away with specifying a schema file and find out the schema of the predicate on run time (during first mutation).

For now we can store the schema at predicate level. Query to find out the schema of a predicate would look like

{
  schema(pred: "film.actor.film") {
    pred,
    type
  }
}

which would return(we can’t return name of object type as of now)

{
    "schema": {
      "pred": "film.actor.film",
      "type": "uid"
    }
}
{
  schema(pred: "film.actor.date_of_birth") {
    pred,
    type
  }
}
{
    "schema":{
       "pred": "film.actor.date_of_birth",
      "type": "DateTime"
    }
}

Query to fetch all predicates.

{
  schema {
    pred,
    type
  }
}
{
    "schema":[ { 
       "pred": "film.actor.date_of_birth",
      "type": "DateTime"
    },{
      "pred": "film.actor.film",
      "type": "uid"
    }
   ]
}
1 Like

Few things:

  • Instead of __type, let’s just use schema.
  • name should instead be pred schema(pred: "film.actor.film").
  • name inside should be type. We don’t need kind.
  • Also, we should have a way to return all the predicate types on the server. (Later we might need to query all other servers as well.)

I was playing around with dgraph today and found that having to include a schema file to start the server makes operations a bit cumbersome.

After going through the docs, I noticed that it is possible to define a type when creating a mutation, so that the schema won’t be needed. I opened an issue to store the schema within the cluster (Ability to store the schema on cluster · Issue #685 · dgraph-io/dgraph · GitHub) which might be related to this.

However, it appears that in order to use indexing, that will need to be defined in a schema. Are there any plans to deal with this problem, so it might be possible to use dgraph indexing without a schema in the future?

Hi @F21,

We’re already storing the schema withing Dgraph (Schema file is just something to start with). The types are inferred from the mutation (if not specified in schema). We’re working on allowing mutations to schema itself (Adding an index to a predicate, etc) and you can expect it with the next release.

Thanks!

1 Like

@ashwin95r is there a general timeline for a release that allows dynamic schema generation ?

@matthiasg: It’s been included in latest release

? That was fast. Will have a look at it then. Thanks !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.