graphql-decorate 1.0.1 → 1.0.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: 87a8fe01c943ec96814efe0e1eff084e8a1a06d07ddfb25bdc957b7b9d7e1359
4
- data.tar.gz: 834c64c23ce5db962159773e82f10ad7130322cffba0ef340a3dbd244b0ec8e4
3
+ metadata.gz: b79924fe9758b0881143f50e7536b02958a88932be59b541545f56ab62fc2571
4
+ data.tar.gz: c2455d37d70dc7ff45d1fbe4eab2ae304437ad4c04d0f0cb4ef5912447c68308
5
5
  SHA512:
6
- metadata.gz: 536f14a8113cd9c166667260b743ef2443b1b845a2293d4fc1b006fd9818d819cd90439c6fd186d10c7ba0657eb6bd67840053160a65045edff94a69ace61db4
7
- data.tar.gz: a083fe5519d3d5c980e01e9aa72f8e9c4f18d05c0130032a617933aba15410a9b32d7ef0b29dae8445dec018b68fc963b1964bb2534f06481594ab7759587498
6
+ metadata.gz: fa468e9077d6854f198045c2ad8ebc47bb07c9c63cc2e14d52b3f65693fe12c9dc2466787740c76c92ea98e4617b0c42cc39c72672f3c5dbc777291a259f66e2
7
+ data.tar.gz: 7372025f4fd3857dff61b875f9da3883030f5f1b43f406a985d76f74ca72c548d2df3cabf915a7979eecc8f66b8a8330849d1b7f1df43405fa4aba575185bc39
data/README.md CHANGED
@@ -54,7 +54,7 @@ class RectangleDecorator < BaseDecorator
54
54
  end
55
55
  end
56
56
 
57
- class Rectangle < BaseObject
57
+ class RectangleType < BaseObject
58
58
  decorate_with RectangleDecorator
59
59
 
60
60
  field :area, Int, null: false
@@ -84,8 +84,7 @@ end
84
84
  ### Types
85
85
  Two methods are made available on your type classes: `decorate_with` and `decorate_metadata`.
86
86
  Every method that yields the underlying object will also yield the current GraphQL `context`.
87
- If decoration depends on some context in the current query then you can access it when the field
88
- is resolved.
87
+ If decoration depends on some context in the current query then you can access it when the field is resolved.
89
88
 
90
89
  #### decorate_with
91
90
  `decorate_with` accepts a decorator class that will decorate every instance of your type.
@@ -123,17 +122,17 @@ to return `Hash`s.
123
122
  ```ruby
124
123
  class Rectangle < GraphQL::Schema::Object
125
124
  decorate_metadata do |metadata|
126
- metadata.unscoped do |object, _graphql_context|
127
- {
128
- name: object.name
129
- }
130
- end
125
+ metadata.unscoped do |object, _graphql_context|
126
+ {
127
+ name: object.name
128
+ }
129
+ end
131
130
 
132
- metadata.scoped do |object, _graphql_context|
133
- {
134
- inside_rectangle: true
135
- }
136
- end
131
+ metadata.scoped do |object, _graphql_context|
132
+ {
133
+ inside_rectangle: true
134
+ }
135
+ end
137
136
  end
138
137
  end
139
138
  ```
@@ -148,7 +147,7 @@ You can mix and match these methods to suit your needs. Note that if `unscoped`
148
147
  class Rectangle < GraphQL::Schema::Object
149
148
  decorate_with RectangleDecorator
150
149
  decorate_metadata do |metadata|
151
- metadata.scoped do |object, _graphql_context|
150
+ metadata.scoped do |object, _graphql_context|
152
151
  {
153
152
  name: object.name
154
153
  }
@@ -4,20 +4,24 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'graphql/decorate/version'
6
6
 
7
+ # rubocop:disable Metrics/BlockLength
7
8
  Gem::Specification.new do |spec|
8
- spec.name = 'graphql-decorate'
9
- spec.version = GraphQL::Decorate::VERSION
10
- spec.authors = ['Ben Brook']
11
- spec.email = ['bbrook154@gmail.com']
9
+ spec.name = 'graphql-decorate'
10
+ spec.version = GraphQL::Decorate::VERSION
11
+ spec.authors = ['Ben Brook']
12
+ spec.email = ['bbrook154@gmail.com']
12
13
 
13
- spec.summary = 'A decorator integration for the GraphQL gem'
14
- spec.homepage = 'https://www.github.com/TrueCar/graphql-decorate'
15
- spec.license = 'MIT'
14
+ spec.summary = 'A decorator integration for the GraphQL gem'
15
+ spec.homepage = 'https://www.github.com/TrueCar/graphql-decorate'
16
+ spec.license = 'MIT'
17
+ spec.metadata = {
18
+ 'rubygems_mfa_required' => 'true'
19
+ }
16
20
 
17
21
  # Specify which files should be added to the gem when it is released.
18
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added
19
23
  # into git.
20
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
25
  `git ls-files -z`.split("\x0").reject do |f|
22
26
  f.match(%r{^(test|spec|features)/})
23
27
  end
@@ -28,7 +32,7 @@ Gem::Specification.new do |spec|
28
32
 
29
33
  spec.required_ruby_version = '>= 2.6.0'
30
34
 
31
- spec.add_runtime_dependency 'graphql', '>= 1.3', '< 2'
35
+ spec.add_runtime_dependency 'graphql', '>= 1.3'
32
36
 
33
37
  spec.add_development_dependency 'bundler', '>= 2'
34
38
  spec.add_development_dependency 'rake', '>= 12.3.3'
@@ -38,3 +42,4 @@ Gem::Specification.new do |spec|
38
42
  spec.add_development_dependency 'simplecov', '~> 0.21.2'
39
43
  spec.add_development_dependency 'yard', '~> 0.9.26'
40
44
  end
45
+ # rubocop:enable Metrics/BlockLength
@@ -100,15 +100,23 @@ module GraphQL
100
100
  end
101
101
 
102
102
  def resolved_type_attributes
103
- @resolved_type_attributes ||= begin
104
- if type_attributes.unresolved_type?
105
- if type.respond_to?(:resolve_type)
106
- GraphQL::Decorate::TypeAttributes.new(type.resolve_type(value, graphql_context))
107
- else
108
- graphql_context.schema.resolve_type(type, value, graphql_context)
109
- end
110
- end
111
- end
103
+ @resolved_type_attributes ||= if type_attributes.unresolved_type?
104
+ if type.respond_to?(:resolve_type)
105
+ GraphQL::Decorate::TypeAttributes.new(type.resolve_type(value,
106
+ graphql_context))
107
+ else
108
+ resolve_type_attributes_from_schema
109
+ end
110
+ end
111
+ end
112
+
113
+ def resolve_type_attributes_from_schema
114
+ result = graphql_context.schema.resolve_type(type, value, graphql_context)
115
+ return result unless result.is_a?(Array) && result.size == 2
116
+
117
+ result[0]
118
+ .authorized_new(result[1], graphql_context)
119
+ .then(&GraphQL::Decorate::TypeAttributes.method(:new))
112
120
  end
113
121
  end
114
122
  end
@@ -3,6 +3,6 @@
3
3
  module GraphQL
4
4
  module Decorate
5
5
  # Current version number
6
- VERSION = '1.0.1'
6
+ VERSION = '1.0.4'
7
7
  end
8
8
  end
@@ -35,13 +35,13 @@ module GraphQL
35
35
  # @param schema_defn [GraphQL::Schema] Current schema class
36
36
  # @return [nil]
37
37
  def self.use(schema_defn)
38
- schema_defn.to_graphql.types.each do |_name, type|
38
+ schema_defn.types.each do |_name, type|
39
39
  next unless type.respond_to?(:fields)
40
40
 
41
41
  type.fields.each do |_name, field|
42
- field_type = extract_type(field.type_class.type)
42
+ field_type = extract_type(field.type)
43
43
  type_attributes = GraphQL::Decorate::TypeAttributes.new(field_type)
44
- field.type_class.extension(GraphQL::Decorate::FieldExtension) if type_attributes.decoratable?
44
+ field.extension(GraphQL::Decorate::FieldExtension) if type_attributes.decoratable?
45
45
  end
46
46
  end
47
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-decorate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Brook
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +153,8 @@ files:
159
153
  homepage: https://www.github.com/TrueCar/graphql-decorate
160
154
  licenses:
161
155
  - MIT
162
- metadata: {}
156
+ metadata:
157
+ rubygems_mfa_required: 'true'
163
158
  post_install_message:
164
159
  rdoc_options: []
165
160
  require_paths:
@@ -175,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
170
  - !ruby/object:Gem::Version
176
171
  version: '0'
177
172
  requirements: []
178
- rubygems_version: 3.0.3
173
+ rubygems_version: 3.0.3.1
179
174
  signing_key:
180
175
  specification_version: 4
181
176
  summary: A decorator integration for the GraphQL gem