inigorb 0.27.5 → 0.27.6

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: 788d97815fbd001b6eebffed2c9f7c9ef5ea8eddb4228c060ce8dfc155b71aa0
4
+ data.tar.gz: b21a0572e9fabb0c6c55fe1a112c2e09f0fc5891e9a9353a05599e43a843a1ed
5
5
  SHA512:
6
- metadata.gz: 5635418c67f39131177f34e6831440004ab89a0ade0ec73a052c9c1c2d6cc7f396b3ddaf0a759495dee5df473debb8e35c751407b1d1b3ecc18b76313f7b2e71
7
- data.tar.gz: 506d88a0918b5117f9424a56baef74aaab1bb065447cab2bdc48b9710a4db2649d0ae7fae27dec2c12e5c4939022ce06fcf8451bdd2f7e8167f6240617121625
6
+ metadata.gz: 4120ce3939645d632e5f72e17bf5342e2e7c869368e64cb05f6d9fb411f6eaf73afb3088828c081db4a6d3ea15341403c25396d021303b8387a2fc49a1214669
7
+ data.tar.gz: 9a97a310ced373289fccb74631452212da345acb5e7d2ea1c45ec46b1e7f95ec016fccf7d0d15ec6994758416d1301ddc7eee0cbd111a63989a1e6582c4c7364
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.6
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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt