Most of the time you will use xSetupWithSchemaDataCommitTxn which does all of the above + optionally sets a schema and data.
const schema = `
name: string @index(exact) .
street: string @index(exact) .
`;
const sampleData = {
uid: "_:user",
name: "cameron",
addresses: [
{uid: "_:address1", street: "william", postcode: 2000},
{uid: "_:address2", street: "george", postcode: 2001},
{uid: "_:address3", street: "hay", postcode: 2444},
{uid: "_:address4", street: "short", postcode: 2107}
]
};
const {result, dgraphClient} = await xSetupWithSchemaDataCommitTxn({schema, data: sampleData});
Generated using TypeDoc
xGetSchemaMapTxn is useful for verifying you schema is what you think it is. Will ignore system predicates only returning the predicates you have set!
const schema = ` name: string @index(fulltext) . age: int . percent: float . awesome: bool . friend: uid @reverse . date: dateTime . location: geo . `; await xSetSchemaAlt(schema, dgraphClient); const schemaMap = await xGetSchemaMapTxn(dgraphClient); // check our schema expect(schemaMap.name.getType()).toBe('string'); expect(schemaMap.age.getType()).toBe('int');