Enforce schema

I’ve been running Dgraph for a while in a PoC system, and I’m surprised to find that, in some data, some fields from a different type are in another type. In pseudocode, let say I have:

type Money {
    o_amount: Int
    o_currency: String

type Txn {
    x_amount: Money
    x_date: : String

type Message {
    m_payload: String

The “bad” data I found:

m_payload: "Hello"
o_amount: 100
o_currency: "USD"

As you can see from the schema, o_* are Money fields, but for some reason exist in (some) Message.

I’m sure it’s my code bug, but I’m only aware of this when I use expand(_all_) (I usually spell out the fields I want).

My question:

How do I enforce schema so that an object can only use fields from its type?

Not only the field names, but also the type and whether it’s an array/not. I have another case where the data is an array [] instead of object {}.

Dgraph does not enforce restrictions on fields based on types while mutating/inserting records. However, clients can introspect the schema and use the details to enforce restrictions.