cm-graphql 0.0.6 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1a6afa908507f31c6c11f19e42e1e34c59963b80fb8d4e4f26f2661199910e3
4
- data.tar.gz: '017878eb571de1b93072801b45f3fdb221013ff42d722b6827e18c12afe2f5f0'
3
+ metadata.gz: 56ea64e15d7c0d65f0b6f21e04ffe418d411bd784ec37903e3a640b0b4ae1ffb
4
+ data.tar.gz: 6c512133b0c2e0468d625c4935343cbfd13582968429d83aace9d69434fbdb6c
5
5
  SHA512:
6
- metadata.gz: 8f340a1be6e20126f347786dd53a68c158972cf76044db36311666506e8d72c775dec5ac737ee110ff76b4ffa38a42ff6c99e92359048c27f043b94e1feedbfb
7
- data.tar.gz: 2fd871043d2cbb44853f2cc2048fa0240ca1550b2c8c4de480d52252f81e061055ee5a4e73ca1405c4cf3ec9734fe183c13dc9a517d92519149d11066fac9705
6
+ metadata.gz: f9d6986119de8ab2a2bcbbf131898ae2603922c831bab6a5dacf944a30bba7e79986efa2ff47b2aaac98d2ccdbe4fddace2b6a209151dcd6d8ff6a7aaef5deab
7
+ data.tar.gz: 2036fa861286d2c055db30e2f2ee3a6e77910a23b06d6d9f9fdb77a8dedf753503060a566d65956bf717ea02bcd19a44093399743d40f83c9204be68b833fecb
@@ -0,0 +1 @@
1
+ * @Mahaveer1141 @anbublacky @mikevic
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/Gemfile.lock CHANGED
@@ -1,68 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-graphql (0.0.6)
5
- graphiql-rails (~> 1.9)
6
- graphql (~> 2.2, >= 2.2.5)
7
- graphql-rails_logger (~> 1.2, >= 1.2.4)
4
+ cm-graphql (0.0.8)
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.3.3)
14
- actionview (= 7.1.3.3)
15
- activesupport (= 7.1.3.3)
13
+ actionpack (8.0.2)
14
+ actionview (= 8.0.2)
15
+ activesupport (= 8.0.2)
16
16
  nokogiri (>= 1.8.5)
17
- racc
18
17
  rack (>= 2.2.4)
19
18
  rack-session (>= 1.0.1)
20
19
  rack-test (>= 0.6.3)
21
20
  rails-dom-testing (~> 2.2)
22
21
  rails-html-sanitizer (~> 1.6)
23
- actionview (7.1.3.3)
24
- activesupport (= 7.1.3.3)
22
+ useragent (~> 0.16)
23
+ actionview (8.0.2)
24
+ activesupport (= 8.0.2)
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.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)
29
+ activemodel (8.0.2)
30
+ activesupport (= 8.0.2)
31
+ activerecord (8.0.2)
32
+ activemodel (= 8.0.2)
33
+ activesupport (= 8.0.2)
34
34
  timeout (>= 0.4.0)
35
- activesupport (7.1.3.3)
35
+ activesupport (8.0.2)
36
36
  base64
37
+ benchmark (>= 0.3)
37
38
  bigdecimal
38
- concurrent-ruby (~> 1.0, >= 1.0.2)
39
+ concurrent-ruby (~> 1.0, >= 1.3.1)
39
40
  connection_pool (>= 2.2.5)
40
41
  drb
41
42
  i18n (>= 1.6, < 2)
43
+ logger (>= 1.4.2)
42
44
  minitest (>= 5.1)
43
- mutex_m
44
- tzinfo (~> 2.0)
45
+ securerandom (>= 0.3)
46
+ tzinfo (~> 2.0, >= 2.0.5)
47
+ uri (>= 0.13.1)
45
48
  base64 (0.2.0)
46
- bigdecimal (3.1.8)
49
+ benchmark (0.4.0)
50
+ bigdecimal (3.1.9)
47
51
  builder (3.3.0)
48
- concurrent-ruby (1.3.1)
49
- connection_pool (2.4.1)
52
+ concurrent-ruby (1.3.5)
53
+ connection_pool (2.5.2)
50
54
  crass (1.0.6)
55
+ date (3.4.1)
51
56
  drb (2.2.1)
52
- erubi (1.12.0)
53
- graphiql-rails (1.10.0)
57
+ erubi (1.13.1)
58
+ fiber-storage (1.0.1)
59
+ graphiql-rails (1.10.4)
54
60
  railties
55
- graphql (2.3.4)
61
+ graphql (2.5.4)
56
62
  base64
57
- graphql-rails_logger (1.2.4)
63
+ fiber-storage
64
+ logger
65
+ graphql-rails_logger (1.2.5)
58
66
  actionpack (> 5.0)
59
67
  activesupport (> 5.0)
60
68
  railties (> 5.0)
