cm-graphql 0.0.15 → 0.0.16
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e208a4149a2f430397eb52c9b1607eff36daa49855fea35928d8f58a6a023469
|
|
4
|
+
data.tar.gz: c9577f78b6605eab7cd235dcf416077b760b68a1804d7c27e87f7dfa762956f8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3a3846a68d9bc237cdba5bc4ed80f5183cf2347dedc69f62d685650dd60022871040f93fb007a143055fe01a6aed19df7b73cb64b68f85b3dd9970ea4f3332a
|
|
7
|
+
data.tar.gz: 5709fd50e1e93cc71beb6b223fc2af15cfee22f05a7567a505bc47bc385402ce64904afa65fd28f54aa5a9a0551e3b5d0a98cb5d947e7c2d56f3acbaaa76b508
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CmGraphql
|
|
4
|
+
module Types
|
|
5
|
+
module Objects
|
|
6
|
+
module Base
|
|
7
|
+
class ImageVariantsType < ::Types::BaseObject
|
|
8
|
+
description 'Named image variant URLs for an attached image.'
|
|
9
|
+
|
|
10
|
+
CmGraphql::AttachmentVariantsService::DEFAULT_VARIANTS.each_key do |variant_name|
|
|
11
|
+
field_name = variant_name.downcase
|
|
12
|
+
|
|
13
|
+
field field_name, String, null: true,
|
|
14
|
+
description: "#{variant_name} image variant URL."
|
|
15
|
+
|
|
16
|
+
define_method(field_name) do
|
|
17
|
+
CmGraphql::AttachmentVariantsService.url_for(object, variant_name)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -8,6 +8,8 @@ module Types::Objects::Base
|
|
|
8
8
|
field :base64, String, nil, null: false
|
|
9
9
|
field :byte_size, Int, nil, null: false
|
|
10
10
|
field :file_size, String, nil, null: false
|
|
11
|
+
field :variants, CmGraphql::Types::Objects::Base::ImageVariantsType, null: true,
|
|
12
|
+
description: 'Named image variant URLs.'
|
|
11
13
|
|
|
12
14
|
def id
|
|
13
15
|
if object.class.eql?(ActiveStorage::Variant)
|
|
@@ -66,5 +68,11 @@ module Types::Objects::Base
|
|
|
66
68
|
|
|
67
69
|
ActiveSupport::NumberHelper.number_to_human_size(byte_size)
|
|
68
70
|
end
|
|
71
|
+
|
|
72
|
+
def variants
|
|
73
|
+
return nil if object.is_a?(ActiveStorage::Variant) || object.is_a?(ActiveStorage::VariantWithRecord)
|
|
74
|
+
|
|
75
|
+
CmGraphql::AttachmentVariantsService.image?(object) ? object : nil
|
|
76
|
+
end
|
|
69
77
|
end
|
|
70
78
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CmGraphql
|
|
4
|
+
class AttachmentVariantsService
|
|
5
|
+
DEFAULT_VARIANTS = {
|
|
6
|
+
'AVATAR_96' => { resize_to_fill: [96, 96] },
|
|
7
|
+
'AVATAR_256' => { resize_to_fill: [256, 256] },
|
|
8
|
+
'GALLERY_512' => { resize_to_fill: [512, 512] },
|
|
9
|
+
'FULL_1080' => { resize_to_limit: [1080, 1080] }
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
def self.image?(attachment)
|
|
13
|
+
return false if attachment.blank?
|
|
14
|
+
return false if attachment.respond_to?(:attached?) && !attachment.attached?
|
|
15
|
+
|
|
16
|
+
content_type = if attachment.respond_to?(:content_type)
|
|
17
|
+
attachment.content_type
|
|
18
|
+
elsif attachment.respond_to?(:blob)
|
|
19
|
+
attachment.blob.content_type
|
|
20
|
+
end
|
|
21
|
+
content_type.to_s.start_with?('image/')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.url_for(attachment, variant_name)
|
|
25
|
+
transformations = DEFAULT_VARIANTS[variant_name.to_s]
|
|
26
|
+
return nil if transformations.blank?
|
|
27
|
+
|
|
28
|
+
Rails.application.routes.url_helpers.rails_representation_url(
|
|
29
|
+
attachment.variant(transformations)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/cm-graphql.gemspec
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'cm-graphql'
|
|
5
|
-
spec.version = '0.0.
|
|
6
|
-
spec.date = '
|
|
5
|
+
spec.version = '0.0.16'
|
|
6
|
+
spec.date = '2026-09-02'
|
|
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
9
|
spec.authors = ['Anbazhagan Palani']
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anbazhagan Palani
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-09-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: graphiql-rails
|
|
@@ -87,6 +87,7 @@ files:
|
|
|
87
87
|
- app/exceptions/base_exception.rb
|
|
88
88
|
- app/exceptions/recaptcha_verification_failed.rb
|
|
89
89
|
- app/graphql/cm_graphql/extensions/recaptcha_extension.rb
|
|
90
|
+
- app/graphql/cm_graphql/types/objects/base/image_variants_type.rb
|
|
90
91
|
- app/graphql/mutations/authenticated_mutation.rb
|
|
91
92
|
- app/graphql/mutations/base_mutation.rb
|
|
92
93
|
- app/graphql/queries/base_query.rb
|
|
@@ -106,6 +107,7 @@ files:
|
|
|
106
107
|
- app/models/concerns/attachable.rb
|
|
107
108
|
- app/models/concerns/paginator.rb
|
|
108
109
|
- app/models/filtered_list.rb
|
|
110
|
+
- app/services/cm_graphql/attachment_variants_service.rb
|
|
109
111
|
- app/services/recaptcha_verifier.rb
|
|
110
112
|
- cm-graphql.gemspec
|
|
111
113
|
- config/initializers/active_record_extension.rb
|
|
@@ -123,7 +125,7 @@ homepage: https://github.com/commutatus/cm-graphql
|
|
|
123
125
|
licenses:
|
|
124
126
|
- MIT
|
|
125
127
|
metadata: {}
|
|
126
|
-
post_install_message:
|
|
128
|
+
post_install_message:
|
|
127
129
|
rdoc_options: []
|
|
128
130
|
require_paths:
|
|
129
131
|
- lib
|
|
@@ -138,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
140
|
- !ruby/object:Gem::Version
|
|
139
141
|
version: '0'
|
|
140
142
|
requirements: []
|
|
141
|
-
rubygems_version: 3.
|
|
142
|
-
signing_key:
|
|
143
|
+
rubygems_version: 3.0.3.1
|
|
144
|
+
signing_key:
|
|
143
145
|
specification_version: 4
|
|
144
146
|
summary: A gem to setup grapqhl basics like pagination, file upload
|
|
145
147
|
test_files: []
|