cm-graphql 0.0.10 → 0.0.11

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: b6c2f7040bfb9a66bf445a9b39ec6c26f5f40f2a8a6ced52d058035b81c96d3e
4
- data.tar.gz: 56483111c895cc058a15a5d8eff804b1125331f684dec4cecd654d57ef633426
3
+ metadata.gz: 804c41716d68195171fa39944aec667186842a7bd72f0fd0e194914a4591a1a8
4
+ data.tar.gz: 78de5caf228b55e1ac7200d6c50070f2de9973571812e4e97675591a551717a3
5
5
  SHA512:
6
- metadata.gz: 35443f4fcd9d6b181c376bbc72f5123faa398e20509baacc49e9463bccfbffd51793f8c7ba6705eae796d2ffee68d4720228091677525e978d69f9b55f5b56d4
7
- data.tar.gz: 7ff807866e4ec814cbf8865dbf2a60ced6b1cca43038564acded2df32afa2387246397678440dab201cc8261d070603be446c468e3c42f229ce6067c6dce687b
6
+ metadata.gz: f38693d738dd0c880bcd6c526ed04d83976833f66e57a9a30299fb869c4fd702bdad78e5a8d445b9ba64580c64226c57525b6f34afa834435d8f4970dc0703da
7
+ data.tar.gz: fc3df7c9122c14b27acef4222ba552b846dc8c5d87d9e9360fd317b3f07addb3531f055b52860e51a8524ea5ad0980ba7028f910d4e7a46339df4411aa6a011b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-graphql (0.0.9)
4
+ cm-graphql (0.0.10)
5
5
  graphiql-rails (>= 1.9)
6
6
  graphql (>= 2.2.5)
7
7
  graphql-rails_logger (>= 1.2.4)
@@ -1,27 +1,34 @@
1
1
  module Types
2
2
  module EnumHelpers
3
3
  def self.enum_from_model(model, enum_name, graphql_enum_name: nil)
4
- enum_values = model.send(enum_name.to_s.pluralize).keys
4
+ graphql_class_name = graphql_enum_name || "#{model.name}#{enum_name.to_s.camelize}Enum"
5
+
6
+ existing_enum = Types::GraphqlTypeUtils.get_or_check_existing_constant(graphql_class_name)
7
+ return existing_enum if existing_enum
5
8
 
6
- Class.new(Types::BaseEnum) do
7
- graphql_name(graphql_enum_name || "#{model.name}#{enum_name.to_s.camelize}Enum")
9
+ enum_values = model.send(enum_name.to_s.pluralize).keys
10
+ Object.const_set(graphql_class_name, Class.new(Types::BaseEnum) do
11
+ graphql_name(graphql_class_name)
8
12
 
9
13
  enum_values.each do |val|
10
14
  value val, description: "#{val.titleize} #{enum_name}"
11
15
  end
12
- end
16
+ end)
13
17
  end
14
18
 
15
19
  def self.enum_from_array(array, graphql_enum_name)
16
20
  enum_values = array.map(&:to_s)
17
21
 
18
- Class.new(Types::BaseEnum) do
22
+ existing_enum = Types::GraphqlTypeUtils.get_or_check_existing_constant(graphql_enum_name)
23
+ return existing_enum if existing_enum
24
+
25
+ Object.const_set(graphql_enum_name, Class.new(Types::BaseEnum) do
19
26
  graphql_name(graphql_enum_name)
20
27
 
21
28
  enum_values.each do |val|
22
29
  value val, description: val.titleize
23
30
  end
24
- end
31
+ end)
25
32
  end
26
33
  end
27
34
  end
@@ -0,0 +1,7 @@
1
+ module Types
2
+ module GraphqlTypeUtils
3
+ def self.get_or_check_existing_constant(graphql_class_name)
4
+ const_get(graphql_class_name) if const_defined?(graphql_class_name)
5
+ end
6
+ end
7
+ end
@@ -1,8 +1,13 @@
1
1
  module Types
2
2
  module PagingTypeHelper
3
3
  def self.paging_type_for_model(model:, record_data_type: nil, graphql_type_name: nil)
4
- Class.new(Types::BaseObject) do
5
- graphql_name(graphql_type_name.presence || "#{model}PagingType")
4
+ graphql_class_name = graphql_type_name.presence || "#{model}PagingType"
5
+
6
+ existing_paging_type = Types::GraphqlTypeUtils.get_or_check_existing_constant(graphql_class_name)
7
+ return existing_paging_type if existing_paging_type
8
+
9
+ Object.const_set(graphql_class_name, Class.new(Types::BaseObject) do
10
+ graphql_name(graphql_class_name)
6
11
 
7
12
  model_data_type = if record_data_type.present?
8
13
  record_data_type.to_s.constantize
@@ -12,7 +17,7 @@ module Types
12
17
 
13
18
  field :paging, Types::Objects::Base::PagingType, null: true
14
19
  field :data, [model_data_type], null: false
15
- end
20
+ end)
16
21
  end
17
22
  end
18
23
  end
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.10'
5
+ spec.version = '0.0.11'
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'
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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani
@@ -91,6 +91,7 @@ files:
91
91
  - app/graphql/types/enum_helpers.rb
92
92
  - app/graphql/types/enums/base/sort_column.rb
93
93
  - app/graphql/types/enums/base/sort_direction.rb
94
+ - app/graphql/types/graphql_type_utils.rb
94
95
  - app/graphql/types/inputs/base/attachment.rb
95
96
  - app/graphql/types/inputs/base/filter.rb
96
97
  - app/graphql/types/inputs/base/paging.rb