Class: Graphd::ClientStub

Inherits:
Object
  • Object
show all
Defined in:
lib/graphd/client_stub.rb

Overview

gRPC Client stub for DGraph This stub is a very thin wrapper over ‘GRPC::ClientStub`. It exists purely to provide sensible defaults relevant to DGraph like host and credentials

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost:9080', credentials = :this_channel_is_insecure, channel_override: nil, timeout: nil, channel_args: {}) ⇒ ClientStub

Creates a new Graphd::ClientStub

Parameters:

  • host (String) (defaults to: 'localhost:9080')

    the host the stub connects to

  • creds (GRPC::Core::ChannelCredentials|Symbol)

    the channel credentials, or :this_channel_is_insecure, which explicitly indicates that the client should be created with an insecure connection. Note: this argument is ignored if the channel_override argument is provided.

  • channel_override (GRPC::Core::Channel) (defaults to: nil)

    a pre-created channel

  • timeout (Number) (defaults to: nil)

    the default timeout in milliseconds to use in requests This will be used to set the deadline for every call made using this stub

  • channel_args (Hash) (defaults to: {})

    the channel arguments. Note: this argument is ignored if the channel_override argument is provided.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphd/client_stub.rb', line 25

def initialize(
  host = 'localhost:9080',
  credentials = :this_channel_is_insecure,
  channel_override: nil,
  timeout: nil,
  channel_args: {}
)
  @stub = Api::Dgraph::Stub.new(
    host,
    credentials,
    channel_override: channel_override,
    timeout: timeout,
    channel_args: channel_args
  )
end

Instance Attribute Details

#stubObject (readonly)

Returns the value of attribute stub.



11
12
13
# File 'lib/graphd/client_stub.rb', line 11

def stub
  @stub
end

Instance Method Details

#alter(operation) ⇒ Api::Payload

Run operations that alter the DGraph db like set schema and drop_all

Parameters:

Returns:



53
54
55
# File 'lib/graphd/client_stub.rb', line 53

def alter(operation)
  @stub.alter(operation)
end

#check_version(request) ⇒ Api::Version

Request the version of the DGraph server running on host

Parameters:

Returns:



45
46
47
# File 'lib/graphd/client_stub.rb', line 45

def check_version(request)
  @stub.check_version(request)
end

#commit_or_abort(transaction_context:) ⇒ Api::TxnContext

Commit a mutation or abort if it fails

Parameters:

Returns:



69
70
71
# File 'lib/graphd/client_stub.rb', line 69

def commit_or_abort(transaction_context:)
  @stub.commit_or_abort(transaction_context)
end

#query(request) ⇒ Api::Response

Query the db

Parameters:

Returns:



61
62
63
# File 'lib/graphd/client_stub.rb', line 61

def query(request)
  @stub.query(request)
end