graphiti_gql 0.2.6 → 0.2.9

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: a0558a0d0edaf2e03b09fe28ce603afb10eb0cbd02e8aa56be43cfd1044bebab
4
- data.tar.gz: 69660d61a4191bd6428a2ad33d2f9e3e6a4227c31d4be636a6b886af543f35f3
3
+ metadata.gz: 544e1209bfdf6e48d70a76490edec46bc04639d75d91bae2a35ab95ea8fb4530
4
+ data.tar.gz: '0688127e3a2ab48d4bdd3f7f70a4efd544dd4bb4c9a952c0c4302ede86c1c24a'
5
5
  SHA512:
6
- metadata.gz: 892b44992e36645282bd7003218067d248e04ac6f440feaac137afa1449f9b01017d7bcb577bbaf3bd8dc7f1c808b7f9b6eaf6e0c4474b4f1d6910dabb49ad3e
7
- data.tar.gz: 3d29b975b6748e292e4420707c2f8e4825a8e743c197f70126863c230a22ad75f0efece663a2400704716d2c7621d8cdd90732185ee7540c317c23708004a4d0
6
+ metadata.gz: 67b52a3241814fd821cf23982ed55e02c1e0e171d41c5c3bb54cdcd53e04ea28a13fab327d86a5756dee7499f88d163316b93cfebf730a4681ab54a627693f9b
7
+ data.tar.gz: ce6ab0de40b33e0750f4eb33c63249c91a6b478503cce6fc0cc92081b18190346a9e4190027b940020f69459c40094a963b3a0d1e440e63ed4a2f47e1bd904cd
@@ -0,0 +1,2 @@
1
+ enabled:
2
+ - cla
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.8)
5
5
  graphiti (~> 1.3.9)
6
6
  graphql (~> 2.0)
7
7
  graphql-batch (~> 0.5)
@@ -17,6 +17,8 @@ module GraphitiGql
17
17
  Node.new(edge.except(:node).merge(node_id: node_id))
18
18
  end
19
19
  hash[key] = value[:edges].map { |v| Node.new(v[:node], sideload.resource.class) }
20
+ elsif value.key?(:nodes)
21
+ hash[key] = value[:nodes].map { |n| Node.new(n, sideload.resource.class) }
20
22
  else
21
23
  hash[key] = Node.new(value, sideload.resource.class)
22
24
  end
@@ -115,8 +117,9 @@ module GraphitiGql
115
117
  return @query if @query
116
118
 
117
119
  name = Schema.registry.key_for(@resource)
118
- filter_bang = "!" if @resource.filters.values.any? { |f| f[:required] }
119
120
  sortvar = "$sort: [#{name}Sort!]," if @resource.sorts.any?
121
+ filter_bang = "!" if @resource.filters.values.any? { |f| f[:required] }
122
+ filtervar = "$filter: #{name}Filter#{filter_bang}," if @resource.filters.any?
120
123
 
121
124
  if !(fields = @params[:fields])
122
125
  fields = []
@@ -127,7 +130,7 @@ module GraphitiGql
127
130
 
128
131
  q = %|
129
132
  query #{name} (
130
- $filter: #{name}Filter#{filter_bang},
133
+ #{filtervar}
131
134
  #{sortvar}
132
135
  $first: Int,
133
136
  $last: Int,
@@ -135,7 +138,7 @@ module GraphitiGql
135
138
  $after: String,
136
139
  ) {
137
140
  #{@resource.graphql_entrypoint} (
138
- filter: $filter,
141
+ #{ 'filter: $filter,' if filtervar }
139
142
  #{ 'sort: $sort,' if sortvar }
140
143
  first: $first,
141
144
  last: $last,
@@ -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,12 +23,15 @@ 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
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.9"
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.6
4
+ version: 0.2.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: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/probots.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".travis.yml"