graphql_connector 1.3.1 → 1.4.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: 4b8c2af2590f1daf462e0f348e64078c530a4c7f6833a7d8692e6bada0f11291
4
- data.tar.gz: 52edb3725223b2538f91b1904fa57a071ab0b43b853f37f23242e1dbb8d7eb50
3
+ metadata.gz: 99e1add1eb99f9dd85020d90caf9b0cc73e9c8aca660fb8e56f425aa059254f3
4
+ data.tar.gz: 7300a5b796cfd0f0ecba9d5af17d365504e722b759bd97bb2914c2623dfdaa32
5
5
  SHA512:
6
- metadata.gz: c82b787552cf4590bae68e4eb15103252a47660ba4a8b2d7645deb9e218034cadbca24feaf9ef610818106e322fc7916a91fdd3726d251e49c0051224666d3c2
7
- data.tar.gz: 491988a32bc66f1d597d32dbf0164b5f5a23a87923ac6d4da3c0fbc8272de1b6721ba8657b35e99ad221a9bcb2860431964e22281fcba341da36f3f5dd49ba1e
6
+ metadata.gz: 9a46cbb39e8f3ccc7a79dbf47bd1437e1bc775f6a4b592dc1b52dec21a9ebca72e1ebb4a78c781ce2ed69ef35702f725480b20ba22765da9aea4a965a9f99700
7
+ data.tar.gz: 4ae66cde11f69d1f4c8c4bab379a8251516f4b63562c427246b62044c2a26bc9e31be6bb13fd41435879c4693260f4b653b25b98f78dc88f5e2c52fc7a69ccd1
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: ['2.4.10', '2.5.9', '2.6.7', '2.7.3', '3.0.1']
10
+ ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
11
11
  name: "ruby ${{ matrix.ruby }}"
12
12
  steps:
13
13
  - uses: actions/checkout@v1
data/.rubocop.yml CHANGED
@@ -1,2 +1,4 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ Layout/LineLength:
4
+ Max: 100
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.4.0 (2022-03-17)
2
+
3
+ * Add config for `httparty_adapter_options` allowing forwarding options to `httparty`
4
+
1
5
  ## 1.3.1 (2021-06-04)
2
6
 
3
7
  * add more specs to test headers and connectors
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_connector (1.3.0)
4
+ graphql_connector (1.4.0)
5
5
  httparty (~> 0.16)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.0)
11
11
  coderay (1.1.2)
12
- diff-lcs (1.3)
12
+ diff-lcs (1.5.0)
13
13
  httparty (0.18.1)
14
14
  mime-types (~> 3.0)
15
15
  multi_xml (>= 0.5.2)
@@ -27,19 +27,19 @@ GEM
27
27
  method_source (~> 1.0)
28
28
  rainbow (3.0.0)
29
29
  rexml (3.2.5)
30
- rspec (3.9.0)
31
- rspec-core (~> 3.9.0)
32
- rspec-expectations (~> 3.9.0)
33
- rspec-mocks (~> 3.9.0)
34
- rspec-core (3.9.1)
35
- rspec-support (~> 3.9.1)
36
- rspec-expectations (3.9.1)
30
+ rspec (3.11.0)
31
+ rspec-core (~> 3.11.0)
32
+ rspec-expectations (~> 3.11.0)
33
+ rspec-mocks (~> 3.11.0)
34
+ rspec-core (3.11.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-expectations (3.11.0)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.9.0)
39
- rspec-mocks (3.9.1)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-mocks (3.11.0)
40
40
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.9.0)
42
- rspec-support (3.9.2)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-support (3.11.0)
43
43
  rubocop (0.82.0)
44
44
  jaro_winkler (~> 1.5.1)
45
45
  parallel (~> 1.10)
@@ -62,4 +62,4 @@ DEPENDENCIES
62
62
  rubocop (~> 0.75)
63
63
 
64
64
  BUNDLED WITH
