cm-graphql 0.0.6 → 0.0.7

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: d1a6afa908507f31c6c11f19e42e1e34c59963b80fb8d4e4f26f2661199910e3
4
- data.tar.gz: '017878eb571de1b93072801b45f3fdb221013ff42d722b6827e18c12afe2f5f0'
3
+ metadata.gz: bfe03ea1105356f62c221657ccf7e1ac08f138cc537a1e28bf70f9ad1aa0e0b7
4
+ data.tar.gz: 8275b35c3ba06d16d1be8a32ea6fd0e528c9a6db7c63793d84f2d1e65d62a734
5
5
  SHA512:
6
- metadata.gz: 8f340a1be6e20126f347786dd53a68c158972cf76044db36311666506e8d72c775dec5ac737ee110ff76b4ffa38a42ff6c99e92359048c27f043b94e1feedbfb
7
- data.tar.gz: 2fd871043d2cbb44853f2cc2048fa0240ca1550b2c8c4de480d52252f81e061055ee5a4e73ca1405c4cf3ec9734fe183c13dc9a517d92519149d11066fac9705
6
+ metadata.gz: 742fa1b707f8fd4e726879779293563da46f8c901f64987fd0897d0ccb6aafcf60a9fb010aa7e58d109da244584bbdc5074ac2d8ef142f6bfdc5c5727b3989da
7
+ data.tar.gz: 7ee1c3308c49eb9f5b14ce47c2b2d710160c8087b2bc645326ffb3e3a6b355e68614ca7856879659a14b546225dc19730dd13f22edfd311f0314b1d1f05b4811
@@ -0,0 +1 @@
1
+ * @Mahaveer1141 @anbublacky @mikevic
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/Gemfile.lock CHANGED
@@ -2,9 +2,9 @@ PATH
2
2
  remote: .
3
3
  specs:
4
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)
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
@@ -45,24 +45,26 @@ GEM
45
45
  base64 (0.2.0)
46
46
  bigdecimal (3.1.8)
47
47
  builder (3.3.0)
48
- concurrent-ruby (1.3.1)
48
+ concurrent-ruby (1.3.4)
49
49
  connection_pool (2.4.1)
50
50
  crass (1.0.6)
51
51
  drb (2.2.1)
52
- erubi (1.12.0)
53
- graphiql-rails (1.10.0)
52
+ erubi (1.13.0)
53
+ fiber-storage (1.0.0)
54
+ graphiql-rails (1.10.1)
54
55
  railties
55
- graphql (2.3.4)
56
+ graphql (2.3.17)
56
57
  base64
58
+ fiber-storage
57
59
  graphql-rails_logger (1.2.4)
58
60
  actionpack (> 5.0)
59
61
  activesupport (> 5.0)
60
62
  railties (> 5.0)
61
63
  rouge (~> 3.0)
62
- i18n (1.14.5)
64
+ i18n (1.14.6)
63
65
  concurrent-ruby (~> 1.0)
64
66
  io-console (0.7.2)
65
- irb (1.13.1)
67
+ irb (1.14.1)
66
68
  rdoc (>= 4.0.0)
67
69
  reline (>= 0.4.2)
68
70
  kaminari (1.2.2)
@@ -80,14 +82,18 @@ GEM
80
82
  loofah (2.22.0)
81
83
  crass (~> 1.0.2)
82
84
  nokogiri (>= 1.12.0)
83
- minitest (5.23.1)
85
+ mini_portile2 (2.8.7)
86
+ minitest (5.25.1)
84
87
  mutex_m (0.2.0)
85
- nokogiri (1.16.5-arm64-darwin)
88
+ nokogiri (1.16.7)
89
+ mini_portile2 (~> 2.8.2)
90
+ racc (~> 1.4)
91
+ nokogiri (1.16.7-arm64-darwin)
86
92
  racc (~> 1.4)
87
93
  psych (5.1.2)
88
94
  stringio
89
- racc (1.8.0)
90
- rack (3.0.11)
95
+ racc (1.8.1)
96
+ rack (3.1.7)
91
97
  rack-session (2.0.0)
92
98
  rack (>= 3.0.0)
93
99
  rack-test (2.1.0)
@@ -113,16 +119,16 @@ GEM
113
119
  rake (13.2.1)
114
120
  rdoc (6.7.0)
115
121
  psych (>= 4.0.0)
116
- reline (0.5.8)
122
+ reline (0.5.10)
117
123
  io-console (~> 0.5)
118
124
  rouge (3.30.0)
119
- stringio (3.1.0)
120
- thor (1.3.1)
125
+ stringio (3.1.1)
126
+ thor (1.3.2)
121
127
  timeout (0.4.1)
122
128
  tzinfo (2.0.6)
123
129
  concurrent-ruby (~> 1.0)
124
- webrick (1.8.1)
125
- zeitwerk (2.6.15)
130
+ webrick (1.8.2)
131
+ zeitwerk (2.6.18)
126
132
 
127
133
  PLATFORMS
128
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
- 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.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'
@@ -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,7 +1,7 @@
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani
@@ -14,23 +14,20 @@ dependencies:
14
14
  name: graphiql-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: graphql
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.2'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
33
  version: 2.2.5
@@ -38,9 +35,6 @@ dependencies:
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.2'
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
40
  version: 2.2.5
@@ -48,9 +42,6 @@ dependencies:
48
42
  name: graphql-rails_logger
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.2'
54
45
  - - ">="
55
46
  - !ruby/object:Gem::Version
56
47
  version: 1.2.4
@@ -58,9 +49,6 @@ dependencies:
58
49
  prerelease: false
59
50
  version_requirements: !ruby/object:Gem::Requirement
60
51
  requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '1.2'
64
52
  - - ">="
65
53
  - !ruby/object:Gem::Version
66
54
  version: 1.2.4
@@ -91,6 +79,8 @@ executables: []
91
79
  extensions: []
92
80
  extra_rdoc_files: []
93
81
  files:
82
+ - ".github/CODEOWNERS"
83
+ - ".gitignore"
94
84
  - Gemfile
95
85
  - Gemfile.lock
96
86
  - README.md
@@ -98,12 +88,14 @@ files:
98
88
  - app/graphql/mutations/authenticated_mutation.rb
99
89
  - app/graphql/mutations/base_mutation.rb
100
90
  - app/graphql/queries/base_query.rb
91
+ - app/graphql/types/base_connection.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
@@ -139,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
132
  - !ruby/object:Gem::Version
140
133
  version: '0'
141
134
  requirements: []
142
- rubygems_version: 3.2.3
135
+ rubygems_version: 3.5.15
143
136
  signing_key:
144
137
  specification_version: 4
145
138
  summary: A gem to setup grapqhl basics like pagination, file upload