graphql_connector 1.2.1 → 1.3.0
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 +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +14 -1
- data/lib/graphql_connector/base_server_type.rb +9 -7
- data/lib/graphql_connector/configuration.rb +3 -2
- data/lib/graphql_connector/http_client.rb +10 -2
- data/lib/graphql_connector/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec05781e16009638ffb57356c4b648730b6d04eb60129211cc1f462c6b1db77
|
4
|
+
data.tar.gz: fde0b8313c159ae15b43b3aa050c53c710902854080459e41d7da28595226c8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a30c45c22bc87d78bc34377c1bca7e40c78d72c96a8d1e840ee89aec119cacfc01b1a517c86c5ca2867573a160742382bd3bf9ce02f256e8e8f42313b36aa5b
|
7
|
+
data.tar.gz: 218116c1728b4da4583e709435df2f2e1ba3477edcae34ec0958f398e42ccad3fdee8b80d3de1cc3312c4d7cae9a97add6384273d2cc162a4a86031dd4c5f149
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -30,10 +30,23 @@ Or install it yourself as:
|
|
30
30
|
You need to configure the `graphql_connector` first:
|
31
31
|
``` ruby
|
32
32
|
GraphqlConnector.configure do |config|
|
33
|
-
config.add_server(name: 'Foo', uri: 'http://foo.com/api/graphql', headers: {})
|
33
|
+
config.add_server(name: 'Foo', uri: 'http://foo.com/api/graphql', headers: {}, connector: {})
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
37
|
+
The connector is expecting that it contains a `base` connector instance and a
|
38
|
+
`method` parameter as string, where it gets the token. Currently like this:
|
39
|
+
```ruby
|
40
|
+
{ base: TokenAgent.new, method: 'get_authorization_header' }
|
41
|
+
```
|
42
|
+
|
43
|
+
Your method should return a hash like this:
|
44
|
+
```ruby
|
45
|
+
{ 'Authorization' => 'Token HERE' }
|
46
|
+
|
47
|
+
When you set a connector, it will override the setting in the headers for
|
48
|
+
Authorization.
|
49
|
+
|
37
50
|
For each graphql server you wish to query use `add_server`.
|
38
51
|
|
39
52
|
Afterwards you will have the following options to fetch and/or mutate data with
|
@@ -5,9 +5,9 @@ module GraphqlConnector
|
|
5
5
|
# Class to wrap http_client calls under a specific namespaced class
|
6
6
|
class BaseServerType
|
7
7
|
class << self
|
8
|
-
def build(name, uri, headers)
|
8
|
+
def build(name, uri, headers, connector = {})
|
9
9
|
verify_new_client_type_for!(name)
|
10
|
-
base_class = class_with(uri, headers)
|
10
|
+
base_class = class_with(uri, headers, connector)
|
11
11
|
base_object = GraphqlConnector.const_set(name, base_class)
|
12
12
|
inject_http_client_delegations(base_object)
|
13
13
|
create_service_class_module(base_object)
|
@@ -39,11 +39,12 @@ module GraphqlConnector
|
|
39
39
|
METHOD
|
40
40
|
end
|
41
41
|
|
42
|
-
def class_with(uri, headers)
|
42
|
+
def class_with(uri, headers, connector = {})
|
43
43
|
Class.new do
|
44
|
-
attr_accessor :uri, :headers
|
45
|
-
@uri
|
46
|
-
@headers
|
44
|
+
attr_accessor :uri, :headers, :connector
|
45
|
+
@uri = uri
|
46
|
+
@headers = headers
|
47
|
+
@connector = connector
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -53,7 +54,8 @@ module GraphqlConnector
|
|
53
54
|
def_delegators :http_client, :query, :raw_query, :mutation
|
54
55
|
|
55
56
|
def http_client
|
56
|
-
@http_client ||=
|
57
|
+
@http_client ||=
|
58
|
+
GraphqlConnector::HttpClient.new(@uri, @headers, @connector)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -9,8 +9,9 @@ module GraphqlConnector
|
|
9
9
|
@base_server_types = {}
|
10
10
|
end
|
11
11
|
|
12
|
-
def add_server(name:, uri:, headers:)
|
13
|
-
@base_server_types[name] =
|
12
|
+
def add_server(name:, uri:, headers:, connector: {})
|
13
|
+
@base_server_types[name] =
|
14
|
+
BaseServerType.build(name, uri, headers, connector)
|
14
15
|
end
|
15
16
|
|
16
17
|
def reset!
|
@@ -3,9 +3,10 @@
|
|
3
3
|
module GraphqlConnector
|
4
4
|
# Wrapper class for HTTParty post query
|
5
5
|
class HttpClient
|
6
|
-
def initialize(uri, headers)
|
6
|
+
def initialize(uri, headers, connector = {})
|
7
7
|
@uri = uri
|
8
8
|
@headers = headers
|
9
|
+
@connector = connector
|
9
10
|
end
|
10
11
|
|
11
12
|
def query(model, conditions, selected_fields)
|
@@ -24,7 +25,7 @@ module GraphqlConnector
|
|
24
25
|
|
25
26
|
def raw_query(query_string, variables: {})
|
26
27
|
response = HTTParty.post(@uri,
|
27
|
-
headers:
|
28
|
+
headers: handle_headers,
|
28
29
|
body: { query: query_string,
|
29
30
|
variables: variables })
|
30
31
|
parsed_body = JSON.parse(response.body)
|
@@ -34,6 +35,13 @@ module GraphqlConnector
|
|
34
35
|
|
35
36
|
private
|
36
37
|
|
38
|
+
def handle_headers
|
39
|
+
return @headers if @connector.empty?
|
40
|
+
|
41
|
+
@headers
|
42
|
+
.merge(@connector[:base].send(@connector[:method]))
|
43
|
+
end
|
44
|
+
|
37
45
|
def format_body(response_body)
|
38
46
|
return OpenStruct.new(response_body) unless response_body.is_a? Array
|
39
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garllon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.1.4
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: GraphQL client
|