cm-graphql 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +45 -53
- data/app/graphql/types/base_connection.rb +29 -0
- data/app/graphql/types/inputs/image_resolution.rb +12 -0
- data/app/graphql/types/objects/base/attachment_type.rb +18 -7
- data/cm-graphql.gemspec +6 -6
- data/config/initializers/active_record_extension.rb +2 -0
- data/lib/generators/cm_graphql/add_graphql_generator.rb +1 -0
- data/lib/generators/cm_graphql/templates/base_connection.rb +29 -0
- metadata +9 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe03ea1105356f62c221657ccf7e1ac08f138cc537a1e28bf70f9ad1aa0e0b7
|
4
|
+
data.tar.gz: 8275b35c3ba06d16d1be8a32ea6fd0e528c9a6db7c63793d84f2d1e65d62a734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742fa1b707f8fd4e726879779293563da46f8c901f64987fd0897d0ccb6aafcf60a9fb010aa7e58d109da244584bbdc5074ac2d8ef142f6bfdc5c5727b3989da
|
7
|
+
data.tar.gz: 7ee1c3308c49eb9f5b14ce47c2b2d710160c8087b2bc645326ffb3e3a6b355e68614ca7856879659a14b546225dc19730dd13f22edfd311f0314b1d1f05b4811
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @Mahaveer1141 @anbublacky @mikevic
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cm-graphql (0.0.
|
5
|
-
graphiql-rails (
|
6
|
-
graphql (
|
7
|
-
graphql-rails_logger (
|
4
|
+
cm-graphql (0.0.6)
|
5
|
+
graphiql-rails (>= 1.9)
|
6
|
+
graphql (>= 2.2.5)
|
7
|
+
graphql-rails_logger (>= 1.2.4)
|
8
8
|
kaminari (~> 1.2, >= 1.2.2)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionpack (7.1.
|
14
|
-
actionview (= 7.1.
|
15
|
-
activesupport (= 7.1.
|
13
|
+
actionpack (7.1.3.3)
|
14
|
+
actionview (= 7.1.3.3)
|
15
|
+
activesupport (= 7.1.3.3)
|
16
16
|
nokogiri (>= 1.8.5)
|
17
17
|
racc
|
18
18
|
rack (>= 2.2.4)
|
@@ -20,19 +20,19 @@ GEM
|
|
20
20
|
rack-test (>= 0.6.3)
|
21
21
|
rails-dom-testing (~> 2.2)
|
22
22
|
rails-html-sanitizer (~> 1.6)
|
23
|
-
actionview (7.1.
|
24
|
-
activesupport (= 7.1.
|
23
|
+
actionview (7.1.3.3)
|
24
|
+
activesupport (= 7.1.3.3)
|
25
25
|
builder (~> 3.1)
|
26
26
|
erubi (~> 1.11)
|
27
27
|
rails-dom-testing (~> 2.2)
|
28
28
|
rails-html-sanitizer (~> 1.6)
|
29
|
-
activemodel (7.1.
|
30
|
-
activesupport (= 7.1.
|
31
|
-
activerecord (7.1.
|
32
|
-
activemodel (= 7.1.
|
33
|
-
activesupport (= 7.1.
|
29
|
+
activemodel (7.1.3.3)
|
30
|
+
activesupport (= 7.1.3.3)
|
31
|
+
activerecord (7.1.3.3)
|
32
|
+
activemodel (= 7.1.3.3)
|
33
|
+
activesupport (= 7.1.3.3)
|
34
34
|
timeout (>= 0.4.0)
|
35
|
-
activesupport (7.1.
|
35
|
+
activesupport (7.1.3.3)
|
36
36
|
base64
|
37
37
|
bigdecimal
|
38
38
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -43,29 +43,29 @@ GEM
|
|
43
43
|
mutex_m
|
44
44
|
tzinfo (~> 2.0)
|
45
45
|
base64 (0.2.0)
|
46
|
-
bigdecimal (3.1.
|
47
|
-
builder (3.
|
48
|
-
concurrent-ruby (1.
|
46
|
+
bigdecimal (3.1.8)
|
47
|
+
builder (3.3.0)
|
48
|
+
concurrent-ruby (1.3.4)
|
49
49
|
connection_pool (2.4.1)
|
50
50
|
crass (1.0.6)
|
51
|
-
drb (2.2.
|
52
|
-
|
53
|
-
|
54
|
-
graphiql-rails (1.
|
51
|
+
drb (2.2.1)
|
52
|
+
erubi (1.13.0)
|
53
|
+
fiber-storage (1.0.0)
|
54
|
+
graphiql-rails (1.10.1)
|
55
55
|
railties
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
graphql (2.3.17)
|
57
|
+
base64
|
58
|
+
fiber-storage
|
59
59
|
graphql-rails_logger (1.2.4)
|
60
60
|
actionpack (> 5.0)
|
61
61
|
activesupport (> 5.0)
|
62
62
|
railties (> 5.0)
|
63
63
|
rouge (~> 3.0)
|
64
|
-
i18n (1.14.
|
64
|
+
i18n (1.14.6)
|
65
65
|
concurrent-ruby (~> 1.0)
|
66
|
-
io-console (0.7.
|
67
|
-
irb (1.
|
68
|
-
rdoc
|
66
|
+
io-console (0.7.2)
|
67
|
+
irb (1.14.1)
|
68
|
+
rdoc (>= 4.0.0)
|
69
69
|
reline (>= 0.4.2)
|
70
70
|
kaminari (1.2.2)
|
71
71
|
activesupport (>= 4.1.0)
|
@@ -82,18 +82,18 @@ GEM
|
|
82
82
|
loofah (2.22.0)
|
83
83
|
crass (~> 1.0.2)
|
84
84
|
nokogiri (>= 1.12.0)
|
85
|
-
mini_portile2 (2.8.
|
86
|
-
minitest (5.
|
85
|
+
mini_portile2 (2.8.7)
|
86
|
+
minitest (5.25.1)
|
87
87
|
mutex_m (0.2.0)
|
88
|
-
nokogiri (1.16.
|
88
|
+
nokogiri (1.16.7)
|
89
89
|
mini_portile2 (~> 2.8.2)
|
90
90
|
racc (~> 1.4)
|
91
|
-
nokogiri (1.16.
|
91
|
+
nokogiri (1.16.7-arm64-darwin)
|
92
92
|
racc (~> 1.4)
|
93
93
|
psych (5.1.2)
|
94
94
|
stringio
|
95
|
-
racc (1.
|
96
|
-
rack (3.
|
95
|
+
racc (1.8.1)
|
96
|
+
rack (3.1.7)
|
97
97
|
rack-session (2.0.0)
|
98
98
|
rack (>= 3.0.0)
|
99
99
|
rack-test (2.1.0)
|
@@ -108,35 +108,27 @@ GEM
|
|
108
108
|
rails-html-sanitizer (1.6.0)
|
109
109
|
loofah (~> 2.21)
|
110
110
|
nokogiri (~> 1.14)
|
111
|
-
railties (7.1.
|
112
|
-
actionpack (= 7.1.
|
113
|
-
activesupport (= 7.1.
|
111
|
+
railties (7.1.3.3)
|
112
|
+
actionpack (= 7.1.3.3)
|
113
|
+
activesupport (= 7.1.3.3)
|
114
114
|
irb
|
115
115
|
rackup (>= 1.0.0)
|
116
116
|
rake (>= 12.2)
|
117
117
|
thor (~> 1.0, >= 1.2.2)
|
118
118
|
zeitwerk (~> 2.6)
|
119
|
-
rake (13.1
|
120
|
-
rdoc (6.
|
119
|
+
rake (13.2.1)
|
120
|
+
rdoc (6.7.0)
|
121
121
|
psych (>= 4.0.0)
|
122
|
-
reline (0.
|
122
|
+
reline (0.5.10)
|
123
123
|
io-console (~> 0.5)
|
124
124
|
rouge (3.30.0)
|
125
|
-
|
126
|
-
|
127
|
-
concurrent-ruby (~> 1.0)
|
128
|
-
rack (>= 2.2.4, < 4)
|
129
|
-
sprockets-rails (3.4.2)
|
130
|
-
actionpack (>= 5.2)
|
131
|
-
activesupport (>= 5.2)
|
132
|
-
sprockets (>= 3.0.0)
|
133
|
-
stringio (3.1.0)
|
134
|
-
thor (1.3.0)
|
125
|
+
stringio (3.1.1)
|
126
|
+
thor (1.3.2)
|
135
127
|
timeout (0.4.1)
|
136
128
|
tzinfo (2.0.6)
|
137
129
|
concurrent-ruby (~> 1.0)
|
138
|
-
webrick (1.8.
|
139
|
-
zeitwerk (2.6.
|
130
|
+
webrick (1.8.2)
|
131
|
+
zeitwerk (2.6.18)
|
140
132
|
|
141
133
|
PLATFORMS
|
142
134
|
arm64-darwin-20
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Types
|
2
|
+
class BaseConnection < Types::BaseObject
|
3
|
+
# add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
|
4
|
+
include GraphQL::Types::Relay::ConnectionBehaviors
|
5
|
+
|
6
|
+
field :total_count, Integer, "Total # of objects returned from this Plural Query", null: false
|
7
|
+
def total_count
|
8
|
+
object.nodes&.count
|
9
|
+
end
|
10
|
+
|
11
|
+
field :total_page_count, Integer, "Total # of pages, based on total count and pagesize", null: false
|
12
|
+
def total_page_count
|
13
|
+
return 1 unless object.nodes&.count&.positive?
|
14
|
+
# get total count and create array with total count as first item
|
15
|
+
my_total_count = object.nodes&.count
|
16
|
+
possible_page_sizes = [my_total_count]
|
17
|
+
|
18
|
+
# add first and last argument counts to the array if they exist
|
19
|
+
possible_page_sizes.push(object.arguments[:first]) if object.arguments[:first]
|
20
|
+
possible_page_sizes.push(object.arguments[:last]) if object.arguments[:last]
|
21
|
+
|
22
|
+
# get the smallest of the array items
|
23
|
+
actual_page_size = possible_page_sizes.min
|
24
|
+
|
25
|
+
# return the total_count divided by the page size, rounded up
|
26
|
+
(my_total_count / actual_page_size.to_f).ceil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Types
|
2
|
+
module Inputs
|
3
|
+
class ImageResolution < Base::Filter
|
4
|
+
graphql_name 'ImageResolution'
|
5
|
+
|
6
|
+
description 'Additional attributes needed for Image Resolution'
|
7
|
+
|
8
|
+
argument :width, Integer, nil, required: true
|
9
|
+
argument :height, Integer, nil, required: true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,7 +2,9 @@ module Types::Objects::Base
|
|
2
2
|
class AttachmentType < Types::BaseObject
|
3
3
|
field :id, Int, nil, null: false
|
4
4
|
field :filename, String, nil, null: false
|
5
|
-
field :url, String, nil, null: false
|
5
|
+
field :url, String, nil, null: false do
|
6
|
+
argument :resolution, Types::Inputs::ImageResolution, required: false, default_value: nil
|
7
|
+
end
|
6
8
|
field :base64, String, nil, null: false
|
7
9
|
|
8
10
|
def id
|
@@ -21,13 +23,22 @@ module Types::Objects::Base
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def url
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def url(resolution:)
|
27
|
+
resized_image = resize_image(resolution&.width, resolution&.height, object)
|
28
|
+
if resized_image.class.eql?(ActiveStorage::Variant) || resized_image.class.eql?(ActiveStorage::VariantWithRecord)
|
29
|
+
Rails.application.routes.url_helpers.rails_representation_url(resized_image)
|
30
|
+
elsif defined?(resized_image.service_url)
|
31
|
+
resized_image.service_url
|
32
|
+
else
|
33
|
+
resized_image.url
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def resize_image(width, height, attachment)
|
38
|
+
if width.present? && height.present? && (attachment.attached? && attachment.content_type.include?('image'))
|
39
|
+
attachment.variant(resize_to_fill: [width, height])
|
29
40
|
else
|
30
|
-
|
41
|
+
attachment
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
data/cm-graphql.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'cm-graphql'
|
5
|
-
spec.version = '0.0.
|
5
|
+
spec.version = '0.0.7'
|
6
6
|
spec.date = '2022-09-14'
|
7
7
|
spec.summary = 'A gem to setup grapqhl basics like pagination, file upload'
|
8
8
|
spec.description = 'A gem to setup grapqhl basics like pagination, file upload'
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['
|
9
|
+
spec.authors = ['Anbazhagan Palani']
|
10
|
+
spec.email = ['anbu@commutatus.com']
|
11
11
|
spec.homepage = 'https://github.com/commutatus/template-paging-api'
|
12
12
|
spec.license = 'MIT'
|
13
13
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
spec.required_ruby_version = '>= 3.0.0'
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'graphiql-rails', '
|
22
|
-
spec.add_runtime_dependency 'graphql', '
|
23
|
-
spec.add_runtime_dependency 'graphql-rails_logger', '
|
21
|
+
spec.add_runtime_dependency 'graphiql-rails', '>= 1.9'
|
22
|
+
spec.add_runtime_dependency 'graphql', '>= 2.2.5'
|
23
|
+
spec.add_runtime_dependency 'graphql-rails_logger', '>= 1.2.4'
|
24
24
|
spec.add_runtime_dependency 'kaminari', '~> 1.2', '>= 1.2.2'
|
25
25
|
end
|
@@ -8,6 +8,7 @@ module CmGraphql
|
|
8
8
|
def add_graphql
|
9
9
|
generate 'graphql:install'
|
10
10
|
template 'graphql_schema.rb', "app/graphql/#{Rails.application.class.module_parent_name.underscore}_schema.rb"
|
11
|
+
copy_file 'base_connection.rb', 'app/graphql/types/base_connection.rb'
|
11
12
|
gsub_file 'app/controllers/graphql_controller.rb', '# protect_from_forgery with: :null_session', 'protect_from_forgery with: :null_session'
|
12
13
|
end
|
13
14
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Types
|
2
|
+
class BaseConnection < Types::BaseObject
|
3
|
+
# add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
|
4
|
+
include GraphQL::Types::Relay::ConnectionBehaviors
|
5
|
+
|
6
|
+
field :total_count, Integer, "Total # of objects returned from this Plural Query", null: false
|
7
|
+
def total_count
|
8
|
+
object.nodes&.count
|
9
|
+
end
|
10
|
+
|
11
|
+
field :total_page_count, Integer, "Total # of pages, based on total count and pagesize", null: false
|
12
|
+
def total_page_count
|
13
|
+
return 1 unless object.nodes&.count&.positive?
|
14
|
+
# get total count and create array with total count as first item
|
15
|
+
my_total_count = object.nodes&.count
|
16
|
+
possible_page_sizes = [my_total_count]
|
17
|
+
|
18
|
+
# add first and last argument counts to the array if they exist
|
19
|
+
possible_page_sizes.push(object.arguments[:first]) if object.arguments[:first]
|
20
|
+
possible_page_sizes.push(object.arguments[:last]) if object.arguments[:last]
|
21
|
+
|
22
|
+
# get the smallest of the array items
|
23
|
+
actual_page_size = possible_page_sizes.min
|
24
|
+
|
25
|
+
# return the total_count divided by the page size, rounded up
|
26
|
+
(my_total_count / actual_page_size.to_f).ceil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cm-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Aditya Tiwari
|
8
7
|
- Anbazhagan Palani
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
@@ -15,23 +14,20 @@ dependencies:
|
|
15
14
|
name: graphiql-rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- - "
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '1.9'
|
21
20
|
type: :runtime
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- - "
|
24
|
+
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
26
|
version: '1.9'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: graphql
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '2.2'
|
35
31
|
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 2.2.5
|
@@ -39,9 +35,6 @@ dependencies:
|
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- - "~>"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '2.2'
|
45
38
|
- - ">="
|
46
39
|
- !ruby/object:Gem::Version
|
47
40
|
version: 2.2.5
|
@@ -49,9 +42,6 @@ dependencies:
|
|
49
42
|
name: graphql-rails_logger
|
50
43
|
requirement: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.2'
|
55
45
|
- - ">="
|
56
46
|
- !ruby/object:Gem::Version
|
57
47
|
version: 1.2.4
|
@@ -59,9 +49,6 @@ dependencies:
|
|
59
49
|
prerelease: false
|
60
50
|
version_requirements: !ruby/object:Gem::Requirement
|
61
51
|
requirements:
|
62
|
-
- - "~>"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '1.2'
|
65
52
|
- - ">="
|
66
53
|
- !ruby/object:Gem::Version
|
67
54
|
version: 1.2.4
|
@@ -87,12 +74,13 @@ dependencies:
|
|
87
74
|
version: 1.2.2
|
88
75
|
description: A gem to setup grapqhl basics like pagination, file upload
|
89
76
|
email:
|
90
|
-
- taditya.tiwari007@gmail.com
|
91
77
|
- anbu@commutatus.com
|
92
78
|
executables: []
|
93
79
|
extensions: []
|
94
80
|
extra_rdoc_files: []
|
95
81
|
files:
|
82
|
+
- ".github/CODEOWNERS"
|
83
|
+
- ".gitignore"
|
96
84
|
- Gemfile
|
97
85
|
- Gemfile.lock
|
98
86
|
- README.md
|
@@ -100,12 +88,14 @@ files:
|
|
100
88
|
- app/graphql/mutations/authenticated_mutation.rb
|
101
89
|
- app/graphql/mutations/base_mutation.rb
|
102
90
|
- app/graphql/queries/base_query.rb
|
91
|
+
- app/graphql/types/base_connection.rb
|
103
92
|
- app/graphql/types/enums/base/sort_column.rb
|
104
93
|
- app/graphql/types/enums/base/sort_direction.rb
|
105
94
|
- app/graphql/types/inputs/base/attachment.rb
|
106
95
|
- app/graphql/types/inputs/base/filter.rb
|
107
96
|
- app/graphql/types/inputs/base/paging.rb
|
108
97
|
- app/graphql/types/inputs/base/sort.rb
|
98
|
+
- app/graphql/types/inputs/image_resolution.rb
|
109
99
|
- app/graphql/types/objects/base/attachment_type.rb
|
110
100
|
- app/graphql/types/objects/base/paging_type.rb
|
111
101
|
- app/models/concerns/attachable.rb
|
@@ -118,6 +108,7 @@ files:
|
|
118
108
|
- lib/cm-graphql/engine.rb
|
119
109
|
- lib/generators/cm_graphql/add_graphql_generator.rb
|
120
110
|
- lib/generators/cm_graphql/list_api_generator.rb
|
111
|
+
- lib/generators/cm_graphql/templates/base_connection.rb
|
121
112
|
- lib/generators/cm_graphql/templates/graphql_schema.rb
|
122
113
|
- lib/generators/cm_graphql/templates/list_type.rb
|
123
114
|
- lib/generators/cm_graphql/templates/query_type.rb
|
@@ -141,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
132
|
- !ruby/object:Gem::Version
|
142
133
|
version: '0'
|
143
134
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.5.15
|
145
136
|
signing_key:
|
146
137
|
specification_version: 4
|
147
138
|
summary: A gem to setup grapqhl basics like pagination, file upload
|