graphiform 0.2.5 → 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: 2f56c92956905df19b6e8a756b8826c63710619ab9c67f5e019280ccca4c0cd5
4
- data.tar.gz: 6ac0fbb69feaa5d7a544dc1c5618f7c09b9cfd09fa6a0ad498e139e2c7539547
3
+ metadata.gz: 2e55c110ba5d43da683380c9539c51f93631a778035d365f6e2b46e17970e9da
4
+ data.tar.gz: 31a4e3a257380e80ccde4d64b82d1c25a2968103682e6007daad0ea4ab3aa74f
5
5
  SHA512:
6
- metadata.gz: 8fe2ea6fc9d0c5bd906357d7571b2aa187c247a2fccd573716da623e22f784c3aaf4337fae660ec5b30061a40af57ac99f2cd1ec68b93c35cf06b8098196da3d
7
- data.tar.gz: ee62442607c271725f12401d2d27f89667ef3992c41e7e09935809e5c2ee77c8aa99986d69a60ddacb7b0ab439717a47dd803a7579f3749514fca572fc440b15
6
+ metadata.gz: a2d85418970b93ad95ff1d8868a674365009d14e22158539c294e6ffeaa1cd9f4cb42026e4bfa672c8ddf97fd3a7ab980b1b6b3a33cbd134081eb2d4d1d79aea
7
+ data.tar.gz: 1a3314cb91a7bbffcb3060820e7cd9501b82aca0f168e6de51aca60df6e31e9635ada501361a319ba56327c0b8abe2150e81f1f52e9dda7800bda6708846b0cd
data/lib/graphiform.rb CHANGED
@@ -5,6 +5,7 @@ require 'graphiform/skeleton'
5
5
  require 'graphiform/active_record_helpers'
6
6
  require 'graphiform/core'
7
7
  require 'graphiform/fields'
8
+ require 'graphiform/sort_enum'
8
9
 
9
10
  module Graphiform
10
11
  def self.included(base)
@@ -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)
@@ -157,7 +160,7 @@ module Graphiform
157
160
  column_def = column(as || name)
158
161
  association_def = association(as || name)
159
162
 
160
- type = ::Enums::Sort if column_def.present?
163
+ type = ::Graphiform::SortEnum if column_def.present?
161
164
  type = association_def.klass.graphql_sort if Helpers.association_arguments_valid?(association_def, :graphql_sort)
162
165
 
163
166
  return if type.blank?
@@ -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,
@@ -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
@@ -80,12 +88,5 @@ module Graphiform
80
88
  Helpers.get_const_or_create('BaseEnum', ::Enums) do
81
89
  Class.new(::GraphQL::Schema::Enum)
82
90
  end
83
-
84
- Helpers.get_const_or_create('Sort', ::Enums) do
85
- Class.new(::Enums::BaseEnum) do
86
- value 'ASC', 'Sort results in ascending order'
87
- value 'DESC', 'Sort results in descending order'
88
- end
89
- end
90
91
  end
91
92
  end
@@ -0,0 +1,8 @@
1
+ require 'graphql'
2
+
3
+ module Graphiform
4
+ class SortEnum < ::GraphQL::Schema::Enum
5
+ value 'ASC', 'Sort results in ascending order'
6
+ value 'DESC', 'Sort results in descending order'
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Graphiform
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.10'.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.5
4
+ version: 0.2.10
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-08-02 00:00:00.000000000 Z
11
+ date: 2021-05-06 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
@@ -124,6 +124,7 @@ files:
124
124
  - lib/graphiform/fields.rb
125
125
  - lib/graphiform/helpers.rb
126
126
  - lib/graphiform/skeleton.rb
127
+ - lib/graphiform/sort_enum.rb
127
128
  - lib/graphiform/version.rb
128
129
  - lib/tasks/graphiform_tasks.rake
129
130
  homepage: https://github.com/3-form/graphiform
@@ -145,7 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  - !ruby/object:Gem::Version
146
147
  version: '0'
147
148
  requirements: []
148
- rubygems_version: 3.0.3
149
+ rubyforge_project:
150
+ rubygems_version: 2.7.7
149
151
  signing_key:
150
152
  specification_version: 4
151
153
  summary: Generate GraphQL types, inputs, resolvers, queries, and connections based