graphd 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88eb11e1213f9fec8d7a0878d7843fe27c964d1bf58411723a786d05336030dd
4
- data.tar.gz: 615be59bdd018561230ef2a94d03b1621944ff8795c35d24b22fa622104097d5
3
+ metadata.gz: 98359f417fb784ec316e80de7298c05e7b69ba5910de8f85ae168bdfc9aefc4d
4
+ data.tar.gz: 06374bfbcfb72a0b2d57003d465a2e7d6a87f7337acd51da84d50370bdf1ccc8
5
5
  SHA512:
6
- metadata.gz: f11e994643bb475fcc61edd2cac76d8e93fbe34cf654e27652e16beb9222af284ae2923d9ae35c80c7c3d1c647bedfcb30ddd00a37f6c4c771b133df45e5f1c2
7
- data.tar.gz: eeb3ed744e29ec79eb081a8c323d90ce066fc754800f8afa894daf31397580454826a883fa74850def50df7885fa325765f9e89189e3acc1951bfa05bafc9cd5
6
+ metadata.gz: a0025a478e2c14db90355a0b644d1424af1c124c35a4bf0db76f8b0b3e3259aab0a3903c4336f69b3716d2eb30764e26c41acb36f4a395b5d023705927ec9a7d
7
+ data.tar.gz: 57e4df0e40891cbdea1e3afe151bebfc83a3eae70efb61a44808d1b914c82aa3f8de336ca76995c4e9db60614790b4e6d0653d2437fde674784d6951f9f303c9
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphd (0.4.0)
4
+ graphd (0.5.0)
5
+ grpc (~> 1.34.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc'
4
+ require_relative '../lib/graphd'
5
+
6
+ def client_stub
7
+ # if timeout is exceeded will throw `GRPC::DeadlineExceeded`
8
+ @client_stub ||= Graphd::ClientStub.new('localhost:9080', timeout: 1)
9
+ end
10
+
11
+ def client(client_stub)
12
+ @client ||= Graphd::Client.new(client_stub)
13
+ end
14
+
15
+ def run
16
+ dgraph_client = client(client_stub)
17
+ version = dgraph_client.check_version
18
+ p version
19
+ end
20
+
21
+ run
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.metadata['homepage_uri'] = spec.homepage
19
19
  spec.metadata['source_code_uri'] = 'https://github.com/thegeorgeous/graphd'
20
20
  spec.metadata['changelog_uri'] = 'https://github.com/thegeorgeous/graphd'
21
+ spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/graphd/'
21
22
 
22
23
  # Specify which files should be added to the gem when it is released.
23
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -10,6 +10,10 @@ module Graphd
10
10
  # client_stub = Graphd::ClientStub.new('localhost:9080')
11
11
  # client = Graphd::Cilent.new(client_stub)
12
12
  class Client
13
+ # Create a new instance of Graphd::Client
14
+ #
15
+ # @param clients [Array<Graphd::ClientStub>] The stubs that can be used
16
+ # to communicate with a DGraph server
13
17
  def initialize(*clients)
14
18
  raise ClientError unless clients
15
19
 
@@ -17,6 +21,9 @@ module Graphd
17
21
  @jwt = Api::Jwt.new
18
22
  end
19
23
 
24
+ # Get the version of the DGraph server
25
+ #
26
+ # @return [String] the version of the DGraph server
20
27
  def check_version
21
28
  request = Api::Check.new
22
29
  response = client.check_version(request)
@@ -27,6 +34,12 @@ module Graphd
27
34
  client.alter(operation)
28
35
  end
29
36
 
37
+ # Create a new transaction
38
+ #
39
+ # @param read_only [true, false] whether the transaction should be read only
40
+ # @param best_effort [true, false] Enable best-effort queries for the transaction
41
+ #
42
+ # @return [Transaction]
30
43
  def txn(read_only: false, best_effort: false)
31
44
  Transaction.new(self, read_only: read_only, best_effort: best_effort)
32
45
  end
@@ -5,29 +5,67 @@ require_relative 'api_services_pb'
5
5
 
6
6
  module Graphd
7
7
  # gRPC Client stub for DGraph
8
+ # This stub is a very thin wrapper over `GRPC::ClientStub`. It exists purely
9
+ # to provide sensible defaults relevant to DGraph like host and credentials
8
10
  class ClientStub
9
11
  attr_reader :stub
10
12
 
13
+ # Creates a new Graphd::ClientStub
14
+ #
15
+ # @param host [String] the host the stub connects to
16
+ # @param creds [GRPC::Core::ChannelCredentials|Symbol] the channel credentials, or
17
+ # :this_channel_is_insecure, which explicitly indicates that the client
18
+ # should be created with an insecure connection. Note: this argument is
19
+ # ignored if the channel_override argument is provided.
20
+ # @param channel_override [GRPC::Core::Channel] a pre-created channel
21
+ # @param timeout [Number] the default timeout in milliseconds to use in requests
22
+ # This will be used to set the deadline for every call made using this stub
23
+ # @param channel_args [Hash] the channel arguments. Note: this argument is
24
+ # ignored if the channel_override argument is provided.
11
25
  def initialize(
12
26
  host = 'localhost:9080',
13
27
  credentials = :this_channel_is_insecure,
14
- channel_args = {}
28
+ channel_override: nil,
29
+ timeout: nil,
30
+ channel_args: {}
15
31
  )
16
- @stub = Api::Dgraph::Stub.new(host, credentials, channel_args)
32
+ @stub = Api::Dgraph::Stub.new(
33
+ host,
34
+ credentials,
35
+ channel_override: channel_override,
36
+ timeout: timeout,
37
+ channel_args: channel_args
38
+ )
17
39
  end
18
40
 
41
+ # Request the version of the DGraph server running on host
42
+ #
43
+ # @param request [Api::Check]
44
+ # @return [Api::Version]
19
45
  def check_version(request)
20
46
  @stub.check_version(request)
21
47
  end
22
48
 
49
+ # Run operations that alter the DGraph db like set schema and drop_all
50
+ #
51
+ # @param operation [Api::Operation]
52
+ # @return [Api::Payload]
23
53
  def alter(operation)
24
54
  @stub.alter(operation)
25
55
  end
26
56
 
57
+ # Query the db
58
+ #
59
+ # @param request [Api::Request]
60
+ # @return [Api::Response]
27
61
  def query(request)
28
62
  @stub.query(request)
29
63
  end
30
64
 
65
+ # Commit a mutation or abort if it fails
66
+ #
67
+ # @param transaction_context [Api::TxnContext]
68
+ # @return [Api::TxnContext]
31
69
  def commit_or_abort(transaction_context:)
32
70
  @stub.commit_or_abort(transaction_context)
33
71
  end
@@ -1,9 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require_relative 'transaction_error'
4
5
 
5
6
  module Graphd
7
+ # A transaction to perform queries and mutations
8
+ #
9
+ # A transaction bounds a sequence of queries and mutations that are committed
10
+ # by Dgraph as a single unit: that is, on commit, either all the changes are
11
+ # accepted by Dgraph or none are.
6
12
  class Transaction
13
+ # Create a new transaction
14
+ #
15
+ # @param client [Graphd::Client] The client for which the transaction needs to be created
16
+ # @param read_only [true, false] whether the transaction should be read only
17
+ # Read-only transactions are ideal for transactions which only involve
18
+ # queries. Mutations and commits are not allowed.
19
+ # @param best_effort [true, false] Enable best-effort queries Best-effort
20
+ # queries are faster than normal queries because they bypass the normal
21
+ # consensus protocol. For this same reason, best-effort queries cannot
22
+ # guarantee to return the latest data. Best-effort queries are only
23
+ # supported by read-only transactions.
7
24
  def initialize(client, read_only: false, best_effort: false)
8
25
  if !read_only && best_effort
9
26
  raise TransactionError, 'Best effort transactions are only compatible with read-only transactions'
@@ -30,6 +47,17 @@ module Graphd
30
47
  do_request(request)
31
48
  end
32
49
 
50
+ # Create or modify an instance of Api::Mutation with the provided configuration
51
+ #
52
+ # @param mutation [Api::Mutation] (optional) A mutation to be modified
53
+ # @param set_obj [Hash] (optional) A Hash that represent a value to be set
54
+ # This value will be set the value of `set_json` of `Api::Mutation`
55
+ # @param del_obj [Hash] (optional) A Hash that represents a value to be deleted
56
+ # This value will be set the value of `delete_json` of `Api::Mutation`
57
+ # @param set_nquads [String] (optional) An N-Quad representing the value to be set for `Api::Mutation`
58
+ # @param del_nquads [String] (optional) An N-Quad representing the value to be deleted for `Api::Mutation`
59
+ #
60
+ # @return [Api::Mutation]
33
61
  def create_mutation(mutation: nil, set_obj: nil, del_obj: nil, set_nquads: nil, del_nquads: nil, cond: nil)
34
62
  mutation ||= ::Api::Mutation.new
35
63
 
@@ -42,6 +70,18 @@ module Graphd
42
70
  mutation
43
71
  end
44
72
 
73
+ # Create an instance of Api::Request
74
+ #
75
+ # @param query [String] (optional) A GraphQL query as a string
76
+ # @param query [Hash] (optional) A Hash of variables used in the provided query
77
+ # The keys can be symbols or strings but not numbers. The values must be
78
+ # strings
79
+ # @param mutations [Array<Api::Mutation>] A list of mutations
80
+ # @param commit_now [true, false] Indicate that the mutation must be
81
+ # immediately committed. This can be used when the mutation needs to be
82
+ # committed, without querying anything further.
83
+ #
84
+ # @return [Api::Request]
45
85
  def create_request(query: nil, variables: nil, mutations: nil, commit_now: nil)
46
86
  request = ::Api::Request.new(
47
87
  start_ts: @transaction_context.start_ts,
@@ -50,10 +90,12 @@ module Graphd
50
90
  best_effort: true
51
91
  )
52
92
  variables&.each do |key, value|
53
- unless key.is_a?(String) && value.is_a?(String)
54
- raise TransactionError, 'Values and keys in variable map must be strings'
93
+ unless key.is_a?(Symbol) || key.is_a?(String)
94
+ raise TransactionError, 'Keys in variable map must be symbols or strings'
55
95
  end
56
96
 
97
+ raise TransactionError, 'Values in variable map must be strings' unless value.is_a?(String)
98
+
57
99
  request.vars[key] = value
58
100
  end
59
101
 
@@ -1,4 +1,4 @@
1
- # lib/transaction_error.rb
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Graphd
4
4
  class TransactionError < StandardError
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Graphd
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Thomas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-27 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -33,6 +33,7 @@ executables:
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - ".github/dependabot.yml"
36
37
  - ".gitignore"
37
38
  - ".rspec"
38
39
  - ".rubocop.yml"
@@ -47,6 +48,7 @@ files:
47
48
  - bin/console
48
49
  - bin/setup
49
50
  - examples/simple_example.rb
51
+ - examples/timeout_example.rb
50
52
  - graphd.gemspec
51
53
  - lib/graphd.rb
52
54
  - lib/graphd/aborted_error.rb
@@ -67,6 +69,7 @@ metadata:
67
69
  homepage_uri: https://github.com/thegeorgeous/graphd
68
70
  source_code_uri: https://github.com/thegeorgeous/graphd
69
71
  changelog_uri: https://github.com/thegeorgeous/graphd
72
+ documentation_uri: https://rubydoc.info/gems/graphd/
70
73
  post_install_message:
71
74
  rdoc_options: []
72
75
  require_paths: