graphiform 0.2.6 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphiform/core.rb +15 -2
- data/lib/graphiform/fields.rb +27 -2
- data/lib/graphiform/helpers.rb +3 -1
- data/lib/graphiform/skeleton.rb +8 -0
- data/lib/graphiform/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ee58551bb7e16aeccf79e81c5665e74cfa9bd6750c517b02eaef9f28deefe24
|
4
|
+
data.tar.gz: 1d37cf0e858774a84d88dd87e6bd67c00bfd5266c76ceb7aa656dc612019d275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056d9d69dfe38e12fd40dae4b62a758f86dea1daddb8c1f140910a5ea86beb51f1ecbd19a38b624bf51ee654058d4a63f7177781e6dde548c33bd2543d92eecd
|
7
|
+
data.tar.gz: 84db19af1351992f07456ba23197661e8fc3a5843496ec2e2c53641f94786cbc7b8d675fd20566211e8ca419356f5b7d923de1b4da1f2a9a02b080095e80a3b8
|
data/lib/graphiform/core.rb
CHANGED
@@ -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.
|
157
|
+
@value.take
|
145
158
|
end
|
146
159
|
end
|
147
160
|
end
|
data/lib/graphiform/fields.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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,
|
data/lib/graphiform/helpers.rb
CHANGED
@@ -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(
|
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
|
data/lib/graphiform/skeleton.rb
CHANGED
@@ -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
|
data/lib/graphiform/version.rb
CHANGED
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.
|
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:
|
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.
|
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.
|
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
|
-
|
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
|