simple_graphql_client 0.3.1 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/lib/simple_graphql_client/client.rb +2 -10
- data/lib/simple_graphql_client/errors/parser_error.rb +19 -0
- data/lib/simple_graphql_client/response.rb +27 -0
- data/lib/simple_graphql_client/version.rb +1 -1
- data/lib/simple_graphql_client.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75583dfdfc82b5761e828e02e92237823ee459b199322928afdc02fde54af20f
|
4
|
+
data.tar.gz: cfdf0151d93e72a84543aef7cdc9e505f427ac5b08e580d575bd1eee3b3ea583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39fe24ef9b5232d9b958b21afd80e7b1b630cfd6b37acc52773729df4bae629e93b2a2d998ece217341902069867bc3a59fba6c7947f80ac8c54d714ebbd604b
|
7
|
+
data.tar.gz: b777d759103d1a372731204a5dbf1081f969bbbb47206b74e821db88d9fc21491cff3b6fc47cc278bf53993bc3fa261949c908e1f3778535a2aba691f6e601e2
|
data/Changelog.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_graphql_client (0.
|
4
|
+
simple_graphql_client (0.4)
|
5
5
|
rest-client (~> 2.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -11,6 +11,7 @@ GEM
|
|
11
11
|
diff-lcs (1.4.4)
|
12
12
|
domain_name (0.5.20190701)
|
13
13
|
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
hashie (5.0.0)
|
14
15
|
http-accept (1.7.0)
|
15
16
|
http-cookie (1.0.4)
|
16
17
|
domain_name (~> 0.5)
|
@@ -65,6 +66,7 @@ PLATFORMS
|
|
65
66
|
x86_64-linux
|
66
67
|
|
67
68
|
DEPENDENCIES
|
69
|
+
hashie (~> 5.0)
|
68
70
|
rake (~> 13.0)
|
69
71
|
rspec (~> 3.0)
|
70
72
|
rubocop (~> 0.80)
|
@@ -7,9 +7,8 @@ module SimpleGraphqlClient
|
|
7
7
|
class Client
|
8
8
|
attr_reader :options
|
9
9
|
|
10
|
-
def initialize(url:,
|
10
|
+
def initialize(url:, &block)
|
11
11
|
@url = url
|
12
|
-
@options = options
|
13
12
|
@request_options = block
|
14
13
|
end
|
15
14
|
|
@@ -18,7 +17,7 @@ module SimpleGraphqlClient
|
|
18
17
|
query: gql,
|
19
18
|
variables: variables
|
20
19
|
}.to_json, request_options)
|
21
|
-
|
20
|
+
Response.new(response)
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
@@ -28,12 +27,5 @@ module SimpleGraphqlClient
|
|
28
27
|
options = @request_options ? @request_options.call : {}
|
29
28
|
base_options.merge(options)
|
30
29
|
end
|
31
|
-
|
32
|
-
def handle_response(body)
|
33
|
-
errors = body.is_a?(Hash) ? body["errors"] : body.errors
|
34
|
-
raise SimpleGraphqlClient::Errors::QueryError, errors if errors
|
35
|
-
|
36
|
-
body.is_a?(Hash) ? body["data"] : body.data
|
37
|
-
end
|
38
30
|
end
|
39
31
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleGraphqlClient
|
4
|
+
module Errors
|
5
|
+
class ParserError < StandardError
|
6
|
+
attr_reader :error, :response
|
7
|
+
|
8
|
+
def initialize(error, response)
|
9
|
+
@error = error
|
10
|
+
@response = response
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
"Failed to parse response #{response.body[0..10]}... from #{response.request.inspect}."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rest_client"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module SimpleGraphqlClient
|
7
|
+
class Response
|
8
|
+
attr_reader :raw_response
|
9
|
+
|
10
|
+
def initialize(raw_response)
|
11
|
+
@raw_response = raw_response
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
parsed_body = Hashie::Mash.new(JSON.parse(raw_response.body))
|
16
|
+
raise SimpleGraphqlClient::Errors::QueryError, parsed_body.errors if parsed_body.errors
|
17
|
+
|
18
|
+
parsed_body.data
|
19
|
+
rescue JSON::ParserError => e
|
20
|
+
raise SimpleGraphqlClient::Errors::ParserError.new(e, raw_response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def errors
|
24
|
+
response_body
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "hashie"
|
4
|
+
|
3
5
|
require_relative "simple_graphql_client/version"
|
6
|
+
require_relative "simple_graphql_client/response"
|
4
7
|
require_relative "simple_graphql_client/client"
|
5
8
|
require_relative "simple_graphql_client/errors/query_error"
|
9
|
+
require_relative "simple_graphql_client/errors/parser_error"
|
6
10
|
|
7
11
|
module SimpleGraphqlClient
|
8
12
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_graphql_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Verbinnen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -46,7 +46,9 @@ files:
|
|
46
46
|
- bin/setup
|
47
47
|
- lib/simple_graphql_client.rb
|
48
48
|
- lib/simple_graphql_client/client.rb
|
49
|
+
- lib/simple_graphql_client/errors/parser_error.rb
|
49
50
|
- lib/simple_graphql_client/errors/query_error.rb
|
51
|
+
- lib/simple_graphql_client/response.rb
|
50
52
|
- lib/simple_graphql_client/version.rb
|
51
53
|
- simple_graphql_client.gemspec
|
52
54
|
homepage: https://github.com/djpate/simple-graphql-client
|