How to use the dgraph-js.DgraphClientStub 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 dgraph-io / dgraph-js / examples / tls / index.js View on Github external
function newClientStub() {
    // First create the appropriate TLS certs with dgraph cert:
    //     $ dgraph cert
    //     $ dgraph cert -n localhost
    //     $ dgraph cert -c user
    const rootCaCert = fs.readFileSync(path.join(__dirname, 'tls', 'ca.crt'));
    const clientCertKey = fs.readFileSync(path.join(__dirname, 'tls', 'client.user.key'));
    const clientCert = fs.readFileSync(path.join(__dirname, 'tls', 'client.user.crt'));
    return new dgraph.DgraphClientStub(
        "localhost:9080",
        grpc.credentials.createSsl(rootCaCert, clientCertKey, clientCert));
}
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()
github dgraph-io / dgraph-js / examples / simple / index.js View on Github external
function newClientStub() {
    return new dgraph.DgraphClientStub("localhost:9080", grpc.credentials.createInsecure());
}
github dgraph-io / dgraph-js / examples / simple / index-pre-v7.6.js View on Github external
function newClientStub() {
    return new dgraph.DgraphClientStub("localhost:9080", grpc.credentials.createInsecure());
}
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
  }
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);

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