inigorb 0.27.4 → 0.27.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inigo-darwin-amd64.dylib +0 -0
- data/lib/inigo-darwin-arm64.dylib +0 -0
- data/lib/inigo-linux-amd64.so +0 -0
- data/lib/inigo-linux-arm64.so +0 -0
- data/lib/inigo-windows-amd64.dll +0 -0
- data/lib/inigo-windows-arm64.dll +0 -0
- data/lib/inigorb.rb +108 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 788d97815fbd001b6eebffed2c9f7c9ef5ea8eddb4228c060ce8dfc155b71aa0
|
4
|
+
data.tar.gz: b21a0572e9fabb0c6c55fe1a112c2e09f0fc5891e9a9353a05599e43a843a1ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4120ce3939645d632e5f72e17bf5342e2e7c869368e64cb05f6d9fb411f6eaf73afb3088828c081db4a6d3ea15341403c25396d021303b8387a2fc49a1214669
|
7
|
+
data.tar.gz: 9a97a310ced373289fccb74631452212da345acb5e7d2ea1c45ec46b1e7f95ec016fccf7d0d15ec6994758416d1301ddc7eee0cbd111a63989a1e6582c4c7364
|
Binary file
|
Binary file
|
data/lib/inigo-linux-amd64.so
CHANGED
Binary file
|
data/lib/inigo-linux-arm64.so
CHANGED
Binary file
|
data/lib/inigo-windows-amd64.dll
CHANGED
Binary file
|
data/lib/inigo-windows-arm64.dll
CHANGED
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
|
@@ -54,13 +63,15 @@ module Inigo
|
|
54
63
|
|
55
64
|
request = Rack::Request.new(env)
|
56
65
|
|
57
|
-
|
58
|
-
|
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)
|
59
70
|
return @app.call(env)
|
60
71
|
end
|
61
72
|
|
62
73
|
# GraphiQL request
|
63
|
-
if request.get? &&
|
74
|
+
if request.get? && env['HTTP_ACCEPT'].include?('text/html')
|
64
75
|
return @app.call(env)
|
65
76
|
end
|
66
77
|
|
@@ -74,10 +85,71 @@ module Inigo
|
|
74
85
|
if request.post?
|
75
86
|
# Read request from body
|
76
87
|
request.body.each { |chunk| gReq += chunk }
|
88
|
+
|
89
|
+
if self.class.operation_store.present? && has_operation_id?(gReq)
|
90
|
+
parsed = JSON.parse(gReq)
|
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('/')
|
99
|
+
# Query can't be resolved
|
100
|
+
if parts.length != 2
|
101
|
+
request.body.rewind
|
102
|
+
return @app.call(env)
|
103
|
+
end
|
104
|
+
data = self.class.operation_store.get(client_name: parts[0], operation_alias: parts[1])
|
105
|
+
# Query can't be resolved
|
106
|
+
if !data
|
107
|
+
request.body.rewind
|
108
|
+
return @app.call(env)
|
109
|
+
end
|
110
|
+
if data.name
|
111
|
+
parsed.merge!('operationName' => data.name)
|
112
|
+
end
|
113
|
+
|
114
|
+
if data.body
|
115
|
+
parsed.merge!('query' => data.body)
|
116
|
+
end
|
117
|
+
|
118
|
+
gReq = ''
|
119
|
+
gReq = JSON.dump(parsed)
|
120
|
+
env['rack.input'] = StringIO.new(gReq)
|
121
|
+
env['CONTENT_LENGTH'] = gReq.length.to_s
|
122
|
+
env['CONTENT_TYPE'] = 'application/json'
|
123
|
+
end
|
77
124
|
request.body.rewind
|
78
125
|
elsif request.get?
|
126
|
+
operation_id = get_operation_id(request.params)
|
127
|
+
if operation_id && self.class.operation_store
|
128
|
+
parts = operation_id.split('/')
|
129
|
+
# Query can't be resolved
|
130
|
+
if parts.length != 2
|
131
|
+
return @app.call(env)
|
132
|
+
end
|
133
|
+
data = self.class.operation_store.get(client_name: parts[0], operation_alias: parts[1])
|
134
|
+
# Query can't be resolved
|
135
|
+
if !data
|
136
|
+
return @app.call(env)
|
137
|
+
end
|
138
|
+
|
139
|
+
if data.name
|
140
|
+
request.params['operationName'] = data.name
|
141
|
+
end
|
142
|
+
|
143
|
+
if data.body
|
144
|
+
request.params['query'] = data.body
|
145
|
+
end
|
146
|
+
|
147
|
+
# Update the env with the modified query string
|
148
|
+
env['QUERY_STRING'] = Rack::Utils.build_nested_query(request.params)
|
149
|
+
end
|
150
|
+
|
79
151
|
# Read request from query param
|
80
|
-
gReq = JSON.dump(
|
152
|
+
gReq = JSON.dump(request.params)
|
81
153
|
end
|
82
154
|
|
83
155
|
q = Query.new(self.class.instance, gReq)
|
@@ -87,7 +159,7 @@ module Inigo
|
|
87
159
|
|
88
160
|
# Introspection query
|
89
161
|
if resp.any?
|
90
|
-
return respond(resp)
|
162
|
+
return respond(200, { 'Content-Type' => 'application/json'}, resp)
|
91
163
|
end
|
92
164
|
|
93
165
|
# Modify query if required
|
@@ -108,12 +180,12 @@ module Inigo
|
|
108
180
|
end
|
109
181
|
|
110
182
|
# Forward to request handler
|
111
|
-
response = @app.call(env)
|
183
|
+
status, headers, response = @app.call(env)
|
112
184
|
|
113
185
|
# Inigo: process response
|
114
|
-
processed_response = q.process_response(response
|
186
|
+
processed_response = q.process_response(response.body.to_s)
|
115
187
|
if processed_response
|
116
|
-
return respond(processed_response)
|
188
|
+
return respond(status, headers, processed_response)
|
117
189
|
end
|
118
190
|
|
119
191
|
response
|
@@ -121,12 +193,17 @@ module Inigo
|
|
121
193
|
|
122
194
|
private
|
123
195
|
|
124
|
-
def self.initialize_middleware(schema = nil)
|
196
|
+
def self.initialize_middleware(schema = nil, operation_store = nil)
|
125
197
|
return if @@initialized
|
126
198
|
|
127
199
|
if schema
|
128
200
|
@@schema = schema
|
129
201
|
end
|
202
|
+
|
203
|
+
if operation_store
|
204
|
+
@@operation_store = operation_store
|
205
|
+
end
|
206
|
+
|
130
207
|
# get all the inigo settings from env
|
131
208
|
settings = ENV.select { |k, v| k.start_with?('INIGO') }
|
132
209
|
|
@@ -190,14 +267,32 @@ module Inigo
|
|
190
267
|
JSON.dump(headers)
|
191
268
|
end
|
192
269
|
|
193
|
-
def respond(data)
|
194
|
-
response = Rack::Response.new
|
270
|
+
def respond(status, headers, data)
|
195
271
|
response_hash = {}
|
196
272
|
response_hash['data'] = data['data'] if data['data']
|
197
273
|
response_hash['errors'] = data['errors'] if data['errors']
|
198
274
|
response_hash['extensions'] = data['extensions'] if data['extensions']
|
199
|
-
|
200
|
-
|
275
|
+
|
276
|
+
[status, headers, [JSON.dump(response_hash)]]
|
277
|
+
end
|
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
|
201
296
|
end
|
202
297
|
|
203
298
|
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
|
+
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-
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|