graphql_connector 1.2.1 → 1.3.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: b5e948edafea5975fe63377a5da8f4ca6d01d9876393a811da385b3d3f07fa88
4
- data.tar.gz: 8aa20c39ae60c975e8e17fb1b54e8715a39d2be4f536d1e6df053a93208096b3
3
+ metadata.gz: dec05781e16009638ffb57356c4b648730b6d04eb60129211cc1f462c6b1db77
4
+ data.tar.gz: fde0b8313c159ae15b43b3aa050c53c710902854080459e41d7da28595226c8d
5
5
  SHA512:
6
- metadata.gz: a3a49cf0f8be6bbb061d29e34a5224c76f287c84a9fc2a9af51ba3c4475a043cb0321870ecd59ee027be111335a961b9ec55f609a5721429cabfb5897af5d4ed
7
- data.tar.gz: f051786162a0f05136acc59d1682012c54c1d2d306f3e9284a8136b70be80410b101731c2c608d71d1f600101df0f0427917c0777c9ae725c1ebb8e1bee4bf80
6
+ metadata.gz: 4a30c45c22bc87d78bc34377c1bca7e40c78d72c96a8d1e840ee89aec119cacfc01b1a517c86c5ca2867573a160742382bd3bf9ce02f256e8e8f42313b36aa5b
7
+ data.tar.gz: 218116c1728b4da4583e709435df2f2e1ba3477edcae34ec0958f398e42ccad3fdee8b80d3de1cc3312c4d7cae9a97add6384273d2cc162a4a86031dd4c5f149
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.3.0 (2021-06-02)
2
+
3
+ * add the option to use a connector instead of init header for authorization
4
+ part of headers
5
+
1
6
  ## 1.2.1 (2021-05-25)
2
7
 
3
8
  * relax httparty dependency(`~> 0.17` => `~> 0.16`)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_connector (1.2.0)
4
+ graphql_connector (1.3.0)
5
5
  httparty (~> 0.16)
6
6
 
7
7
  GEM
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 = uri
46
- @headers = 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 ||= GraphqlConnector::HttpClient.new(@uri, @headers)
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] = BaseServerType.build(name, uri, headers)
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: @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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlConnector
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
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.2.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-05-25 00:00:00.000000000 Z
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.2.7
145
+ rubygems_version: 3.1.4
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: GraphQL client