graphiform 0.2.6 → 0.2.11

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: 7499ef9e7181b749ac563666f65231e933d047bbdcc39dbe6f708bdb14e8eab9
4
- data.tar.gz: 3fc690f7cb20996f420516cceb158ff9aa103b2b7ed1e7bae6ceead0864f4409
3
+ metadata.gz: 7ee58551bb7e16aeccf79e81c5665e74cfa9bd6750c517b02eaef9f28deefe24
4
+ data.tar.gz: 1d37cf0e858774a84d88dd87e6bd67c00bfd5266c76ceb7aa656dc612019d275
5
5
  SHA512:
6
- metadata.gz: 7037e930060d081d86091b0c023fb3b3813b6a487bbe19785ebde5f6824eae27210839eb4174e5ea47f3499464aa346609ffc76838ab5c814063b754fa44393b
7
- data.tar.gz: b41292d3ab6b29c3ab9a2eaa8e02c1743f14095ccc88396e3e6602fb1d8e6964b8576885cb95d0006c88509a7befd54450415ce407e0ed31b4bc9f4eeaa38406
6
+ metadata.gz: 056d9d69dfe38e12fd40dae4b62a758f86dea1daddb8c1f140910a5ea86beb51f1ecbd19a38b624bf51ee654058d4a63f7177781e6dde548c33bd2543d92eecd
7
+ data.tar.gz: 84db19af1351992f07456ba23197661e8fc3a5843496ec2e2c53641f94786cbc7b8d675fd20566211e8ca419356f5b7d923de1b4da1f2a9a02b080095e80a3b8
@@ -37,6 +37,7 @@ module Graphiform
37
37
  end
38
38
  @filter.class_eval do
39
39
  argument 'OR', [self], required: false
40
+ argument 'AND', [self], required: false
40
41
  end
41
42
  end
42
43
 
@@ -52,6 +53,15 @@ module Graphiform
52
53
  end
53
54
  end
54
55
 
56
+ def graphql_grouping
57
+ local_demodulized_name = demodulized_name
58
+ Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Groupings) do
59
+ Class.new(::Inputs::Groupings::BaseGrouping) do
60
+ graphql_name "#{local_demodulized_name}Grouping"
61
+ end
62
+ end
63
+ end
64
+
55
65
  def graphql_edge
56
66
  Helpers.get_const_or_create("#{demodulized_name}Edge", ::Types) do
57
67
  node_type = graphql_type
@@ -99,9 +109,10 @@ module Graphiform
99
109
  @value
100
110
  end
101
111
 
102
- def apply_built_ins(where: nil, sort: nil, **)
112
+ def apply_built_ins(where: nil, sort: nil, group: nil, **)
103
113
  @value = @value.apply_filters(where.to_h) if where.present? && @value.respond_to?(:apply_filters)
104
114
  @value = @value.apply_sorts(sort.to_h) if sort.present? && @value.respond_to?(:apply_sorts)
115
+ @value = @value.apply_groupings(group.to_h) if group.present? && @value.respond_to?(:apply_groupings)
105
116
 
106
117
  @value
107
118
  end
@@ -115,6 +126,7 @@ module Graphiform
115
126
 
116
127
  local_graphql_filter = graphql_filter
117
128
  local_graphql_sort = graphql_sort
129
+ local_graphql_grouping = graphql_grouping
118
130
 
119
131
  model = self
120
132
  @base_resolver.class_eval do
@@ -126,6 +138,7 @@ module Graphiform
126
138
 
127
139
  argument :where, local_graphql_filter, required: false
128
140
  argument :sort, local_graphql_sort, required: false unless local_graphql_sort.arguments.empty?
141
+ argument :group, local_graphql_grouping, required: false unless local_graphql_grouping.arguments.empty?
129
142
  end
130
143
  end
131
144
 
@@ -141,7 +154,7 @@ module Graphiform
141
154
  def base_resolve(**args)
142
155
  @value = model.all
143
156
  apply_built_ins(**args)
144
- @value.first
157
+ @value.take
145
158
  end
146
159
  end
147
160
  end
@@ -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,
@@ -5,7 +5,7 @@ module Graphiform
5
5
  def self.logger
6
6
  return Rails.logger if Rails.logger.present?
7
7
 
8
- @logger ||= Logger.new(STDOUT)
8
+ @logger ||= Logger.new($stdout)
9
9
  @logger
10
10
  end
11
11
 
@@ -32,6 +32,8 @@ module Graphiform
32
32
  GraphQL::Types::Float
33
33
  when :boolean
34
34
  GraphQL::Types::Boolean
35
+ when :json, :jsonb
36
+ GraphQL::Types::JSON
35
37
  else
36
38
  active_record_type
37
39
  end
@@ -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.6'.freeze
2
+ VERSION = '0.2.11'.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.6
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2021-07-12 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.3
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.3
54
+ version: 0.2.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: appraisal
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
- rubygems_version: 3.0.3
149
+ rubyforge_project:
150
+ rubygems_version: 2.7.7
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Generate GraphQL types, inputs, resolvers, queries, and connections based