61
- rouge (~> 3.0)
62
- i18n (1.14.5)
69
+ rouge (>= 3.0)
70
+ i18n (1.14.7)
63
71
  concurrent-ruby (~> 1.0)
64
- io-console (0.7.2)
65
- irb (1.13.1)
72
+ io-console (0.8.0)
73
+ irb (1.15.2)
74
+ pp (>= 0.6.0)
66
75
  rdoc (>= 4.0.0)
67
76
  reline (>= 0.4.2)
68
77
  kaminari (1.2.2)
@@ -77,52 +86,62 @@ GEM
77
86
  activerecord
78
87
  kaminari-core (= 1.2.2)
79
88
  kaminari-core (1.2.2)
80
- loofah (2.22.0)
89
+ logger (1.7.0)
90
+ loofah (2.24.0)
81
91
  crass (~> 1.0.2)
82
92
  nokogiri (>= 1.12.0)
83
- minitest (5.23.1)
84
- mutex_m (0.2.0)
85
- nokogiri (1.16.5-arm64-darwin)
93
+ mini_portile2 (2.8.8)
94
+ minitest (5.25.5)
95
+ nokogiri (1.18.8)
96
+ mini_portile2 (~> 2.8.2)
86
97
  racc (~> 1.4)
87
- psych (5.1.2)
98
+ nokogiri (1.18.8-arm64-darwin)
99
+ racc (~> 1.4)
100
+ pp (0.6.2)
101
+ prettyprint
102
+ prettyprint (0.2.0)
103
+ psych (5.2.3)
104
+ date
88
105
  stringio
89
- racc (1.8.0)
90
- rack (3.0.11)
91
- rack-session (2.0.0)
106
+ racc (1.8.1)
107
+ rack (3.1.13)
108
+ rack-session (2.1.0)
109
+ base64 (>= 0.1.0)
92
110
  rack (>= 3.0.0)
93
- rack-test (2.1.0)
111
+ rack-test (2.2.0)
94
112
  rack (>= 1.3)
95
- rackup (2.1.0)
113
+ rackup (2.2.1)
96
114
  rack (>= 3)
97
- webrick (~> 1.8)
98
115
  rails-dom-testing (2.2.0)
99
116
  activesupport (>= 5.0.0)
100
117
  minitest
101
118
  nokogiri (>= 1.6)
102
- rails-html-sanitizer (1.6.0)
119
+ rails-html-sanitizer (1.6.2)
103
120
  loofah (~> 2.21)
104
- nokogiri (~> 1.14)
105
- railties (7.1.3.3)
106
- actionpack (= 7.1.3.3)
107
- activesupport (= 7.1.3.3)
108
- irb
121
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
122
+ railties (8.0.2)
123
+ actionpack (= 8.0.2)
124
+ activesupport (= 8.0.2)
125
+ irb (~> 1.13)
109
126
  rackup (>= 1.0.0)
110
127
  rake (>= 12.2)
111
128
  thor (~> 1.0, >= 1.2.2)
112
129
  zeitwerk (~> 2.6)
113
130
  rake (13.2.1)
114
- rdoc (6.7.0)
131
+ rdoc (6.13.1)
115
132
  psych (>= 4.0.0)
116
- reline (0.5.8)
133
+ reline (0.6.1)
117
134
  io-console (~> 0.5)
118
- rouge (3.30.0)
119
- stringio (3.1.0)
120
- thor (1.3.1)
121
- timeout (0.4.1)
135
+ rouge (4.5.1)
136
+ securerandom (0.4.1)
137
+ stringio (3.1.7)
138
+ thor (1.3.2)
139
+ timeout (0.4.3)
122
140
  tzinfo (2.0.6)
123
141
  concurrent-ruby (~> 1.0)
124
- webrick (1.8.1)
125
- zeitwerk (2.6.15)
142
+ uri (1.0.3)
143
+ useragent (0.16.11)
144
+ zeitwerk (2.7.2)
126
145
 
127
146
  PLATFORMS
128
147
  arm64-darwin-20
@@ -133,4 +152,4 @@ DEPENDENCIES
133
152
  cm-graphql!
134
153
 
135
154
  BUNDLED WITH
136
- 2.2.33
155
+ 2.6.8
@@ -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,27 @@
1
+ module Types
2
+ module EnumHelpers
3
+ def self.enum_from_model(model, enum_name, graphql_enum_name: nil)
4
+ enum_values = model.send(enum_name.to_s.pluralize).keys
5
+
6
+ Class.new(Types::BaseEnum) do
7
+ graphql_name(graphql_enum_name || "#{model.name}#{enum_name.to_s.camelize}Enum")
8
+
9
+ enum_values.each do |val|
10
+ value val, description: "#{val.titleize} #{enum_name}"
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.enum_from_array(array, graphql_enum_name)
16
+ enum_values = array.map(&:to_s)
17
+
18
+ Class.new(Types::BaseEnum) do
19
+ graphql_name(graphql_enum_name)
20
+
21
+ enum_values.each do |val|
22
+ value val, description: val.titleize
23
+ end
24
+ end
25
+ end
26
+ end
27
+ 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
- if object.class.eql?(ActiveStorage::Variant)
26
- Rails.application.routes.url_helpers.rails_representation_url(object)
27
- elsif defined?(object.service_url)
28
- object.service_url
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
- object.url
41
+ attachment
31
42
  end
