Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function dropAll(dgraphClient) {
const op = new dgraph.Operation();
op.setDropAll(true);
await dgraphClient.alter(op);
}
async function setSchema(dgraphClient) {
const schema = `
name: string @index(exact) .
age: int .
married: bool .
loc: geo .
dob: datetime .
friend: [uid] @reverse .
`;
const op = new dgraph.Operation();
op.setSchema(schema);
await dgraphClient.alter(op);
}
const dropAll = async () => {
const op = new Operation();
op.setDropAll(true);
await client.alter(op);
}
async function dropAll(dgraphClient) {
const op = new dgraph.Operation();
op.setDropAll(true);
await dgraphClient.alter(op);
}
function setSchema(dgraphClient) {
const schema = `
name: string @index(exact) .
age: int .
married: bool .
loc: geo .
dob: datetime .
`;
const op = new dgraph.Operation();
op.setSchema(schema);
return dgraphClient.alter(op);
}
function dropAll(dgraphClient) {
const op = new dgraph.Operation();
op.setDropAll(true);
return dgraphClient.alter(op);
}
async updateSchema (schema: string) {
const ast = transformSchema(parse(new Source(schema)), this.relay)
const info = getInfo(ast)
let gql = ''
for (var [key, value] of info) {
gql += key + ': ' + value.type
if (value.indexes.size) {
gql += ' @index(' + [...value.indexes].join(',') + ')'
}
gql += ' .\n'
}
const op = new Operation()
op.setSchema(gql)
await client.alter(op)
const version = 1
schema = schema.replace(/\n/g, '\\n')
schema = schema.replace(/"/g, '\\"')
let sets = `_:node "" .\n`
sets += `_:node <__typename> "${updateTypeName}" .\n`
sets += `_:node "${schema}" .\n`
sets += `_:node "${version}" .\n`
const mutation = new Mutation()
mutation.setCommitNow(true)
mutation.setSetNquads(new Uint8Array(new Buffer(sets)))
const txn = client.newTxn()
await txn.mutate(mutation)
}
async applySchema(schema: string, retries = 0): Promise {
try {
log("Apply schema take", retries, "schema: ", schema)
const op = new dgraph.Operation()
op.setSchema(schema)
await this.client.alter(op)
} catch (e) {
if (shouldRetry(e, retries)) {
await waitPromise(`schema ${schema}`)
return await this.applySchema(schema, retries + 1)
} else {
log(e)
throw Error(e)
}
}
}
async disconnect() {