graphiti_gql 0.2.7 → 0.2.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: d38c8d27dc214efd323ee98932bcb858bca8553e45c5e4428858b3b5503db44d
4
- data.tar.gz: ae38e08ba55f6c38b464ed9a3cbd592394568c080aac2361d0549adea259b9fe
3
+ metadata.gz: c8778ea5c62ff7c2eb9f32d674ece0a9b0c87ee30f57417fe02e61e2ed8c75e8
4
+ data.tar.gz: a80c2443b2c13cbd0d36d7160f8b2e3bde75ac97d87b4d58278440fab0e8426e
5
5
  SHA512:
6
- metadata.gz: d50257d774787869a18187e76e924503fb34dfad8c4d93fd73d99289fc203626d120585448bc646175cb9ff80e607df5c374a6207a95732aeccedb2d20ea9d39
7
- data.tar.gz: e1f1ff11574682dd8946907f2e76e3b9279c08039e29e4bc1f53436f184c1e6bd0e04f2ef52f391526abd1d837ef6a9dbd3f1a8a617528ee90942857b66d9706
6
+ metadata.gz: cad6708ae17b85ec5010245978d2f1dae7077fbbcc7d1303241ac1798a110b58638e68ab4d66ffab73a285f5a6ea5d8bc92b2cc347e2bd49c87d3b74fe96dcd7
7
+ data.tar.gz: '09d2dc8810af44fca96160ab941cca950dd35779b7659b30882cd3e2ec3a40a9551055c5cc585ff6c9514a3c3952491c986225f8ede57e915dc64af0901df739'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_gql (0.2.2)
4
+ graphiti_gql (0.2.9)
5
5
  graphiti (~> 1.3.9)
6
6
  graphql (~> 2.0)
7
7
  graphql-batch (~> 0.5)
@@ -118,7 +118,7 @@ module GraphitiGql
118
118
 
119
119
  name = Schema.registry.key_for(@resource)
120
120
  sortvar = "$sort: [#{name}Sort!]," if @resource.sorts.any?
121
- filter_bang = "!" if @resource.filters.values.any? { |f| f[:required] }
121
+ filter_bang = "!" if @resource.grouped_filters.any? || @resource.filters.values.any? { |f| f[:required] }
122
122
  filtervar = "$filter: #{name}Filter#{filter_bang}," if @resource.filters.any?
123
123
 
124
124
  if !(fields = @params[:fields])
@@ -162,6 +162,7 @@ module GraphitiGql
162
162
 
163
163
  def apply_belongs_to_many_filter
164
164
  super
165
+ return unless respond_to?(:belongs_to_many_filter) # activerecord
165
166
  self_ref = self
166
167
  fk_type = parent_resource_class.attributes[:id][:type]
167
168
  fk_type = :hash if polymorphic?
@@ -4,11 +4,8 @@ module GraphitiGql
4
4
  class ToMany
5
5
  def initialize(sideload, sideload_type)
6
6
  @sideload = sideload
7
- @sideload_type = if customized_edge?
8
- build_customized_edge_type(sideload_type)
9
- else
10
- sideload_type
11
- end
7
+ @sideload_type = sideload_type
8
+ @connection_type = find_or_build_connection
12
9
  end
13
10
 
14
11
  def apply(type)
@@ -18,7 +15,7 @@ module GraphitiGql
18
15
  extras: [:lookahead]
19
16
  }
20
17
  opts[:extensions] = [RelayConnectionExtension] unless has_one?
21
- field_type = has_one? ? @sideload_type : @sideload_type.connection_type
18
+ field_type = has_one? ? @sideload_type : @connection_type
22
19
  field = type.field @sideload.name,
23
20
  field_type,
24
21
  **opts
@@ -41,23 +38,23 @@ module GraphitiGql
41
38
  @sideload.type == :many_to_many && @sideload.class.edge_resource
42
39
  end
43
40
 
