Support custom types in schema in place of uid type predicates with strict mutations

Moved from GitHub dgraph/4675

Posted by Fantastitech:

What you wanted to do

I’m creating a schema for some highly-structured, deeply-nested data and I’m running my database with strict mutations on as I have no use for arbitrary nodes in this application.

I’m fleshing out the schema for score keeping for a game. Let’s say I have a “Game” node type. The “Game” node has a “Players” predicate that looks like this: <Players>: [uid] .

“Players” is a predicate for edges to “User” which is also a custom type in my schema. I would like to be able to write my schema as <Players>: [User] . to indicate that this predicate has a type of uid specifically to nodes with the custom type User. Ideally a mutation would fail if the node does not have the correct type applied to it when strict mutations are enabled.

What you actually did

Currently I’m just using uid types on these predicates which will accept the creation of edges to any arbitrary node.

Why that wasn’t great, with examples

The type system seems to be of extremely limited use in its current state. It does not work for enforcing types on mutations, there is no inheritance or nesting possible so it’s only good for a single level of data, and the attributes themselves seem to serve little to no purpose. The only use-case I can find for custom types is logically separating the difference between a “Name” predicate on two different node types so you don’t need to create two different unique “Name” predicates.

The ability to use custom types as enforceable types on predicates would make the custom type system and the strict mutation system drastically more useful for enforcing highly structured data and avoiding issues from typos or unexpected bugs.

marvin-hansen commented :

Have you looked into the GrapQL support?

https://graphql.dgraph.io/

It seems to support inheritance, not so sure about custom types.

I have a very similar use case and porting an existing schema of about 1.2kloc to get some answers soon.

MichelDiz commented :

About checking mutations, you can use the “strict” mutation setting https://docs.dgraph.io/deploy/#restrict-mutation-operations