How to use the dgraph-js.DgraphClient function in dgraph-js

To help you get started, we’ve selected a few dgraph-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dpeek / dgraphql / src / client.js View on Github external
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 () {
github dgraph-io / dgraph-js / examples / simple / index-pre-v7.6.js View on Github external
function newClient(clientStub) {
    return new dgraph.DgraphClient(clientStub);
}
github dpeek / dgraphql / src / cli.js View on Github external
#! /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(() => {
github dgraph-io / dgraph-js / examples / simple / index.js View on Github external
function newClient(clientStub) {
    return new dgraph.DgraphClient(clientStub);
}
github astroband / astrograph / src / dgraph.ts View on Github external
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);
github gverse / gverse / src / gverse / connection.ts View on Github external
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)
  }
github dgraph-io / dgraph-js / examples / tls / index.js View on Github external
function newClient(clientStub) {
    return new dgraph.DgraphClient(clientStub);
}
github astroband / astrograph / src / storage / connection.ts View on Github external
constructor(endpointUrl?: string) {
    this.stub = new DgraphClientStub(endpointUrl || DGRAPH_QUERY_URL, grpc.credentials.createInsecure());

    this.client = new DgraphClient(this.stub);
  }

dgraph-js

Official javascript client for Dgraph

Apache-2.0
Latest version published 3 months ago

Package Health Score

70 / 100
Full package analysis

Similar packages