32
43
  end
33
44
 
data/cm-graphql.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'cm-graphql'
5
- spec.version = '0.0.6'
5
+ spec.version = '0.0.8'
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'
@@ -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', '~> 1.9'
22
- spec.add_runtime_dependency 'graphql', '~> 2.2', '>= 2.2.5'
23
- spec.add_runtime_dependency 'graphql-rails_logger', '~> 1.2', '>= 1.2.4'
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
@@ -1,3 +1,5 @@
1
+ require_relative '../../app/models/concerns/paginator'
2
+
1
3
  ActiveSupport.on_load(:active_record) do
2
4
  module ActiveRecord
3
5
  class Base
@@ -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,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
10
  date: 2022-09-14 00:00:00.000000000 Z
@@ -14,23 +13,20 @@ dependencies:
14
13
  name: graphiql-rails
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.9'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '1.9'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: graphql
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.2'
34
30
  - - ">="
35
31
  - !ruby/object:Gem::Version
36
32
  version: 2.2.5
@@ -38,9 +34,6 @@ dependencies:
38
34
  prerelease: false
39
35
  version_requirements: !ruby/object:Gem::Requirement
40
36
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.2'
44
37
  - - ">="
45
38
  - !ruby/object:Gem::Version
46
39
  version: 2.2.5
@@ -48,9 +41,6 @@ dependencies:
48
41
  name: graphql-rails_logger
49
42
  requirement: !ruby/object:Gem::Requirement
50
43
  requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.2'
54
44
  - - ">="
55
45
  - !ruby/object:Gem::Version
56
46
  version: 1.2.4
@@ -58,9 +48,6 @@ dependencies:
58
48
  prerelease: false
59
49
  version_requirements: !ruby/object:Gem::Requirement
60
50
  requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '1.2'
64
51
  - - ">="
65
52
  - !ruby/object:Gem::Version
66
53
  version: 1.2.4
@@ -91,6 +78,8 @@ executables: []
91
78
  extensions: []
92
79
  extra_rdoc_files: []
93
80
  files:
81
+ - ".github/CODEOWNERS"
82
+ - ".gitignore"
94
83
  - Gemfile
95
84
  - Gemfile.lock
96
85
  - README.md
@@ -98,12 +87,15 @@ files:
98
87
  - app/graphql/mutations/authenticated_mutation.rb
99
88
  - app/graphql/mutations/base_mutation.rb
100
89
  - app/graphql/queries/base_query.rb
90
+ - app/graphql/types/base_connection.rb
91
+ - app/graphql/types/enum_helpers.rb
101
92
  - app/graphql/types/enums/base/sort_column.rb
102
93
  - app/graphql/types/enums/base/sort_direction.rb
103
94
  - app/graphql/types/inputs/base/attachment.rb
104
95
  - app/graphql/types/inputs/base/filter.rb
105
96
  - app/graphql/types/inputs/base/paging.rb
106
97
  - app/graphql/types/inputs/base/sort.rb
98
+ - app/graphql/types/inputs/image_resolution.rb
107
99
  - app/graphql/types/objects/base/attachment_type.rb
108
100
  - app/graphql/types/objects/base/paging_type.rb
109
101
  - app/models/concerns/attachable.rb
@@ -116,6 +108,7 @@ files:
116
108
  - lib/cm-graphql/engine.rb
117
109
  - lib/generators/cm_graphql/add_graphql_generator.rb
118
110
  - lib/generators/cm_graphql/list_api_generator.rb
111
+ - lib/generators/cm_graphql/templates/base_connection.rb
119
112
  - lib/generators/cm_graphql/templates/graphql_schema.rb
120
113
  - lib/generators/cm_graphql/templates/list_type.rb
121
114
  - lib/generators/cm_graphql/templates/query_type.rb
@@ -124,7 +117,6 @@ homepage: https://github.com/commutatus/template-paging-api
124
117
  licenses:
125
118
  - MIT
126
119
  metadata: {}
127
- post_install_message:
128
120
  rdoc_options: []
129
121
  require_paths:
130
122
  - lib
@@ -139,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
131
  - !ruby/object:Gem::Version
140
132
  version: '0'
141
133
  requirements: []
142
- rubygems_version: 3.2.3
143
- signing_key:
134
+ rubygems_version: 3.6.8
144
135
  specification_version: 4
145
136
  summary: A gem to setup grapqhl basics like pagination, file upload
146
137
  test_files: []