cm-graphql 0.0.1 → 0.0.3

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: 88cbec80aeb7ce0649e72b28495436a8bfd2372d564f5b593056106fb10bca8c
4
- data.tar.gz: 90e971f56d3b41f432418bfce7652ba76c7b99bf797ae1cfef2d3a4b0aa0e7cf
3
+ metadata.gz: 7bfab7b28788ebbc885ae022e0968183caaae84a666dc3368dd9139b671188ce
4
+ data.tar.gz: b392401f10dd7227b968d35000df97d98def50880cced1fe3922742908b4c70b
5
5
  SHA512:
6
- metadata.gz: 237af1356eb71878cb5d0cbc21502a3ea95828286da8b8178aaf6be061ccd12e818d4b9545d3e5e92f8a0bc620bd2849afea13bd6f9da89919a5c37058508bad
7
- data.tar.gz: 827e8261f871b22adc627375f39b06bedc8ff7e434330dbf9d8b1919179d26ad8f8c989f8d0106f82793af0595f40864c71393c086efc74d180f1340892e04f7
6
+ metadata.gz: b6bdaa32b7d99300a3d78a4397024eb7d34cea339ad0dd3e0b27895d718e99d8327c6592578f9cbb971d1705f7f484a10d3773220db8a998fd8e0e600b30a2fb
7
+ data.tar.gz: f5a5aeb6e08e3272a7ab2a3534c089e4d2ed3f2c3e352391ff925c2d61449bb63ed9bec646af6743a5b8e99ffc6d4210721fccd5e8529401dfd8ed3ebb38ba56
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-graphql (0.0.1)
4
+ cm-graphql (0.0.3)
5
5
  graphiql-rails (~> 1.8.0)
6
6
  graphql (~> 1.13.1)
7
7
  graphql-errors (~> 0.4.0)
@@ -12,45 +12,45 @@ GEM
12
12
  remote: https://rubygems.org/
13
13
  remote: https://rails-assets.org/
14
14
  specs:
15
- actionpack (7.0.3.1)
16
- actionview (= 7.0.3.1)
17
- activesupport (= 7.0.3.1)
18
- rack (~> 2.0, >= 2.2.0)
15
+ actionpack (7.0.5.1)
16
+ actionview (= 7.0.5.1)
17
+ activesupport (= 7.0.5.1)
18
+ rack (~> 2.0, >= 2.2.4)
19
19
  rack-test (>= 0.6.3)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
22
- actionview (7.0.3.1)
23
- activesupport (= 7.0.3.1)
22
+ actionview (7.0.5.1)
23
+ activesupport (= 7.0.5.1)
24
24
  builder (~> 3.1)
25
25
  erubi (~> 1.4)
26
26
  rails-dom-testing (~> 2.0)
27
27
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
28
- activemodel (7.0.3.1)
29
- activesupport (= 7.0.3.1)
30
- activerecord (7.0.3.1)
31
- activemodel (= 7.0.3.1)
32
- activesupport (= 7.0.3.1)
33
- activesupport (7.0.3.1)
28
+ activemodel (7.0.5.1)
29
+ activesupport (= 7.0.5.1)
30
+ activerecord (7.0.5.1)
31
+ activemodel (= 7.0.5.1)
32
+ activesupport (= 7.0.5.1)
33
+ activesupport (7.0.5.1)
34
34
  concurrent-ruby (~> 1.0, >= 1.0.2)
35
35
  i18n (>= 1.6, < 2)
36
36
  minitest (>= 5.1)
37
37
  tzinfo (~> 2.0)
38
38
  builder (3.2.4)
39
- concurrent-ruby (1.1.10)
39
+ concurrent-ruby (1.2.2)
40
40
  crass (1.0.6)
41
- erubi (1.11.0)
41
+ erubi (1.12.0)
42
42
  graphiql-rails (1.8.0)
43
43
  railties
44
44
  sprockets-rails
45
- graphql (1.13.15)
45
+ graphql (1.13.19)
46
46
  graphql-errors (0.4.0)
47
47
  graphql (>= 1.6.0, < 2)
48
- graphql-rails_logger (1.2.3)
48
+ graphql-rails_logger (1.2.4)
49
49
  actionpack (> 5.0)
50
50
  activesupport (> 5.0)
51
51
  railties (> 5.0)
52
52
  rouge (~> 3.0)
53
- i18n (1.12.0)
53
+ i18n (1.14.1)
54
54
  concurrent-ruby (~> 1.0)
55
55
  kaminari (1.2.2)
56
56
  activesupport (>= 4.1.0)
@@ -64,44 +64,43 @@ GEM
64
64
  activerecord
65
65
  kaminari-core (= 1.2.2)
66
66
  kaminari-core (1.2.2)
67
- loofah (2.18.0)
67
+ loofah (2.21.3)
68
68
  crass (~> 1.0.2)
69
- nokogiri (>= 1.5.9)
69
+ nokogiri (>= 1.12.0)
70
70
  method_source (1.0.0)
71
- mini_portile2 (2.8.0)
72
- minitest (5.16.2)
73
- nokogiri (1.13.8)
74
- mini_portile2 (~> 2.8.0)
71
+ minitest (5.18.1)
72
+ nokogiri (1.15.2-arm64-darwin)
75
73
  racc (~> 1.4)
76
- racc (1.6.0)
77
- rack (2.2.4)
78
- rack-test (2.0.2)
74
+ racc (1.7.1)
75
+ rack (2.2.7)
76
+ rack-test (2.1.0)
79
77
  rack (>= 1.3)
80
78
  rails-dom-testing (2.0.3)
81
79
  activesupport (>= 4.2.0)
82
80
  nokogiri (>= 1.6)
83
- rails-html-sanitizer (1.4.3)
84
- loofah (~> 2.3)
85
- railties (7.0.3.1)
86
- actionpack (= 7.0.3.1)
87
- activesupport (= 7.0.3.1)
81
+ rails-html-sanitizer (1.6.0)
82
+ loofah (~> 2.21)
83
+ nokogiri (~> 1.14)
84
+ railties (7.0.5.1)
85
+ actionpack (= 7.0.5.1)
86
+ activesupport (= 7.0.5.1)
88
87
  method_source
89
88
  rake (>= 12.2)
90
89
  thor (~> 1.0)
91
90
  zeitwerk (~> 2.5)
92
91
  rake (13.0.6)
93
92
  rouge (3.30.0)
94
- sprockets (4.1.1)
93
+ sprockets (4.2.0)
95
94
  concurrent-ruby (~> 1.0)
96
- rack (> 1, < 3)
95
+ rack (>= 2.2.4, < 4)
97
96
  sprockets-rails (3.4.2)
98
97
  actionpack (>= 5.2)
99
98
  activesupport (>= 5.2)
100
99
  sprockets (>= 3.0.0)
101
- thor (1.2.1)
102
- tzinfo (2.0.5)
100
+ thor (1.2.2)
101
+ tzinfo (2.0.6)
103
102
  concurrent-ruby (~> 1.0)
104
- zeitwerk (2.6.0)
103
+ zeitwerk (2.6.8)
105
104
 
106
105
  PLATFORMS
107
106
  arm64-darwin-20
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-admin', git: 'https://github.com/commutatus/template-paging-api.git', branch: 'main'
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,9 @@
1
+ class BaseException < StandardError
2
+ def initialize(message = nil)
3
+ @message = message
4
+ end
5
+
6
+ def message
7
+ @message || 'Something went wrong!'
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Mutations
2
+ class AuthenticatedMutation < BaseMutation
3
+ def self.authorized?(object, context)
4
+ context[:current_user].present?
5
+ end
6
+ end
7
+ end
@@ -23,8 +23,10 @@ module Types::Objects::Base
23
23
  def url
24
24
  if object.class.eql?(ActiveStorage::Variant)
25
25
  Rails.application.routes.url_helpers.rails_representation_url(object)
26
- else
26
+ elsif defined?(object.service_url)
27
27
  object.service_url
28
+ else
29
+ object.url
28
30
  end
29
31
  end
30
32
  end
@@ -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.1'
3
+ spec.version = '0.0.3'
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.1
4
+ version: 0.0.3
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