Dgraph Schema - Custom Properties?

Hi all,

I’m new to DGraph and to Graph Databases generally so apologies if my terminology/knowledge isn’t great.

One of the core design features of the software I want to build is that superusers are able to update the database schema.

For example we might have a person type with a first name, last name etc. and they want to record the date of birth as well. So they can go to a form, create a field that’s a date time and submit their request and then the web server / api checks that’s all fine and make that request to the database.

Now the fields they’re creating themselves might have “custom properties” for its own uses, which aren’t part of the core dgraph schema e.g. I know we can store data in multiple languages in dgraph, but what about storing the name of the field “first name” in multiple languages? what about if I want to store custom flags for the field, for example, which user groups have permission to modify it etc.

I just wanted to query the best way to do this in dgraph. Is the schema in dgraph itself a graph that can have properties and relationships for example?

What about using a Type to dynamically build a schema? Just an idea. Then add a trigger on the post mutation to that type that runs a script to build and push the schema out.

Welcome @mgroberts,

We can add fields dynamically. The client apis support alter commands.

The predicate definition in Dgraph does not directly support addition of metadata. By extension, the query language also does not have any metadata flex. However, you could name your predicates with a url like syntax your-business/firstName. You could then make this url text point to metadata, either as a simple node in Dgraph itself or some other service. There is no way to dynamically “join” this information at runtime from Dgraph directly, but clients can query this metadata and construct queries accordingly.

Thanks @anand. That’s a creative solution.

Is there a list of allowed/disallowed characters in predicates?

1 Like

Hi @mgroberts glad to be of help.

The predicate name rules are available at this link.