I’m brand new to DGraph, so excuse the basic question.
From what I’ve read in the documentation, I need to specify a schema with types. When mutating data, the docs all have uid and dgraph.type in the data.
However, I have a schema with only a searchable index defined (no types) and when I mutate data, I don’t specify uid or dgraph.type. Still, I can query on the defined index and get data back. So my question is: Do I need types in the schema and UIDs and dgraph.type in a mutation; if so, when?
So what you have calls a predicate.
In dgraph types are constructed from several predicats and each predicate can be in different types*
Assuming you use DQL (which is what you actually do) you don’t have to have types in your scheme in order to start working with dgraph.
about uids they are related to each node and generated automatically. You don’t have to specify them when inserting new data unless you connect between two nodes
*if you have predicate with a search index you can use it in several types but if currently if you want two types to have different indices you need 2 different predicates.
Hope that helps and let me know if you have more questions
Yes, you need them. Is strongly recommended that you have a well-defined Schema and types. Of course, Dgraph can handle your mutations and it will be stored, nothing is lost. But, to have some functions working you must to have the Type system aligned. Otherwise, delete(the most crucial one), expand, and so on won’t work for example.
If you already have data on the DB you can use Upsert block (with caution) to add the type tag on the entity. e.g
upsert {
query {
v as q(func: has(user.name))
}
mutation {
set {
uid(v) <dgraph.type> "User" .
}
}
}
That way you don’t need to treat your data again outside Dgraph.
The question about the UIDs on the mutation. It depends.
You just need to add the UID in a mutation if you are updating or deleting a known entity. Otherwise, you can use Blank nodes or nothing. Remove the UID key completely and you gonna create a new entity.
If you are new I recommend that you start with A Tour of Dgraph it is straightforward.