65
- 2.1.4
65
+ 2.3.9
data/README.md CHANGED
@@ -30,20 +30,21 @@ 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: {}, connector: {})
33
+ config.add_server(name: 'Foo', uri: 'http://foo.com/api/graphql', headers: {}, connector: {}, httparty_adapter_options: {})
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. WE expect that the
39
- method is a public method in your connector class. Currently like this:
37
+ * `name` (**mandatory**): Add a namespace under which the API is reachable. In the above example `'Foo'` means that `GraphqlConnector::Foo` provides API functionality for the configured `add_server`
38
+
39
+ * `uri` (**mandatory**): Add uri of grapqhl API server that accepts **POST** requests.
40
+
41
+ * `connector` (**optionally**): Add a **Authentication Token class** in the following format:
40
42
  ```ruby
41
- { base: TokenAgent.new, method: 'get_authorization_header' }
43
+ connector: { base: AuthTokenAgent.instance, method: 'get_authorization_header' }
42
44
  ```
43
-
44
- Your method should return a hash like this:
45
+ `base` is an instance of Authentication Token class and `method` represents the function where it gets the token.
45
46
  ```ruby
46
- class TokenAgent
47
+ class AuthTokenAgent
47
48
  [...]
48
49
  def get_authorization_header
49
50
  [...]
@@ -51,9 +52,12 @@ class TokenAgent
51
52
  end
52
53
  end
53
54
  ```
