Generally, I’m interested how to explore a Dgraph database when you don’t know what is in there. Suppose someone has given you access to a Dgraph instance, what’s the first query you run to start working out what’s in there? Or is GraphQL± not the tool for the job and you should find the schema or get the information out-of-band?
My specific case is I’ve used the Bulk loader to load some RDF and let it construct the schema itself. The RDF looks like:
I don’t know if the property name was loaded with the full URI like http://example.com#linked_to or shortened somehow
if full URIs are used, I can’t figure out how to escape the names in a GraphQL± query. Any queries that use the full URI complain about the : (colon) character. I’ve tried escaping with single quotes, double quotes and backticks but none seem to work. Google queries for “dgraph escape” aren’t yielding anything either.
I can’t find the generated schema. I’m running in Docker and I’ve done a docker exec into the container to look around but can’t find a schema
Solutions to my specific case are appreciated but I’m more interested in the general skill of exploring a Dgraph DB with no prior knowledge. In a relational world I’d get some tables names, describe them then start doing some SELECT * queries to get a feel for the DB. In other NoSQL DBs there’s typically some wildcard type queries where you can start looking at some data, any data! In GraphQL± I’m stuck, I can’t figure out a SELECT * type query.
I’ve tried guessing at UIDs but no matter what UID I used, I get a response but without any edge names:
{
f(func: uid(0x00)) {
uid
linked_to # here I'm guessing the RDF property was shortened
}
}
Then start looking at some of the nodes. E.g. use the has function to find all nodes with a particular predicate (discovered from the schema query). https://docs.dgraph.io/query-language/#has
Next step would be to start expanding the graph using expand(_all_) and start to explore the relationships.
GrahpQL± and Ratel are great for this, since Ratel helps to visualise the relationships (which would otherwise be harder to understand just looking at the raw JSON responses).
For predicate names, I would recommend using simplified predicate names, e.g. type and linked_to. You would have to pre-process your data, but it will make everything much easier for you. Although, if you really want to use URIs for predicates, you should be able to escape using a backslash.
Hi Peter,
thanks for the helpful tips. They’re exactly what I needed.
I don’t want to use URIs for predicates, that’s just what my RDF data has in it and I was trying to quickly get Dgraph up and running with my data to take it for a test drive. If I’m going to be pre-processing the RDF, I’ll strip the names down to simple ones like you suggest.
For what it’s worth, I can’t get that backslash escaping to work. A query like this works, so we know it’s a good starting point:
{
me(func: has(age)) {
expand(_all_)
}
}
Then I change the predicate name to a full URI, which we expect to fail: