graphql-decorate 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -14
- data/graphql-decorate.gemspec +13 -8
- data/lib/graphql/decorate/undecorated_field.rb +8 -9
- data/lib/graphql/decorate/version.rb +1 -1
- data/lib/graphql/decorate.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac0949a542979b4218036dae55013d1b148cda15cfafdab0d741aa23d882d289
|
4
|
+
data.tar.gz: ac03a2c2c2d554fadd4a7b1ad489d572954c84d7efb77f8afe301c3e8f5909ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4646f9ea8f791e8ae56163ee8f1ff67849a697365eed6fc5ac9d3ef4327933d6d650cb2aef6cf8160ebea76826de0152d13c9c0b5719da5bdb02e012d9371587
|
7
|
+
data.tar.gz: 02e3384f30868f20d490db4dc3481c77bc94f1ce1e3ad446c15a9bb63a3825fd98d7712341452ed532e4a794379503a0e9d4db518080c521d980579337373fd3
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ class RectangleDecorator < BaseDecorator
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
class
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
125
|
+
metadata.unscoped do |object, _graphql_context|
|
126
|
+
{
|
127
|
+
name: object.name
|
128
|
+
}
|
129
|
+
end
|
131
130
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
150
|
+
metadata.scoped do |object, _graphql_context|
|
152
151
|
{
|
153
152
|
name: object.name
|
154
153
|
}
|
data/graphql-decorate.gemspec
CHANGED
@@ -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
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
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
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
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
|
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
|
@@ -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,14 @@ module GraphQL
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def resolved_type_attributes
|
103
|
-
@resolved_type_attributes ||=
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
+
graphql_context.schema.resolve_type(type, value, graphql_context)
|
109
|
+
end
|
110
|
+
end
|
112
111
|
end
|
113
112
|
end
|
114
113
|
end
|
data/lib/graphql/decorate.rb
CHANGED
@@ -35,7 +35,7 @@ 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.
|
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|
|
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.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Brook
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -159,7 +159,8 @@ files:
|
|
159
159
|
homepage: https://www.github.com/TrueCar/graphql-decorate
|
160
160
|
licenses:
|
161
161
|
- MIT
|
162
|
-
metadata:
|
162
|
+
metadata:
|
163
|
+
rubygems_mfa_required: 'true'
|
163
164
|
post_install_message:
|
164
165
|
rdoc_options: []
|
165
166
|
require_paths:
|
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
176
|
- !ruby/object:Gem::Version
|
176
177
|
version: '0'
|
177
178
|
requirements: []
|
178
|
-
rubygems_version: 3.0.3
|
179
|
+
rubygems_version: 3.0.3.1
|
179
180
|
signing_key:
|
180
181
|
specification_version: 4
|
181
182
|
summary: A decorator integration for the GraphQL gem
|