cm-graphql 0.0.1 → 0.0.2
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/README.md +24 -1
- data/app/exceptions/base_exception.rb +9 -0
- data/app/graphql/mutations/authenticated_mutation.rb +7 -0
- data/app/models/concerns/attachable.rb +63 -0
- data/cm-graphql.gemspec +2 -2
- data/lib/generators/cm_graphql/add_graphql_generator.rb +1 -0
- data/lib/generators/cm_graphql/list_api_generator.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ee97c08c570d7a3e310f363c27e25823f575dde5e7a96225de64270e3fa5ba6
|
4
|
+
data.tar.gz: 2b64f9e0164661408d26bdfb748251dc5062ef8e128b836ce75e9aa398c9ad86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a74441c0f449d31e0834a7a9432915448f1f2f80e4c22e8a24262bf6e601cd20e210c4a5f5e5f722c8f4331e22083638965801da62d5f2879888a619f5ab36b
|
7
|
+
data.tar.gz: 0c690eee1b9a77f260063b141bf5d923558673d8fb6e1c227898b16ad7263dec285d0e692825f2d44e7ed1663784725de5488a4531cd2882f52dc8fa195d7736
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# CmGraphql
|
2
2
|
|
3
3
|
This should help you to install graphql and setup the basics on any new rails application.
|
4
|
+
- Adds Graphql gem and runs the graphql installer
|
5
|
+
- Copies the grapqhl schema template which has the rescue block configured.
|
6
|
+
- Certain files like grapqhl query, input and exceptions are inside the gem, which makes the listing of records easier.
|
4
7
|
|
5
8
|
## Install
|
6
9
|
|
7
10
|
Add the gem to the Gemfile
|
8
11
|
|
9
12
|
```
|
10
|
-
gem 'cm-
|
13
|
+
gem 'cm-graphql'
|
11
14
|
```
|
12
15
|
|
13
16
|
## Setup
|
@@ -27,6 +30,26 @@ Another generator to help you get started with a basic list endpoint is
|
|
27
30
|
```
|
28
31
|
rails g cm_graphql:list_api model_name
|
29
32
|
rails g cm_graphql:list_api course
|
33
|
+
|
34
|
+
|
35
|
+
# Sample grapqhl request
|
36
|
+
|
37
|
+
query {
|
38
|
+
courses(paging: {
|
39
|
+
pageNo: 1
|
40
|
+
perPage: 100
|
41
|
+
}) {
|
42
|
+
paging {
|
43
|
+
currentPage
|
44
|
+
totalPages
|
45
|
+
totalCount
|
46
|
+
}
|
47
|
+
data {
|
48
|
+
id
|
49
|
+
name
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
30
53
|
```
|
31
54
|
|
32
55
|
This will add the necessary files to the application.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Attachable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
end
|
6
|
+
|
7
|
+
def save_with_attachments
|
8
|
+
save!
|
9
|
+
save_attachment
|
10
|
+
end
|
11
|
+
|
12
|
+
def update!(args)
|
13
|
+
add_accessors_for_attachment_types
|
14
|
+
super
|
15
|
+
save_attachment
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(args)
|
19
|
+
add_accessors_for_attachment_types
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_attachment
|
24
|
+
self.class.attachment_types.each do |attachment_type|
|
25
|
+
next if send("#{attachment_type}_file").blank?
|
26
|
+
|
27
|
+
arr = []
|
28
|
+
if send("#{attachment_type}_file").class.eql?(Array)
|
29
|
+
arr = send("#{attachment_type}_file")
|
30
|
+
else
|
31
|
+
arr << send("#{attachment_type}_file")
|
32
|
+
end
|
33
|
+
arr.each do |x|
|
34
|
+
regexp = %r{\Adata:([-\w]+\/[-\w\+\.]+)?;base64,(.*)}m
|
35
|
+
data_uri_parts = x[:content].match(regexp) || []
|
36
|
+
decoded_data = Base64.decode64(data_uri_parts[2])
|
37
|
+
filename = x[:filename]
|
38
|
+
filepath = "#{Rails.root}/tmp/#{filename}"
|
39
|
+
File.open(filepath, 'wb') do |f|
|
40
|
+
f.write(decoded_data)
|
41
|
+
end
|
42
|
+
send(attachment_type.to_s).attach(io: File.open(filepath), filename: filename, content_type: data_uri_parts[1])
|
43
|
+
File.delete(filepath)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def attached_url(attachment_type)
|
49
|
+
if send(attachment_type.to_s).attached? && send(attachment_type.to_s).class == ActiveStorage::Attached::One
|
50
|
+
Rails.application.routes.url_helpers.rails_blob_url(send(attachment_type.to_s))
|
51
|
+
elsif send(attachment_type.to_s).attached? && send(attachment_type.to_s).class == ActiveStorage::Attached::Many
|
52
|
+
send(attachment_type.to_s)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def add_accessors_for_attachment_types
|
59
|
+
self.class.attachment_types.each do |attachment_type|
|
60
|
+
singleton_class.class_eval { attr_accessor "#{attachment_type}_file" }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/cm-graphql.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'cm-graphql'
|
3
|
-
spec.version = '0.0.
|
3
|
+
spec.version = '0.0.2'
|
4
4
|
spec.date = '2022-09-14'
|
5
5
|
spec.summary = "A gem to setup grapqhl basics like pagination, file upload"
|
6
6
|
spec.description = "A gem to setup grapqhl basics like pagination, file upload"
|
@@ -22,4 +22,4 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency 'graphql-rails_logger', '~> 1.2.3'
|
23
23
|
spec.add_runtime_dependency 'graphiql-rails', '~> 1.8.0'
|
24
24
|
spec.add_runtime_dependency 'kaminari', '~> 1.2.2'
|
25
|
-
end
|
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
|
+
gsub_file 'app/controllers/graphql_controller.rb', '# protect_from_forgery with: :null_session', 'protect_from_forgery with: :null_session'
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -10,6 +10,8 @@ module CmGraphql
|
|
10
10
|
template "list_type.rb", "app/graphql/types/objects/#{@model_name}_list_type.rb"
|
11
11
|
template "record_type.rb", "app/graphql/types/objects/#{@model_name}_type.rb"
|
12
12
|
template "query_type.rb", "app/graphql/queries/#{@model_name}.rb"
|
13
|
+
gsub_file 'app/graphql/types/query_type.rb', 'include GraphQL::Types::Relay::HasNodesField', "include GraphQL::Types::Relay::HasNodesField
|
14
|
+
field :#{@model_name.pluralize}, resolver: Queries::#{@model_name.classify}"
|
13
15
|
end
|
14
16
|
end
|
15
17
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anbazhagan Palani
|
@@ -89,6 +89,8 @@ files:
|
|
89
89
|
- Gemfile
|
90
90
|
- Gemfile.lock
|
91
91
|
- README.md
|
92
|
+
- app/exceptions/base_exception.rb
|
93
|
+
- app/graphql/mutations/authenticated_mutation.rb
|
92
94
|
- app/graphql/mutations/base_mutation.rb
|
93
95
|
- app/graphql/queries/base_query.rb
|
94
96
|
- app/graphql/types/enums/base/sort_column.rb
|
@@ -99,6 +101,7 @@ files:
|
|
99
101
|
- app/graphql/types/inputs/base/sort.rb
|
100
102
|
- app/graphql/types/objects/base/attachment_type.rb
|
101
103
|
- app/graphql/types/objects/base/paging_type.rb
|
104
|
+
- app/models/concerns/attachable.rb
|
102
105
|
- app/models/concerns/paginator.rb
|
103
106
|
- app/models/filtered_list.rb
|
104
107
|
- cm-graphql.gemspec
|