cm-graphql 0.0.15 → 0.0.17
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/Gemfile.lock +1 -1
- data/app/graphql/cm_graphql/types/objects/base/image_variants_type.rb +24 -0
- data/app/graphql/mutations/authenticated_mutation.rb +3 -1
- data/app/graphql/queries/authenticated_query.rb +9 -0
- data/app/graphql/types/objects/base/attachment_type.rb +8 -0
- data/app/services/cm_graphql/attachment_variants_service.rb +33 -0
- data/cm-graphql.gemspec +2 -2
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26b3848e56eff643c974b44dda066ecae2f75c0aa9c5d0f7808fac663b5c8f99
|
|
4
|
+
data.tar.gz: c7c63fefc2d2cb9f2d6fac6be972599e812a2ddba2fd7c24de76bbcc1d212f64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77b290f0898228dc5222e929a59ae26c23178cd559edbcd8cbb6b9886e427a3b30aea19ca8da2824066ca0830348aaeaedd122084c2bda1c664a0264cb225c22
|
|
7
|
+
data.tar.gz: 2755211973020ca7d323afc72f824c2e91be5c09ab4e0edabd3ce980232f0f09fc39d16f992b8c11db2dbe24259e4c684758ade3454420f20462e9d83aafba5b
|
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.17'
|
|
6
|
+
spec.date = '2026-09-30'
|
|
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.17
|
|
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-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: graphiql-rails
|
|
@@ -87,8 +87,10 @@ 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
|
|
93
|
+
- app/graphql/queries/authenticated_query.rb
|
|
92
94
|
- app/graphql/queries/base_query.rb
|
|
93
95
|
- app/graphql/types/base_connection.rb
|
|
94
96
|
- app/graphql/types/enum_helpers.rb
|
|
@@ -106,6 +108,7 @@ files:
|
|
|
106
108
|
- app/models/concerns/attachable.rb
|
|
107
109
|
- app/models/concerns/paginator.rb
|
|
108
110
|
- app/models/filtered_list.rb
|
|
111
|
+
- app/services/cm_graphql/attachment_variants_service.rb
|
|
109
112
|
- app/services/recaptcha_verifier.rb
|
|
110
113
|
- cm-graphql.gemspec
|
|
111
114
|
- config/initializers/active_record_extension.rb
|
|
@@ -123,7 +126,7 @@ homepage: https://github.com/commutatus/cm-graphql
|
|
|
123
126
|
licenses:
|
|
124
127
|
- MIT
|
|
125
128
|
metadata: {}
|
|
126
|
-
post_install_message:
|
|
129
|
+
post_install_message:
|
|
127
130
|
rdoc_options: []
|
|
128
131
|
require_paths:
|
|
129
132
|
- lib
|
|
@@ -138,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
141
|
- !ruby/object:Gem::Version
|
|
139
142
|
version: '0'
|
|
140
143
|
requirements: []
|
|
141
|
-
rubygems_version: 3.
|
|
142
|
-
signing_key:
|
|
144
|
+
rubygems_version: 3.0.3.1
|
|
145
|
+
signing_key:
|
|
143
146
|
specification_version: 4
|
|
144
147
|
summary: A gem to setup grapqhl basics like pagination, file upload
|
|
145
148
|
test_files: []
|