Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { DgraphClientStub, DgraphClient, Operation, Mutation } from 'dgraph-js'
import { parse, GraphQLSchema, Source } from 'graphql'
import transformSchema from './transformSchema'
import buildSchema from './buildSchema'
import getInfo from './getInfo'
import type { SchemaInfo } from './getInfo'
export type ClientConfig = {
relay?: boolean,
debug?: boolean
}
const stub = new DgraphClientStub()
const client = new DgraphClient(stub)
const updateTypeName = 'SchemaUpdate'
export class Client {
_info: SchemaInfo
_debug: boolean
init: Promise
schema: GraphQLSchema
relay: boolean
constructor (config: ClientConfig) {
this._debug = config.debug || false
this.init = this.loadSchema()
this.relay = config.relay || false
}
loadSchema () {
function newClient(clientStub) {
return new dgraph.DgraphClient(clientStub);
}
#! /usr/bin/env node
const fs = require('fs')
const program = require('commander')
const { DgraphClientStub, DgraphClient, Operation } = require('dgraph-js')
const stub = new DgraphClientStub()
const client = new DgraphClient(stub)
const dropAll = () => {
const op = new Operation()
op.setDropAll(true)
return client.alter(op)
}
program
.arguments('')
.option('-s, --schema ', 'The schema to update')
.action((action, options) => {
if (action === 'update') {
const { Client } = require('./client')
const client2 = new Client({ relay: false, debug: false })
const schema = fs.readFileSync(options.schema).toString()
client2.updateSchema(schema).then(() => {
function newClient(clientStub) {
return new dgraph.DgraphClient(clientStub);
}
import { DgraphClientStub, DgraphClient, Operation, Mutation } from "dgraph-js";
import { AccountEntry, Ledger, EntryType } from "./model";
import { Collection, Ingestor } from "./ingest";
import grpc from "grpc";
import logger from "./common/util/logger";
import { DEBUG_LEDGER } from "./common/util/secrets";
const clientStub = new DgraphClientStub("localhost:9080", grpc.credentials.createInsecure());
const client = new DgraphClient(clientStub);
const dropAll = async () => {
const op = new Operation();
op.setDropAll(true);
await client.alter(op);
}
const setSchema = async () => {
const schema = `
type: string @index(exact) .
seq: int @index(int) .
id: string @index(exact) .
`;
const op = new Operation();
op.setSchema(schema);
await client.alter(op);
constructor(private environment: Environment) {
this.stub = new dgraph.DgraphClientStub(
`${environment.host}:${environment.port}`,
grpc.credentials.createInsecure()
)
this.client = new dgraph.DgraphClient(this.stub)
this.client.setDebugMode(environment.debug)
}
function newClient(clientStub) {
return new dgraph.DgraphClient(clientStub);
}
constructor(endpointUrl?: string) {
this.stub = new DgraphClientStub(endpointUrl || DGRAPH_QUERY_URL, grpc.credentials.createInsecure());
this.client = new DgraphClient(this.stub);
}