graphiform 0.2.8 → 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: 432786d8d7975e7f6e64f28d1bc59d0755ce92235a20316464443a919269ae0c
4
- data.tar.gz: cd9e5a854f67606b057fb6e98d6a5b43958aa8d6434d8178e6bb85b568925b5e
3
+ metadata.gz: 841f7ddfa6fd9f56cda166df64e77ec0d94fac684c872ce44b5fc024afe3d433
4
+ data.tar.gz: 10c339a1f949bf05dfa2dcf94a8bf3332f3a1c468699c605ab8ac60966644fd0
5
5
  SHA512:
6
- metadata.gz: 5ab126d3a8225ac6142b1e6088939d8e30dea963b9b1413ada93261e79a9324153e6307764fe11c7ff76180015ce359bee435c33d0ee950b213713bd71e986e6
7
- data.tar.gz: 60e32edb27e043e3440d1b5c97128a7e7873a1df2df60386c86253653b7842b85f6f6300bb3b5b1ded0d02822db9af66f618ecd110b0fa22c13a43fb96f83b0e
6
+ metadata.gz: e72009f747cf7bf8b6655940eb443900cf2c08e419cb25e1786aafc1b36347fb0f6916bc7d837a82681e46280a6bc5b6fe617b80ba081556f7acf319f01ed40b
7
+ data.tar.gz: d13b40bf891ccad27f83e7a23c55b20b5c94c594bc83d28ee07b762aca7a5740030aeaec20789d2cccc590ca701a566e0257555d5e0c2ee67fe02608e61c25ec
@@ -52,6 +52,15 @@ module Graphiform
52
52
  end
53
53
  end
54
54
 
55
+ def graphql_grouping
56
+ local_demodulized_name = demodulized_name
57
+ Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Groupings) do
58
+ Class.new(::Inputs::Groupings::BaseGrouping) do
59
+ graphql_name "#{local_demodulized_name}Grouping"
60
+ end
61
+ end
62
+ end
63
+
55
64
  def graphql_edge
56
65
  Helpers.get_const_or_create("#{demodulized_name}Edge", ::Types) do
57
66
  node_type = graphql_type
@@ -99,9 +108,10 @@ module Graphiform
99
108
  @value
100
109
  end
101
110
 
102
- def apply_built_ins(where: nil, sort: nil, **)
111
+ def apply_built_ins(where: nil, sort: nil, group: nil, **)
103
112
  @value = @value.apply_filters(where.to_h) if where.present? && @value.respond_to?(:apply_filters)
104
113
  @value = @value.apply_sorts(sort.to_h) if sort.present? && @value.respond_to?(:apply_sorts)
114
+ @value = @value.apply_groupings(group.to_h) if group.present? && @value.respond_to?(:apply_groupings)
105
115
 
106
116
  @value
107
117
  end
@@ -115,6 +125,7 @@ module Graphiform
115
125
 
116
126
  local_graphql_filter = graphql_filter
117
127
  local_graphql_sort = graphql_sort
128
+ local_graphql_grouping = graphql_grouping
118
129
 
119
130
  model = self
120
131
  @base_resolver.class_eval do
@@ -126,6 +137,7 @@ module Graphiform
126
137
 
127
138
  argument :where, local_graphql_filter, required: false
128
139
  argument :sort, local_graphql_sort, required: false unless local_graphql_sort.arguments.empty?
140
+ argument :group, local_graphql_grouping, required: false unless local_graphql_grouping.arguments.empty?
129
141
  end
130
142
  end
131
143
 
@@ -21,6 +21,7 @@ module Graphiform
21
21
 
22
22
  graphql_add_scopes_to_filter(name, as || name)
23
23
  graphql_field_to_sort(name, as || name)
24
+ graphql_field_to_grouping(name, as || name)
24
25
  end
25
26
 
26
27
  def graphql_writable_field(
@@ -120,9 +121,11 @@ module Graphiform
120
121
  type = association_def.klass.graphql_filter
121
122
  end
122
123
 
123
- non_sort_by_scopes = added_scopes.select { |scope_def| !scope_def.options || scope_def.options[:type] != :sort }
124
+ filter_only_by_scopes = added_scopes.select do |scope_def|
125
+ !scope_def.options || scope_def.options[:type].blank? || scope_def.options[:type] == :enum
126
+ end
124
127
 
125
- non_sort_by_scopes.each do |added_scope|
128
+ filter_only_by_scopes.each do |added_scope|
126
129
  scope_argument_type = type || added_scope.options[:argument_type]
127
130
  if added_scope.options[:type] == :enum
128
131
  enum = graphql_create_enum(name)
@@ -175,6 +178,28 @@ module Graphiform
175
178
  end
176
179
  end
177
180
 
181
+ def graphql_field_to_grouping(name, as)
182
+ column_def = column(as || name)
183
+ association_def = association(as || name)
184
+
185
+ type = GraphQL::Types::Boolean if column_def.present?
186
+ type = association_def.klass.graphql_grouping if Helpers.association_arguments_valid?(association_def, :graphql_grouping)
187
+
188
+ return if type.blank?
189
+
190
+ local_graphql_grouping = graphql_grouping
191
+
192
+ local_graphql_grouping.class_eval do
193
+ argument(
194
+ name,
195
+ type,
196
+ required: false,
197
+ as: as,
198
+ method_access: false
199
+ )
200
+ end
201
+ end
202
+
178
203
  def graphql_add_field_to_type(
179
204
  field_name,
180
205
  type,
@@ -45,6 +45,14 @@ module Graphiform
45
45
  Class.new(::GraphQL::Schema::InputObject)
46
46
  end
47
47
 
48
+ Helpers.get_const_or_create('Groupings', ::Inputs) do
49
+ Module.new
50
+ end
51
+
52
+ Helpers.get_const_or_create('BaseGrouping', ::Inputs::Groupings) do
53
+ Class.new(::GraphQL::Schema::InputObject)
54
+ end
55
+
48
56
  # Resolvers
49
57
  Helpers.get_const_or_create('Resolvers') do
50
58
  Module.new
@@ -1,3 +1,3 @@
1
1
  module Graphiform
2
- VERSION = '0.2.8'.freeze
2
+ VERSION = '0.2.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.6
47
+ version: 0.2.7
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.6
54
+ version: 0.2.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: appraisal
57
57
  requirement: !ruby/object:Gem::Requirement