55
+ :warning: The function under `method` must be a public one in your connector class.<br />
56
+ :warning: When you set a connector, it will override the setting in the headers for Authorization.
57
+
58
+
59
+ * `httparty_adapter_options` (**optionally**): Add any [`connection_adapter`](https://github.com/jnunemaker/httparty/blob/master/lib/httparty/connection_adapter.rb) options that `httparty` supports in a hash format e.g. `{ timeout: 4 }`
54
60
 
55
- When you set a connector, it will override the setting in the headers for
56
- Authorization.
57
61
 
58
62
  For each graphql server you wish to query use `add_server`.
59
63
 
@@ -71,9 +75,23 @@ See the following sub sections for details
71
75
 
72
76
  You can call your graphql_endpoint via:
73
77
  ```ruby
74
- GraphqlConnector::<name>.raw_query(query_string)
78
+ GraphqlConnector::<name>.raw_query('query { products { id name } }')
79
+
80
+ GraphqlConnector::<name>.raw_query('query { products($id: [ID!]) { products(id: $id) { id name } } }', variables: { id: 1 })
81
+
82
+ GraphqlConnector::<name>.raw_query('mutation { createProduct(name: "Coca-Cola") { id name } }')
83
+ ```
84
+
85
+ Or if you want to **override**/**set** any `httparty_adapter_options` it is also possible to pass them in:
86
+ ```ruby
87
+ GraphqlConnector::<name>.raw_query('query { products { id name } }', httparty_adapter_options: { timeout: 3, verify: true })
88
+
89
+ GraphqlConnector::<name>.raw_query('query { products($id: [ID!]) { products(id: $id) { id name } } }', variables: { id: 1 }, httparty_adapter_options: { timeout: 3, verify: true })
90
+
91
+ GraphqlConnector::<name>.raw_query('mutation { createProduct(name: "Coca-Cola") { id name } }', httparty_adapter_options: { timeout: 3, verify: true })
75
92
  ```
76
93
 
94
+
77
95
  Note that `<name>` has to be replaced by any of the ones added via `add_server`
78
96
 
79
97
  See also [here](examples/raw_query_examples.rb) for example usage
@@ -83,16 +101,24 @@ See also [here](examples/raw_query_examples.rb) for example usage
83
101
 
84
102
  You can also use the more comfortable `query`:
85
103
  ```ruby
86
- GraphqlConnector::<name>.query(model, condition, selected_fields)
104
+ GraphqlConnector::<name>.query('products', { id: [1,2] } , ['id','name'])
105
+ ```
106
+
107
+ Or if you want to **override**/**set** any `httparty` adapter_options, it is also possible
108
+ to pass them in:
109
+
110
+ ```ruby
111
+ GraphqlConnector::<name>.query('products', { id: [1,2] } , ['id','name'], httparty_adapter_options: { timeout: 3 })
87
112
  ```
88
113
 
89
- | Variable | DataType | Example |
90
- |----------------|-------------------------|------------------------------------------|
91
- | model | String | 'product' |
92
- | condition | Hash(key, value) | { id: 1 } |
93
- | selected_fields | Array of Strings/Hashes | ['id', 'name', productCategory: ['id']] |
114
+ | Variable | Required | DataType | Example |
115
+ |--------------------------|-------------------------------|-------------------------|-----------------------------------------|
116
+ | model | Yes | String | 'product' |
117
+ | condition | Yes (but can be empty) | Hash(key, value) | { id: 1 } |
118
+ | selected_fields | Yes | Array of Strings/Hashes | ['id', 'name', productCategory: ['id']] |
119
+ | httparty_adapter_options | No | Hash | { timeout: 3 } |
94
120
 
95
- > Caution:
121
+ :warning:
96
122
  > You get an OpenStruct back. Currently only the first level attributes are
97
123
  > supported with OpenStruct, associated objects are still a normal array of
98
124
  > hashes.
@@ -129,14 +155,25 @@ so that it has re-usable graphql `query` and `mutation` **class methods**.
129
155
  * Then you can aliases as many graphql server types via `add_query` and/or `add_raw_query` and/or `add_mutation`:
130
156
 
131
157
  ```ruby
132
- add_query <alias>: :<graphql_server_type>, params: [...], returns: [...]
158
+ add_query products_by: :products, params: [:id], returns: [:id, :name]
133
159
 
134
- add_raw_query <alias>: 'query { ... }', params: [...]
160
+ add_raw_query products_raw_by: 'query { products(($id: [ID!]) products { id name } }', params: [:id]
135
161
 
136
- add_mutation <alias>: :<graphql_server_type>, params: [...], returns: [...]
162
+ add_mutation create: :createProduct, params: [:name], returns: [:id, :name]
137
163
  ```
138
164
  * :grey_exclamation: If not needed omit `params`
139
165
 
166
+ Or if you want to **override**/**set** any `httparty` adapter_options, it is also possible
167
+ to pass them in:
168
+
169
+ ```ruby
170
+ add_query products_by: :products, params: [:id], returns: [:id, :name], httparty_adapter_options: { timeout: 3 }
171
+
172
+ add_raw_query products_raw_by: 'query { products(($id: [ID!]) products { id name } }', params: [:id], httparty_adapter_options: { verify: true }
173
+
174
+ add_mutation create: :createProduct, params: [:name], returns: [:id, :name], httparty_adapter_options: { timeout: 5, verify: false }
175
+ ```
176
+
140
177
  See also [here](examples/departments_service_class_examples.rb) and also here for complete example usage:
141
178
 
142
179
  ```ruby
@@ -153,7 +190,8 @@ class Product
153
190
 
154
191
  add_query by_id: :products,
155
192
  params: :id,
156
- returns: [:name, product_category: [:id, :name]]
193
+ returns: [:name, product_category: [:id, :name]],
194
+ httparty_adapter_options: { timeout: 3 }
157
195
 
158
196
  add_query by_names: :products,
159
197
  params: :names,
@@ -169,7 +207,8 @@ class Product
169
207
 
170
208
  add_mutation create: :createProduct,
171
209
  params: [:name, :catgetoryId],
172
- returns: [:id, :name]
210
+ returns: [:id, :name],
211
+ httparty_adapter_options: { verify: false }
173
212
  end
174
213
 
175
214
  Product.all
@@ -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 = {}, connector = {})
8
+ def build(name, uri, headers = {}, connector = {}, httparty_adapter_options = {})
9
9
  verify_new_client_type_for!(name)
10
- base_class = class_with(uri, headers, connector)
10
+ base_class = class_with(uri, headers, connector, httparty_adapter_options)
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,12 +39,13 @@ module GraphqlConnector
39
39
  METHOD
40
40
  end
41
41
 
42
- def class_with(uri, headers = {}, connector = {})
42
+ def class_with(uri, headers = {}, connector = {}, httparty_adapter_options = {})
43
43
  Class.new do
44
- attr_accessor :uri, :headers, :connector
44
+ attr_accessor :uri, :headers, :connector, :httparty_adapter_options
45
45
  @uri = uri
46
46
  @headers = headers
47
47
  @connector = connector
48
+ @httparty_adapter_options = httparty_adapter_options
48
49
  end
49
50
  end
50
51
 
@@ -54,8 +55,10 @@ module GraphqlConnector
54
55
  def_delegators :http_client, :query, :raw_query, :mutation
55
56
 
56
57
  def http_client
57
- @http_client ||=
58
- GraphqlConnector::HttpClient.new(@uri, @headers, @connector)
58
+ @http_client ||= GraphqlConnector::HttpClient.new(@uri,
59
+ @headers,
60
+ @connector,
61
+ @httparty_adapter_options)
59
62
  end
60
63
  end
61
64
  end
@@ -9,9 +9,9 @@ module GraphqlConnector
9
9
  @base_server_types = {}
10
10
  end
11
11
 
12
- def add_server(name:, uri:, headers: {}, connector: {})
12
+ def add_server(name:, uri:, headers: {}, connector: {}, httparty_adapter_options: {})
13
13
  @base_server_types[name] =
14
- BaseServerType.build(name, uri, headers, connector)
14
+ BaseServerType.build(name, uri, headers, connector, httparty_adapter_options)
15
15
  end
16
16
 
17
17
  def reset!
@@ -3,31 +3,29 @@
3
3
  module GraphqlConnector
4
4
  # Wrapper class for HTTParty post query
5
5
  class HttpClient
6
- def initialize(uri, headers = {}, connector = {})
6
+ def initialize(uri, headers = {}, connector = {}, httparty_adapter_options = {})
7
7
  @uri = uri
8
8
  @headers = headers
9
9
  @connector = connector
10
+ @httparty_adapter_options = httparty_adapter_options
10
11
  end
11
12
 
12
- def query(model, conditions, selected_fields)
13
- query_string =
14
- Formatters::QueryFormat.new(model, conditions, selected_fields).create
15
- parsed_body = raw_query(query_string)
16
- format_body(parsed_body['data'][model.to_s])
13
+ def query(model, conditions, selected_fields, httparty_adapter_options: {})
14
+ query_string = Formatters::QueryFormat.new(model, conditions, selected_fields).create
15
+ format_body(query_string, model, httparty_adapter_options)
17
16
  end
18
17
 
19
- def mutation(model, inputs, selected_fields)
20
- query_string =
21
- Formatters::MutationFormat.new(model, inputs, selected_fields).create
22
- parsed_body = raw_query(query_string)
23
- format_body(parsed_body['data'][model.to_s])
18
+ def mutation(model, inputs, selected_fields, httparty_adapter_options: {})
19
+ query_string = Formatters::MutationFormat.new(model, inputs, selected_fields).create
20
+ format_body(query_string, model, httparty_adapter_options)
24
21
  end
25
22
 
26
- def raw_query(query_string, variables: {})
23
+ def raw_query(query_string, variables: {}, httparty_adapter_options: {})
24
+ adapter_options = combined_adapter_options(httparty_adapter_options)
27
25
  response = HTTParty.post(@uri,
28
26
  headers: handle_headers,
29
- body: { query: query_string,
30
- variables: variables })
27
+ body: { query: query_string, variables: variables },
28
+ **adapter_options)
31
29
  parsed_body = JSON.parse(response.body)
32
30
  verify_response!(parsed_body)
33
31
  parsed_body
@@ -35,6 +33,10 @@ module GraphqlConnector
35
33
 
36
34
  private
37
35
 
36
+ def combined_adapter_options(options)
37
+ @httparty_adapter_options.merge(options)
38
+ end
39
+
38
40
  def handle_headers
39
41
  return @headers if @connector.empty?
40
42
 
@@ -42,7 +44,9 @@ module GraphqlConnector
42
44
  .merge(@connector[:base].public_send(@connector[:method]))
43
45
  end
44
46
 
45
- def format_body(response_body)
47
+ def format_body(query_string, model, httparty_adapter_options)
48
+ parsed_body = raw_query(query_string, httparty_adapter_options: httparty_adapter_options)
49
+ response_body = parsed_body['data'][model.to_s]
46
50
  return OpenStruct.new(response_body) unless response_body.is_a? Array
47
51
 
48
52
  response_body.map { |entry| OpenStruct.new(entry) }
@@ -5,101 +5,83 @@ module GraphqlConnector
5
5
  # Module that allows to build query methods within the context of
6
6
  # service class
7
7
  module Queryable
8
- CONDITIONS = 'binding.local_variables.map do |var|
9
- [var, binding.local_variable_get(var)]
10
- end.to_h'
8
+ BINDINGS = 'binding.local_variables.map do |var|
9
+ [var, binding.local_variable_get(var)]
10
+ end.to_h'
11
11
 
12
- def add_query(params: [], returns:, **method_to_query)
13
- class_method_name = method_to_query.first[0]
14
- query_type = method_to_query.first[1]
15
- ReturnFieldsValidator.validate(returns)
16
- ClassMethodValidator.validate_class_method(class_method_name, self)
17
- ClassMethodValidator.validate_element_class_type(query_type, Symbol)
12
+ def add_query(params: [], httparty_adapter_options: {}, returns:, **method_to_query)
13
+ class_method_name, query_type = parse_variables(method_to_query)
18
14
 
19
- if params.empty?
20
- return query_method(class_method_name, query_type, returns)
21
- end
15
+ ensure_params_format!(returns, class_method_name, query_type)
16
+ ParamsValidator.validate(params) unless params.empty?
22
17
 
23
- ParamsValidator.validate(params)
24
- query_keyword_method(class_method_name, query_type, params, returns)
18
+ signature = method_signature(class_method_name, params)
19
+ signature[:graphql_method_type] = :query
20
+ create_method(signature, query_type, returns, httparty_adapter_options)
25
21
  end
26
22
 
27
- def add_raw_query(params: [], **method_to_raw_query)
28
- class_method_name = method_to_raw_query.first[0]
29
- query_string = method_to_raw_query.first[1]
23
+ def add_raw_query(params: [], httparty_adapter_options: {}, **method_to_raw_query)
24
+ class_method_name, query_string = parse_variables(method_to_raw_query)
25
+
30
26
  ClassMethodValidator.validate_class_method(class_method_name, self)
31
27
  ClassMethodValidator.validate_element_class_type(query_string, String)
28
+ ParamsValidator.validate(params) unless params.empty?
32
29
 
33
- if params.empty?
34
- return raw_query_method(class_method_name, query_string)
35
- end
36
-
37
- ParamsValidator.validate(params)
38
- raw_query_keyword_method(class_method_name, query_string, params)
30
+ signature = method_signature(class_method_name, params)
31
+ raw_query_method(signature, query_string, httparty_adapter_options)
39
32
  end
40
33
 
41
- def add_mutation(params: [], returns:, **method_to_query)
42
- class_method_name = method_to_query.first[0]
43
- query_type = method_to_query.first[1]
44
- ReturnFieldsValidator.validate(returns)
45
- ClassMethodValidator.validate_class_method(class_method_name, self)
46
- ClassMethodValidator.validate_element_class_type(query_type, Symbol)
34
+ def add_mutation(params: [], httparty_adapter_options: {}, returns:, **method_to_query)
35
+ class_method_name, query_type = parse_variables(method_to_query)
47
36
 
48
- if params.empty?
49
- return mutation_method(class_method_name, query_type, returns)
50
- end
37
+ ensure_params_format!(returns, class_method_name, query_type)
38
+ ParamsValidator.validate(params) unless params.empty?
51
39
 
52
- ParamsValidator.validate(params)
53
- mutation_keyword_method(class_method_name, query_type, params, returns)
40
+ signature = method_signature(class_method_name, params)
41
+ signature[:graphql_method_type] = :mutation
42
+ create_method(signature, query_type, returns, httparty_adapter_options)
54
43
  end
55
44
 
56
45
  private
57
46
 
58
- def query_method(class_method_name, query_type, return_fields)
59
- define_singleton_method class_method_name do
60
- http_client.query(query_type, {}, return_fields.to_a)
61
- end
47
+ def parse_variables(method_to_query)
48
+ class_method_name = method_to_query.first[0]
49
+ query_type = method_to_query.first[1]
50
+ [class_method_name, query_type]
62
51
  end
63
52
 
64
- def raw_query_method(class_method_name, query_string)
65
- define_singleton_method class_method_name do
66
- http_client.raw_query(query_string)
67
- end
68
- end
53
+ def method_signature(name, keywords)
54
+ return { head: name, bindings: {} } if keywords.empty?
69
55
 
70
- def query_keyword_method(name, query_type, keywords, return_fields)
71
56
  keywords = [keywords].flatten
72
- instance_eval <<-METHOD, __FILE__, __LINE__ + 1
73
- def #{name}(#{keywords.map { |keyword| "#{keyword}:" }.join(', ')})
74
- http_client.query("#{query_type}",
75
- #{CONDITIONS},
76
- #{return_fields.to_a})
77
- end
78
- METHOD
57
+ { head: "#{name}(#{keywords.map { |keyword| "#{keyword}:" }.join(', ')})",
58
+ bindings: BINDINGS }
79
59
  end
80
60
 
81
- def raw_query_keyword_method(name, query_string, keywords)
82
- keywords = [keywords].flatten
61
+ def ensure_params_format!(returns, class_method_name, query_type)
62
+ ReturnFieldsValidator.validate(returns)
63
+ ClassMethodValidator.validate_class_method(class_method_name, self)
64
+ ClassMethodValidator.validate_element_class_type(query_type, Symbol)
65
+ end
66
+
67
+ def raw_query_method(signature, query_string, httparty_adapter_options)
83
68
  instance_eval <<-METHOD, __FILE__, __LINE__ + 1
84
- def #{name}(#{keywords.map { |keyword| "#{keyword}:" }.join(', ')})
85
- http_client.raw_query("#{query_string}", variables: #{CONDITIONS})
69
+ def #{signature[:head]}
70
+ http_client.raw_query("#{query_string}",
71
+ variables: #{signature[:bindings]},
72
+ httparty_adapter_options: #{httparty_adapter_options})
86
73
  end
87
74
  METHOD
88
75
  end
89
76
 
90
- def mutation_method(class_method_name, query_type, return_fields)
91
- define_singleton_method class_method_name do
92
- http_client.mutation(query_type, {}, return_fields.to_a)
93
- end
94
- end
95
-
96
- def mutation_keyword_method(name, query_type, keywords, return_fields)
97
- keywords = [keywords].flatten
77
+ def create_method(signature, query_type, return_fields, httparty_adapter_options)
98
78
  instance_eval <<-METHOD, __FILE__, __LINE__ + 1
99
- def #{name}(#{keywords.map { |keyword| "#{keyword}:" }.join(', ')})
100
- http_client.mutation("#{query_type}",
101
- #{CONDITIONS},
102
- #{return_fields.to_a})
79
+ def #{signature[:head]}
80
+ http_client.#{signature[:graphql_method_type]}(
81
+ "#{query_type}",
82
+ #{signature[:bindings]},
83
+ #{return_fields.to_a},
84
+ httparty_adapter_options: #{httparty_adapter_options})
103
85
  end
104
86
  METHOD
105
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlConnector
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.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.3.1
4
+ version: 1.4.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-06-04 00:00:00.000000000 Z
12
+ date: 2022-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -90,6 +90,8 @@ executables: []
90
90
  extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
94
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
93
95
  - ".github/workflows/ci.yaml"
94
96
  - ".gitignore"
95
97
  - ".rspec"