44
- def build_customized_edge_type(sideload_type)
45
- edge_type_class = build_edge_type_class(sideload_type)
41
+ def find_or_build_connection
42
+ registered_parent = Schema.registry.get(@sideload.parent_resource.class)
43
+ parent_name = registered_parent[:type].graphql_name
44
+ name = "#{parent_name}To#{@sideload_type.graphql_name}Connection"
45
+ return Schema.registry[name][:type] if Schema.registry[name]
46
46
 
47
- # Build the sideload type with new edge class applied
48
- if sideload_type.is_a?(Module)
49
- klass = sideload_type
50
- # There's some magic that happens when subclassing, but modules
51
- # don't subclass. This is the kind of resetting we need to happen.
52
- # Might be a graphql-ruby issue.
53
- klass.instance_variable_set(:@connection_type, nil)
54
- klass.instance_variable_set(:@edge_type, nil)
55
- klass.edge_type_class(edge_type_class)
47
+ if customized_edge?
48
+ prior = @sideload_type.connection_type
49
+ klass = Class.new(prior)
50
+ klass.graphql_name(name)
51
+ edge_type_class = build_edge_type_class(@sideload_type)
52
+ edge_type_class.node_type(prior.node_type)
53
+ klass.edge_type(edge_type_class)
54
+ Schema.registry[name] = { type: klass }
56
55
  klass
57
56
  else
58
- klass = Class.new(sideload_type)
59
- klass.edge_type_class(edge_class)
60
- klass
57
+ @sideload_type.connection_type
61
58
  end
62
59
  end
63
60
 
@@ -23,16 +23,20 @@ module GraphitiGql
23
23
  Registry.instance
24
24
  end
25
25
 
26
+ # TODO - when no sorts schema error, when no filters schema error
26
27
  def define_filters(field)
27
28
  filter_type = generate_filter_type(field)
28
29
  required = @resource.filters.any? { |name, config|
29
30
  value = !!config[:required]
30
31
  if @sideload
31
- value && @sideload.foreign_key != name
32
+ fk = @sideload.foreign_key
33
+ fk = fk.values.first if fk.is_a?(Hash)
34
+ value && fk != name
32
35
  else
33
36
  value
34
37
  end
35
38
  }
39
+ required = true if @resource.grouped_filters.any? && !@sideload
36
40
  field.argument :filter, filter_type, required: required
37
41
  end
38
42
 
@@ -43,11 +47,18 @@ module GraphitiGql
43
47
  end
44
48
  klass = Class.new(GraphQL::Schema::InputObject)
45
49
  klass.graphql_name type_name
50
+ required_via_group = []
51
+ if (group = @resource.grouped_filters).present?
52
+ if group[:required] == :all
53
+ required_via_group = group[:names].map(&:to_sym)
54
+ end
55
+ end
46
56
  @resource.filters.each_pair do |name, config|
47
57
  attr_type = generate_filter_attribute_type(type_name, name, config)
58
+ required = !!config[:required] || required_via_group.include?(name)
48
59
  klass.argument name.to_s.camelize(:lower),
49
60
  attr_type,
50
- required: !!config[:required]
61
+ required: required
51
62
  end
52
63
  registry[type_name] = { type: klass }
53
64
  klass
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '7.0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - richmolj@gmail.com
114
114
  executables: []
@@ -170,7 +170,7 @@ licenses:
170
170
  - MIT
171
171
  metadata:
172
172
  homepage_uri: https://www.graphiti.dev
173
- post_install_message:
173
+ post_install_message:
174
174
  rdoc_options: []
175
175
  require_paths:
176
176
  - lib
@@ -185,8 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubygems_version: 3.0.3.1
189
- signing_key:
188
+ rubygems_version: 3.3.7
189
+ signing_key:
190
190
  specification_version: 4
191
191
  summary: GraphQL support for Graphiti
192
192
  test_files: []