graphiti_graphql 0.1.5 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/bin/bundle +22 -13
- data/graphiti_graphql.gemspec +1 -1
- data/lib/graphiti_graphql.rb +5 -1
- data/lib/graphiti_graphql/engine.rb +8 -7
- data/lib/graphiti_graphql/federation/loaders/has_many.rb +13 -0
- data/lib/graphiti_graphql/runner.rb +22 -3
- data/lib/graphiti_graphql/schema.rb +40 -2
- data/lib/graphiti_graphql/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bd5442b050cb69b0ee1d2bc601f6bba2aa6f891d87f0d30168f70979881e779
|
4
|
+
data.tar.gz: 2135585438d5c17da4a74f3e35110e6030a2ba52229118490eb4d10d941fa326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31419e16ea7745753d88fdb633d4f71d7c57d0bd4bc04a205df835d49cb0fb61412c7287ff53e992bf4f47cc50af1e8869fd525ee478a65dad8623c98513951c
|
7
|
+
data.tar.gz: 3415e4aab9e14a5c31338dc052f1e5487c4ee377e5def3fbccf49e60e3a33de8eca819d0b6f003c44e5d93c7b4a264f6e6ccae63249948ab09fbe94519e6a9b6
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphiti_graphql (0.1.
|
4
|
+
graphiti_graphql (0.1.6)
|
5
5
|
activesupport (>= 4.1)
|
6
|
-
graphiti (
|
6
|
+
graphiti (~> 1.3)
|
7
7
|
graphql (~> 1.12)
|
8
8
|
|
9
9
|
GEM
|
@@ -28,13 +28,13 @@ GEM
|
|
28
28
|
dry-configurable (0.12.1)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
dry-core (~> 0.5, >= 0.5.0)
|
31
|
-
dry-container (0.
|
31
|
+
dry-container (0.8.0)
|
32
32
|
concurrent-ruby (~> 1.0)
|
33
33
|
dry-configurable (~> 0.1, >= 0.1.3)
|
34
|
-
dry-core (0.
|
34
|
+
dry-core (0.7.1)
|
35
35
|
concurrent-ruby (~> 1.0)
|
36
|
-
dry-inflector (0.2.
|
37
|
-
dry-logic (1.
|
36
|
+
dry-inflector (0.2.1)
|
37
|
+
dry-logic (1.2.0)
|
38
38
|
concurrent-ruby (~> 1.0)
|
39
39
|
dry-core (~> 0.5, >= 0.5)
|
40
40
|
dry-types (1.5.1)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
dry-inflector (~> 0.1, >= 0.1.2)
|
45
45
|
dry-logic (~> 1.0, >= 1.0.2)
|
46
46
|
google-protobuf (3.15.2)
|
47
|
-
graphiti (1.
|
47
|
+
graphiti (1.3.0)
|
48
48
|
activesupport (>= 4.1)
|
49
49
|
concurrent-ruby (~> 1.0)
|
50
50
|
dry-types (>= 0.15.0, < 2.0)
|
data/bin/bundle
CHANGED
@@ -31,7 +31,7 @@ m = Module.new do
|
|
31
31
|
bundler_version = a
|
32
32
|
end
|
33
33
|
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
-
bundler_version = $1
|
34
|
+
bundler_version = $1
|
35
35
|
update_index = i
|
36
36
|
end
|
37
37
|
bundler_version
|
@@ -61,32 +61,41 @@ m = Module.new do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def bundler_version
|
64
|
-
@bundler_version ||=
|
64
|
+
@bundler_version ||=
|
65
65
|
env_var_version || cli_arg_version ||
|
66
|
-
lockfile_version
|
67
|
-
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
68
81
|
end
|
69
82
|
|
70
83
|
def load_bundler!
|
71
84
|
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
72
85
|
|
73
|
-
|
74
|
-
activate_bundler(bundler_version.dup)
|
86
|
+
activate_bundler
|
75
87
|
end
|
76
88
|
|
77
|
-
def activate_bundler
|
78
|
-
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
|
79
|
-
bundler_version = "< 2"
|
80
|
-
end
|
89
|
+
def activate_bundler
|
81
90
|
gem_error = activation_error_handling do
|
82
|
-
gem "bundler",
|
91
|
+
gem "bundler", bundler_requirement
|
83
92
|
end
|
84
93
|
return if gem_error.nil?
|
85
94
|
require_error = activation_error_handling do
|
86
95
|
require "bundler/version"
|
87
96
|
end
|
88
|
-
return if require_error.nil? && Gem::Requirement.new(
|
89
|
-
warn "Activating bundler (#{
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
90
99
|
exit 42
|
91
100
|
end
|
92
101
|
|
data/graphiti_graphql.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency "graphiti", "
|
30
|
+
spec.add_dependency "graphiti", "~> 1.3"
|
31
31
|
spec.add_dependency "activesupport", ">= 4.1"
|
32
32
|
spec.add_dependency "graphql", "~> 1.12"
|
33
33
|
|
data/lib/graphiti_graphql.rb
CHANGED
@@ -13,7 +13,7 @@ require "graphiti_graphql/util"
|
|
13
13
|
|
14
14
|
module GraphitiGraphQL
|
15
15
|
class Configuration
|
16
|
-
attr_accessor :schema_reloading
|
16
|
+
attr_accessor :schema_reloading, :federation_application_controller
|
17
17
|
|
18
18
|
def initialize
|
19
19
|
self.schema_reloading = true
|
@@ -74,6 +74,10 @@ module GraphitiGraphQL
|
|
74
74
|
@config ||= Configuration.new
|
75
75
|
end
|
76
76
|
|
77
|
+
def self.configure
|
78
|
+
yield config
|
79
|
+
end
|
80
|
+
|
77
81
|
def self.schemas
|
78
82
|
@schemas ||= SchemaProxy.new
|
79
83
|
end
|
@@ -64,14 +64,15 @@ module GraphitiGraphQL
|
|
64
64
|
end
|
65
65
|
|
66
66
|
initializer "graphiti_graphql.define_controller" do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
app_controller = GraphitiGraphQL.config.federation_application_controller || ::ApplicationController
|
68
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
|
69
|
+
class GraphitiGraphQL::ExecutionController < app_controller
|
70
|
+
register_exception Graphiti::Errors::UnreadableAttribute, message: true
|
71
|
+
def execute
|
72
|
+
params = request.params # avoid strong_parameters
|
73
|
+
render json: Graphiti.gql(params[:query], params[:variables])
|
74
|
+
end
|
73
75
|
end
|
74
|
-
end
|
75
76
|
end
|
76
77
|
|
77
78
|
initializer "graphiti_graphql.federation" do
|
@@ -15,6 +15,19 @@ module GraphitiGraphQL
|
|
15
15
|
|
16
16
|
@federated_relationship.params_block&.call(@params)
|
17
17
|
|
18
|
+
if (first = @params.delete(:first))
|
19
|
+
@params[:page] ||= {}
|
20
|
+
@params[:page][:size] = first
|
21
|
+
end
|
22
|
+
if (after = @params.delete(:after))
|
23
|
+
@params[:page] ||= {}
|
24
|
+
@params[:page][:after] = after
|
25
|
+
end
|
26
|
+
if (before = @params.delete(:before))
|
27
|
+
@params[:page] ||= {}
|
28
|
+
@params[:page][:before] = before
|
29
|
+
end
|
30
|
+
|
18
31
|
if ids.length > 1 && @params[:page]
|
19
32
|
raise Graphiti::Errors::UnsupportedPagination
|
20
33
|
elsif !@params[:page]
|
@@ -282,11 +282,23 @@ module GraphitiGraphQL
|
|
282
282
|
def gather_pages(params, selection, variable_hash, chained_name = nil)
|
283
283
|
pages = {}.tap do |p|
|
284
284
|
selection.arguments.each do |arg|
|
285
|
-
if
|
285
|
+
if ["page", "first", "after", "before"].include?(arg.name)
|
286
286
|
value = if arg.value.respond_to?(:name) # is a variable
|
287
|
-
variable_hash[arg.value.name]
|
287
|
+
variable_hash[arg.value.name]
|
288
288
|
else
|
289
|
-
arg.value
|
289
|
+
arg.value
|
290
|
+
end
|
291
|
+
|
292
|
+
next unless value
|
293
|
+
|
294
|
+
value = if arg.name == "first"
|
295
|
+
{size: value}
|
296
|
+
elsif arg.name == "after"
|
297
|
+
{after: value}
|
298
|
+
elsif arg.name == "before"
|
299
|
+
{before: value}
|
300
|
+
else
|
301
|
+
value.to_h
|
290
302
|
end
|
291
303
|
|
292
304
|
if chained_name
|
@@ -304,6 +316,13 @@ module GraphitiGraphQL
|
|
304
316
|
params[:page] ||= {}
|
305
317
|
params[:page].merge!(pages)
|
306
318
|
end
|
319
|
+
|
320
|
+
(selection.try(:selections) || []).each do |sub|
|
321
|
+
if sub.try(:name) == "pageInfo"
|
322
|
+
params[:fields] ||= {}
|
323
|
+
params[:fields][:page_info] = sub.selections.map(&:name).map(&:underscore).join(",")
|
324
|
+
end
|
325
|
+
end
|
307
326
|
end
|
308
327
|
|
309
328
|
def gather_stats(params, selection, variable_hash, chained_name = nil)
|
@@ -93,6 +93,7 @@ module GraphitiGraphQL
|
|
93
93
|
query_class = Class.new(existing_query || self.class.base_object)
|
94
94
|
# NB MUST be Query or federation-ruby will break things
|
95
95
|
query_class.graphql_name "Query"
|
96
|
+
query_class.field_class BaseField
|
96
97
|
|
97
98
|
get_entrypoints(entrypoint_resources).each do |resource|
|
98
99
|
next if resource.remote?
|
@@ -145,22 +146,46 @@ module GraphitiGraphQL
|
|
145
146
|
[type],
|
146
147
|
"List #{resource.graphql_class_name(false).pluralize}",
|
147
148
|
null: false
|
149
|
+
|
150
|
+
# Stats currently only supported on top level
|
148
151
|
if top_level
|
152
|
+
klass.field :page_info, PageInfoType, null: false
|
149
153
|
klass.field :stats, generate_stat_class(resource), null: false
|
150
154
|
end
|
151
155
|
register(name, klass)
|
152
156
|
klass
|
153
157
|
end
|
154
158
|
|
159
|
+
# def edge_type(name, type)
|
160
|
+
# if (registered = type_registry[name])
|
161
|
+
# return registered[:type]
|
162
|
+
# end
|
163
|
+
|
164
|
+
# klass = Class.new(BaseObject) do
|
165
|
+
# graphql_name "#{name}Edge"
|
166
|
+
# field :cursor, String, null: false
|
167
|
+
# field :node, type, null: false
|
168
|
+
# end
|
169
|
+
# type_registry[name] = {type: klass}
|
170
|
+
# klass
|
171
|
+
# end
|
172
|
+
|
155
173
|
def add_index(query_class, resource)
|
156
174
|
field_name = resource.graphql_entrypoint.to_s.underscore.to_sym
|
157
175
|
field = query_class.field field_name,
|
158
176
|
generate_connection_type(resource, top_level: true),
|
159
|
-
null: false
|
177
|
+
null: false,
|
178
|
+
connection: false
|
160
179
|
@query_fields[field_name] = resource
|
161
180
|
define_arguments_for_sideload_field(field, resource)
|
162
181
|
end
|
163
182
|
|
183
|
+
def apply_connection_args(field)
|
184
|
+
field.argument :after, "String", "Cursor to paginate after", required: false
|
185
|
+
field.argument :before, "String", "Cursor to paginate before", required: false
|
186
|
+
field.argument :first, "Int", "Same as page.size", required: false
|
187
|
+
end
|
188
|
+
|
164
189
|
def add_show(query_class, resource)
|
165
190
|
field_name = resource.graphql_entrypoint.to_s.underscore.singularize.to_sym
|
166
191
|
field = query_class.field field_name,
|
@@ -222,6 +247,7 @@ module GraphitiGraphQL
|
|
222
247
|
field.argument :sort, [sort_type], required: false
|
223
248
|
end
|
224
249
|
field.argument :page, PageType, required: false
|
250
|
+
apply_connection_args(field)
|
225
251
|
|
226
252
|
unless resource.filters.empty?
|
227
253
|
filter_type = generate_filter_type(field, resource)
|
@@ -375,6 +401,8 @@ module GraphitiGraphQL
|
|
375
401
|
end
|
376
402
|
end
|
377
403
|
|
404
|
+
klass.field :_cursor, String, null: false
|
405
|
+
|
378
406
|
register(type_name, klass, resource, poly_parent)
|
379
407
|
|
380
408
|
resource.sideloads.each_pair do |name, sideload|
|
@@ -477,9 +505,19 @@ module GraphitiGraphQL
|
|
477
505
|
end
|
478
506
|
|
479
507
|
class PageType < GraphQL::Schema::InputObject
|
480
|
-
graphql_name "
|
508
|
+
graphql_name "PageInput"
|
481
509
|
argument :size, Int, required: false
|
482
510
|
argument :number, Int, required: false
|
511
|
+
argument :after, String, required: false
|
512
|
+
argument :before, String, required: false
|
513
|
+
end
|
514
|
+
|
515
|
+
class PageInfoType < BaseObject
|
516
|
+
graphql_name "PageInfo"
|
517
|
+
field :has_next_page, Boolean, null: false
|
518
|
+
field :has_previous_page, Boolean, null: false
|
519
|
+
field :start_cursor, String, null: true
|
520
|
+
field :end_cursor, String, null: true
|
483
521
|
end
|
484
522
|
|
485
523
|
class SortDirType < GraphQL::Schema::Enum
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti_graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphiti
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
274
|
- !ruby/object:Gem::Version
|
275
275
|
version: '0'
|
276
276
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.2.22
|
278
278
|
signing_key:
|
279
279
|
specification_version: 4
|
280
280
|
summary: GraphQL support for Graphiti
|