Partially typed schema

I know in advance what structure I expect to receive for some parts of my data but one certain field can contain arbitrary JSON.

I want to be able to return the original JSON by following the node and run some aggregates over that JSON since I know names of certain fields.

What would be the best approach to handle that and what are my options?

Currently running

mutation = txn.create_mutation(set_obj=partial_data)
request = txn.create_request(mutations=[mutation], commit_now=True)
result = txn.do_request(request)

gives me awful lots of predicates and pollutes the namespace which is expected.

I want to receive the uid of inserted data and use it as a pointer from the strongly typed parts.

Any way to handle this without messing up my predicates and being able to run some limited queries?

After a mutation, you have to do a new query. Or use a method to return the UIDs created in that mutation. No mutation operation will return the inserted data.

Thanks for answering (:

Exactly. I’m using the UIDs created in that mutation to set edges to point at new data. Below is an example to illustrate what I’m trying to achieve.

type MyProduct {
} string @index(term) .
product.props: uid .

A product always has a name string and some properties which are basically arbitrary JSON. I add “uid” key to props JSON so that I could identify the root node UID and set product.props to that value.

First thing - it pollutes predicate namespace with all the keys present in props JSON. Second - expand doesn’t work without a type hence I can’t retrieve the original props JSON.

I came up with a hack to just prepend all keys in props with prop. but that seems messy.

Is there any better way to store arbitrary JSONs for props and retrieving them back while having the ability to query over props?

Do you mean an JSON type? We don’t support JSON “blob” or something. Only the basic types like Int, String and so on.

Currently I went with storing that jsons as base64 strings and that’s ok. As for the original idea, consider the following data:

{'a': 1, 'b': 2.0, 'meta': {'cd': [1, 2, 3], 'ef': 0.5}}
{'a': 1, 'b': 2.0, 'meta': {'name': 'Andrew'}}
{'a': 1, 'b': 2.0, 'meta': {'location': {'lat': 1.27, 'lng': 0.44}}}

I can build schema for ‘a’ and ‘b’ because I know the types, as for the ‘meta’ - I don’t know what could it be, but the space of variations is finite.

Is it possible to save ‘meta’ in Dgraph and be able to query it, without getting all sorts of conflict with my own predicates?

The only hack that I came up with was to preprocess and append random salt to all keys inside ‘meta’.

Try to use facets