inigorb 0.27.5 → 0.27.7

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: 26c3e3abbc50481d5f7cc16aaebebf3021057277cadc8338bbc2497dff00574e
4
- data.tar.gz: 30523a5fd3ba87a2201aa1e30fdedb3c72c000b9c9f8aa56e4ed88c51a14df69
3
+ metadata.gz: c6958605469a47112e9986e2750fb21cd0828ce2f57bb826e221f96bb52549cd
4
+ data.tar.gz: 42387b988b13ca15e30f99d64aee75a19eda115fd25392a4a13ec93249c388a1
5
5
  SHA512:
6
- metadata.gz: 5635418c67f39131177f34e6831440004ab89a0ade0ec73a052c9c1c2d6cc7f396b3ddaf0a759495dee5df473debb8e35c751407b1d1b3ecc18b76313f7b2e71
7
- data.tar.gz: 506d88a0918b5117f9424a56baef74aaab1bb065447cab2bdc48b9710a4db2649d0ae7fae27dec2c12e5c4939022ce06fcf8451bdd2f7e8167f6240617121625
6
+ metadata.gz: 0d7cad1a8f9dd997d4c834d6c9d953c5e1e4c0f50d3ad9c4244740be7760e3d443badaaaa8294e32acd1b33cd53fa086af642ca99839f98ef4007254338cf7e6
7
+ data.tar.gz: a09eebe058d895f2b0aee923ba708a1ca26a8fa0497a1eb9e6abcb7cd730ff808c0b944de6500b3be32c7093711e7f3da628f76e2807bc3c145a3abc852ddb35
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/inigorb.rb CHANGED
@@ -63,13 +63,15 @@ module Inigo
63
63
 
64
64
  request = Rack::Request.new(env)
65
65
 
66
- # 'path' guard -> /graphql
67
- if request.path != self.class.path
66
+ path = self.class.path
67
+ path += "/" unless path.end_with?("/")
68
+ # 'path' guard -> /graphql, /graphql/whatever
69
+ if request.path != self.class.path && !request.path.start_with?(path)
68
70
  return @app.call(env)
69
71
  end
70
72
 
71
73
  # GraphiQL request
72
- if request.get? && request.accept.include?('text/html')
74
+ if request.get? && env['HTTP_ACCEPT'].include?('text/html')
73
75
  return @app.call(env)
74
76
  end
75
77
 
@@ -84,9 +86,16 @@ module Inigo
84
86
  # Read request from body
85
87
  request.body.each { |chunk| gReq += chunk }
86
88
 
87
- if self.class.operation_store.present? && gReq.include?("operationId")
89
+ if self.class.operation_store.present? && has_operation_id?(gReq)
88
90
  parsed = JSON.parse(gReq)
89
- parts = parsed['operationId'].split('/')
91
+ operationId = get_operation_id(parsed)
92
+
93
+ if !operationId
94
+ request.body.rewind
95
+ return @app.call(env)
96
+ end
97
+
98
+ parts = operationId.split('/')
90
99
  # Query can't be resolved
91
100
  if parts.length != 2
92
101
  request.body.rewind
@@ -114,24 +123,9 @@ module Inigo
114
123
  end
115
124
  request.body.rewind
116
125
  elsif request.get?
117
- req = {}
118
-
119
- if request.params['query']
120
- req.merge!('query' => request.params['query'])
121
- end
122
-
123
- if request.params['operationName']
124
- req.merge!('operationName' => request.params['operationName'])
125
- end
126
-
127
- if request.params['variables']
128
- req.merge!('variables' => request.params['variables'])
129
- end
130
-
131
- if request.params['operationId']
132
- req.merge!('operationId' => request.params['operationId'])
133
- if self.class.operation_store
134
- parts = request.params['operationId'].split('/')
126
+ operation_id = get_operation_id(request.params)
127
+ if operation_id && self.class.operation_store
128
+ parts = operation_id.split('/')
135
129
  # Query can't be resolved
136
130
  if parts.length != 2
137
131
  return @app.call(env)
@@ -143,17 +137,19 @@ module Inigo
143
137
  end
144
138
 
145
139
  if data.name
146
- req.merge!('operationName' => data.name)
140
+ request.params['operationName'] = data.name
147
141
  end
148
142
 
149
143
  if data.body
150
- req.merge!('query' => data.body)
144
+ request.params['query'] = data.body
151
145
  end
152
- end
146
+
147
+ # Update the env with the modified query string
148
+ env['QUERY_STRING'] = Rack::Utils.build_nested_query(request.params)
153
149
  end
154
150
 
155
151
  # Read request from query param
156
- gReq = JSON.dump(req)
152
+ gReq = JSON.dump(request.params)
157
153
  end
158
154
 
159
155
  q = Query.new(self.class.instance, gReq)
@@ -280,5 +276,24 @@ module Inigo
280
276
  [status, headers, [JSON.dump(response_hash)]]
281
277
  end
282
278
 
279
+ # operates with string data not to parse the request body unnecessary
280
+ def has_operation_id?(str_data)
281
+ # Relay / Apollo 1.x and Apollo Link have the same field just in different places.
282
+ str_data.include?('operationId')
283
+ end
284
+
285
+ # extracts operation id from parsed body hash
286
+ def get_operation_id(json_data)
287
+ # Relay / Apollo 1.x
288
+ if json_data.include?('operationId')
289
+ json_data['operationId']
290
+ # Apollo Link
291
+ elsif json_data.include?('extensions') && json_data['extensions'].include?('operationId')
292
+ json_data['extensions']['operationId']
293
+ else
294
+ nil
295
+ end
296
+ end
297
+
283
298
  end
284
299
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inigorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.5
4
+ version: 0.27.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inigo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-10 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt