inigorb 0.27.4 → 0.27.5

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: 61225748fde7b180e704d9e45ee2f831eaad0374a2b2164e614f921a48aef653
4
- data.tar.gz: 4d077ed1e60e36916bb104d6c7a0b3e7a6a5134ff39ac0ce52209cdefcd694bc
3
+ metadata.gz: 26c3e3abbc50481d5f7cc16aaebebf3021057277cadc8338bbc2497dff00574e
4
+ data.tar.gz: 30523a5fd3ba87a2201aa1e30fdedb3c72c000b9c9f8aa56e4ed88c51a14df69
5
5
  SHA512:
6
- metadata.gz: ee3e3bd4854fb47afb922b985b6ec77638a14dd778618d503d74b846e24f63b6d5c7aeeda123e03ca5ed8148d42ed556d847f28a988da0d80fa80f46665acc38
7
- data.tar.gz: e71610eb47bbc0416792de36948cf8a9e27b999f4d65695951a3c5f9ff7717f39c8c5646557f753b1ef375dde48f9f8f2ca42624c6fae381259c4f49b1ea6a9b
6
+ metadata.gz: 5635418c67f39131177f34e6831440004ab89a0ade0ec73a052c9c1c2d6cc7f396b3ddaf0a759495dee5df473debb8e35c751407b1d1b3ecc18b76313f7b2e71
7
+ data.tar.gz: 506d88a0918b5117f9424a56baef74aaab1bb065447cab2bdc48b9710a4db2649d0ae7fae27dec2c12e5c4939022ce06fcf8451bdd2f7e8167f6240617121625
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/inigorb.rb CHANGED
@@ -9,6 +9,7 @@ module Inigo
9
9
  @@initialized = false
10
10
  @@path = ''
11
11
  @@schema = ''
12
+ @@operation_store = nil
12
13
 
13
14
  def self.instance
14
15
  @@instance
@@ -42,6 +43,14 @@ module Inigo
42
43
  @@schema = value
43
44
  end
44
45
 
46
+ def self.operation_store
47
+ @@operation_store
48
+ end
49
+
50
+ def self.operation_store=(value)
51
+ @@operation_store = value
52
+ end
53
+
45
54
  def initialize(app)
46
55
  @app = app
47
56
  end
@@ -74,10 +83,77 @@ module Inigo
74
83
  if request.post?
75
84
  # Read request from body
76
85
  request.body.each { |chunk| gReq += chunk }
86
+
87
+ if self.class.operation_store.present? && gReq.include?("operationId")
88
+ parsed = JSON.parse(gReq)
89
+ parts = parsed['operationId'].split('/')
90
+ # Query can't be resolved
91
+ if parts.length != 2
92
+ request.body.rewind
93
+ return @app.call(env)
94
+ end
95
+ data = self.class.operation_store.get(client_name: parts[0], operation_alias: parts[1])
96
+ # Query can't be resolved
97
+ if !data
98
+ request.body.rewind
99
+ return @app.call(env)
100
+ end
101
+ if data.name
102
+ parsed.merge!('operationName' => data.name)
103
+ end
104
+
105
+ if data.body
106
+ parsed.merge!('query' => data.body)
107
+ end
108
+
109
+ gReq = ''
110
+ gReq = JSON.dump(parsed)
111
+ env['rack.input'] = StringIO.new(gReq)
112
+ env['CONTENT_LENGTH'] = gReq.length.to_s
113
+ env['CONTENT_TYPE'] = 'application/json'
114
+ end
77
115
  request.body.rewind
78
116
  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('/')
135
+ # Query can't be resolved
136
+ if parts.length != 2
137
+ return @app.call(env)
138
+ end
139
+ data = self.class.operation_store.get(client_name: parts[0], operation_alias: parts[1])
140
+ # Query can't be resolved
141
+ if !data
142
+ return @app.call(env)
143
+ end
144
+
145
+ if data.name
146
+ req.merge!('operationName' => data.name)
147
+ end
148
+
149
+ if data.body
150
+ req.merge!('query' => data.body)
151
+ end
152
+ end
153
+ end
154
+
79
155
  # Read request from query param
80
- gReq = JSON.dump({ 'query' => request.params['query'] })
156
+ gReq = JSON.dump(req)
81
157
  end
82
158
 
83
159
  q = Query.new(self.class.instance, gReq)
@@ -87,7 +163,7 @@ module Inigo
87
163
 
88
164
  # Introspection query
89
165
  if resp.any?
90
- return respond(resp)
166
+ return respond(200, { 'Content-Type' => 'application/json'}, resp)
91
167
  end
92
168
 
93
169
  # Modify query if required
@@ -108,12 +184,12 @@ module Inigo
108
184
  end
109
185
 
110
186
  # Forward to request handler
111
- response = @app.call(env)
187
+ status, headers, response = @app.call(env)
112
188
 
113
189
  # Inigo: process response
114
- processed_response = q.process_response(response[2].body.to_s)
190
+ processed_response = q.process_response(response.body.to_s)
115
191
  if processed_response
116
- return respond(processed_response)
192
+ return respond(status, headers, processed_response)
117
193
  end
118
194
 
119
195
  response
@@ -121,12 +197,17 @@ module Inigo
121
197
 
122
198
  private
123
199
 
124
- def self.initialize_middleware(schema = nil)
200
+ def self.initialize_middleware(schema = nil, operation_store = nil)
125
201
  return if @@initialized
126
202
 
127
203
  if schema
128
204
  @@schema = schema
129
205
  end
206
+
207
+ if operation_store
208
+ @@operation_store = operation_store
209
+ end
210
+
130
211
  # get all the inigo settings from env
131
212
  settings = ENV.select { |k, v| k.start_with?('INIGO') }
132
213
 
@@ -190,14 +271,13 @@ module Inigo
190
271
  JSON.dump(headers)
191
272
  end
192
273
 
193
- def respond(data)
194
- response = Rack::Response.new
274
+ def respond(status, headers, data)
195
275
  response_hash = {}
196
276
  response_hash['data'] = data['data'] if data['data']
197
277
  response_hash['errors'] = data['errors'] if data['errors']
198
278
  response_hash['extensions'] = data['extensions'] if data['extensions']
199
- response.write(JSON.dump(response_hash))
200
- response.finish
279
+
280
+ [status, headers, [JSON.dump(response_hash)]]
201
281
  end
202
282
 
203
283
  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.4
4
+ version: 0.27.5
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-02 00:00:00.000000000 Z
11
+ date: 2023-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt