graphiti_graphql 0.1.6 → 0.1.10

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: fc07d6560d9c73767aca102d08c8c9f6b31fe09b8f3bb6db266a6566d8c3b50d
4
- data.tar.gz: c51c68edca23ae65f7b3c0a6e7f45d9546442d619fcc76f97682dc24e0b01644
3
+ metadata.gz: 4280e5808da769052de5faf957ad7b7e6b01ee6d5ae7ccd4dd2be210e250da97
4
+ data.tar.gz: a40b2972d39e385fabab7c06ba64fd02a4b53c7b91c6aba4686b9805da12aae1
5
5
  SHA512:
6
- metadata.gz: a9338e7a088054719c0f80147587dff04ebc9320c77ccec823798436a6fa671b616d6df8c9970d64bba332254ee8b08f46a7ef380aea0087889f9592446c0b9e
7
- data.tar.gz: 5cae58a969a23d6dcb0ee8b80a56af8d42eee6a7b0e6c16a6bba8d7b9d009bc78663cdb9e5520572d95c384a91df3e38b7f756a247c3f8b36697e16022ab8fda
6
+ metadata.gz: f15781ad3da2924d6315d0942a4d6dbdb11f2dd31dacd93a03076b3cbc853749d72f643a509da76ea90ebd2473ac60258ec44c65f9e70e83540855a0eabc1ac1
7
+ data.tar.gz: db48fd742bdb61b704af19bb2bcc254cb51190322708f8c435da4871609cb9019e41716d6d089dbd9b69e600b99160b51148c8dee5e6b4d5f6d414fd970e92d2
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_graphql (0.1.4)
4
+ graphiti_graphql (0.1.10)
5
5
  activesupport (>= 4.1)
6
- graphiti (>= 1.2.36)
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.7.2)
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.5.0)
34
+ dry-core (0.7.1)
35
35
  concurrent-ruby (~> 1.0)
36
- dry-inflector (0.2.0)
37
- dry-logic (1.1.0)
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.2.36)
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)
@@ -80,7 +80,7 @@ GEM
80
80
  rainbow (3.0.0)
81
81
  rake (10.5.0)
82
82
  regexp_parser (2.0.3)
83
- rexml (3.2.4)
83
+ rexml (3.2.5)
84
84
  rspec (3.10.0)
85
85
  rspec-core (~> 3.10.0)
86
86
  rspec-expectations (~> 3.10.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 || ">= 0.a"
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 ||= begin
64
+ @bundler_version ||=
65
65
  env_var_version || cli_arg_version ||
66
- lockfile_version || "#{Gem::Requirement.default}.a"
67
- end
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
- # must dup string for RG < 1.8 compatibility
74
- activate_bundler(bundler_version.dup)
86
+ activate_bundler
75
87
  end
76
88
 
77
- def activate_bundler(bundler_version)
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", bundler_version
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(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
- warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
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
 
@@ -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", ">= 1.2.36"
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
 
@@ -64,15 +64,15 @@ module GraphitiGraphQL
64
64
  end
65
65
 
66
66
  initializer "graphiti_graphql.define_controller" do
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])
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
74
75
  end
75
- end
76
76
  end
77
77
 
78
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 arg.name == "page"
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].to_h
287
+ variable_hash[arg.value.name]
288
288
  else
289
- arg.value.to_h
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,11 +93,16 @@ 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
- get_entrypoints(entrypoint_resources).each do |resource|
98
+ # Ensure all types are generated, even if they aren't in a top-level Query
99
+ # We might now want to expose the query, but do want to federate the Type
100
+ graphiti_schema.resources.each do |resource|
98
101
  next if resource.remote?
99
102
  generate_type(resource)
103
+ end
100
104
 
105
+ get_entrypoints(entrypoint_resources).each do |resource|
101
106
  add_index(query_class, resource)
102
107
  add_show(query_class, resource)
103
108
  end
@@ -145,22 +150,46 @@ module GraphitiGraphQL
145
150
  [type],
146
151
  "List #{resource.graphql_class_name(false).pluralize}",
147
152
  null: false
153
+
154
+ # Stats currently only supported on top level
148
155
  if top_level
156
+ klass.field :page_info, PageInfoType, null: false
149
157
  klass.field :stats, generate_stat_class(resource), null: false
150
158
  end
151
159
  register(name, klass)
152
160
  klass
153
161
  end
154
162
 
163
+ # def edge_type(name, type)
164
+ # if (registered = type_registry[name])
165
+ # return registered[:type]
166
+ # end
167
+
168
+ # klass = Class.new(BaseObject) do
169
+ # graphql_name "#{name}Edge"
170
+ # field :cursor, String, null: false
171
+ # field :node, type, null: false
172
+ # end
173
+ # type_registry[name] = {type: klass}
174
+ # klass
175
+ # end
176
+
155
177
  def add_index(query_class, resource)
156
178
  field_name = resource.graphql_entrypoint.to_s.underscore.to_sym
157
179
  field = query_class.field field_name,
158
180
  generate_connection_type(resource, top_level: true),
159
- null: false
181
+ null: false,
182
+ connection: false
160
183
  @query_fields[field_name] = resource
161
184
  define_arguments_for_sideload_field(field, resource)
162
185
  end
163
186
 
187
+ def apply_connection_args(field)
188
+ field.argument :after, "String", "Cursor to paginate after", required: false
189
+ field.argument :before, "String", "Cursor to paginate before", required: false
190
+ field.argument :first, "Int", "Same as page.size", required: false
191
+ end
192
+
164
193
  def add_show(query_class, resource)
165
194
  field_name = resource.graphql_entrypoint.to_s.underscore.singularize.to_sym
166
195
  field = query_class.field field_name,
@@ -222,6 +251,7 @@ module GraphitiGraphQL
222
251
  field.argument :sort, [sort_type], required: false
223
252
  end
224
253
  field.argument :page, PageType, required: false
254
+ apply_connection_args(field)
225
255
 
226
256
  unless resource.filters.empty?
227
257
  filter_type = generate_filter_type(field, resource)
@@ -375,6 +405,8 @@ module GraphitiGraphQL
375
405
  end
376
406
  end
377
407
 
408
+ klass.field :_cursor, String, null: false
409
+
378
410
  register(type_name, klass, resource, poly_parent)
379
411
 
380
412
  resource.sideloads.each_pair do |name, sideload|
@@ -477,9 +509,19 @@ module GraphitiGraphQL
477
509
  end
478
510
 
479
511
  class PageType < GraphQL::Schema::InputObject
480
- graphql_name "Page"
512
+ graphql_name "PageInput"
481
513
  argument :size, Int, required: false
482
514
  argument :number, Int, required: false
515
+ argument :after, String, required: false
516
+ argument :before, String, required: false
517
+ end
518
+
519
+ class PageInfoType < BaseObject
520
+ graphql_name "PageInfo"
521
+ field :has_next_page, Boolean, null: false
522
+ field :has_previous_page, Boolean, null: false
523
+ field :start_cursor, String, null: true
524
+ field :end_cursor, String, null: true
483
525
  end
484
526
 
485
527
  class SortDirType < GraphQL::Schema::Enum
@@ -1,3 +1,3 @@
1
1
  module GraphitiGraphQL
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.10"
3
3
  end
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.6
4
+ version: 0.1.10
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-06-23 00:00:00.000000000 Z
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.2.36
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.2.36
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.0.3
277
+ rubygems_version: 3.2.22
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: GraphQL support for Graphiti