graphql_rails 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95b29ebcb8c062456b3709134aca3184037fabc4d1f5dc6e8440f712065b8b9d
4
- data.tar.gz: 7b177bb136a4bedffaf9c9836db393713d88d531de3cb302f89ec52c652dc56a
3
+ metadata.gz: 4fde3149c0119edc09198e27b61c428ed666ea2bb4582b428142db31a58749c4
4
+ data.tar.gz: d9faa17f35d1ac01400b829983d6a2b16230c62971bb6ed0178b9a6bf4b1c0bd
5
5
  SHA512:
6
- metadata.gz: 6aa73c56c429120d6d6aa534075bee9e36cf4d0fa18d2169e89afb81965eb06e90e3d595f214faf4af1ff91aadcb2fbea9be6ceaf569321be57a9ca654d7bb0f
7
- data.tar.gz: 85fbd80f9a00833636e65941c78e14e0696d55a8b1a3b4530d1a143341d86a152ad3f5879dcf2f9f2b308b297a31cdaa1ed144ad9e50533a9b5e244584a35b87
6
+ metadata.gz: ee735c639cf392c7a4261db07791bb953942977fd4c001fcb101fd3e4a7009db58fb27520d0227e2b3254fdbc5d2dc52043d892597e99d4526ad18fc8919de30
7
+ data.tar.gz: 80e3a427bb04a91332230460638d7f866afc843dbebfd9e9211454869154c32459e9c1d3c2dcaa97e06bd767792bc6ff742b871ded561094354bc4beab2517a1
data/CHANGELOG.md CHANGED
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  * Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
11
11
 
12
+ ## [1.2.4](2021-05-05)
13
+
14
+ * Fixed: Dynamic types definition where type A references type B referencing type A.
15
+
12
16
  ## [1.2.3](2021-04-12)
13
17
 
14
18
  * Fixed: Total count on paginated resources
data/Gemfile.lock CHANGED
@@ -90,7 +90,9 @@ GEM
90
90
  marcel (0.3.3)
91
91
  mimemagic (~> 0.3.2)
92
92
  method_source (1.0.0)
93
- mimemagic (0.3.5)
93
+ mimemagic (0.3.10)
94
+ nokogiri (~> 1)
95
+ rake
94
96
  mini_mime (1.0.2)
95
97
  mini_portile2 (2.5.0)
96
98
  minitest (5.14.2)
@@ -145,7 +147,7 @@ GEM
145
147
  rainbow (3.0.0)
146
148
  rake (13.0.1)
147
149
  regexp_parser (1.8.2)
148
- rexml (3.2.4)
150
+ rexml (3.2.5)
149
151
  rspec (3.10.0)
150
152
  rspec-core (~> 3.10.0)
151
153
  rspec-expectations (~> 3.10.0)
@@ -28,7 +28,7 @@ module GraphqlRails
28
28
 
29
29
  def graphql
30
30
  @graphql ||= Model::Configuration.new(self)
31
- yield(@graphql) if block_given?
31
+ @graphql.tap { |it| yield(it) }.with_ensured_fields! if block_given?
32
32
  @graphql
33
33
  end
34
34
  end
@@ -68,6 +68,14 @@ module GraphqlRails
68
68
  @connection_type ||= BuildConnectionType.call(graphql_type)
69
69
  end
70
70
 
71
+ def with_ensured_fields!
72
+ return self if @graphql_type.blank?
73
+
74
+ reset_graphql_type if attributes.any? && graphql_type.fields.length != attributes.length
75
+
76
+ self
77
+ end
78
+
71
79
  private
72
80
 
73
81
  attr_reader :model_class
@@ -75,6 +83,16 @@ module GraphqlRails
75
83
  def default_name
76
84
  @default_name ||= model_class.name.split('::').last
77
85
  end
86
+
87
+ def reset_graphql_type
88
+ @graphql_type = FindOrBuildGraphqlType.call(
89
+ name: name,
90
+ description: description,
91
+ attributes: attributes,
92
+ type_name: type_name,
93
+ force_define_attributes: true
94
+ )
95
+ end
78
96
  end
79
97
  end
80
98
  end
@@ -10,20 +10,21 @@ module GraphqlRails
10
10
 
11
11
  include ::GraphqlRails::Service
12
12
 
13
- def initialize(name:, description:, attributes:, type_name:)
13
+ def initialize(name:, description:, attributes:, type_name:, force_define_attributes: false)
14
14
  @name = name
15
15
  @description = description
16
16
  @attributes = attributes
17
17
  @type_name = type_name
18
+ @force_define_attributes = force_define_attributes
18
19
  end
19
20
 
20
21
  def call
21
- klass.tap { add_fields_to_graphql_type if new_class? }
22
+ klass.tap { add_fields_to_graphql_type if new_class? || force_define_attributes }
22
23
  end
23
24
 
24
25
  private
25
26
 
26
- attr_reader :name, :description, :attributes, :type_name
27
+ attr_reader :name, :description, :attributes, :type_name, :force_define_attributes
27
28
 
28
29
  delegate :klass, :new_class?, to: :type_class_finder
29
30
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlRails
4
- VERSION = '1.2.3'
4
+ VERSION = '1.2.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Povilas Jurčys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql