active_decorator-graphql 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +25 -0
- data/lib/active_decorator/graphql.rb +13 -1
- data/lib/active_decorator/graphql/config.rb +13 -0
- data/lib/active_decorator/graphql/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 108e2d8ff610ce64f923477f0bfcc2ec6345cfff
|
|
4
|
+
data.tar.gz: d4fa650fcdee5fb6e8ca9bd86ecda1e5a30181d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0838c082fdcd41bc8a2c5797976558878302bd392003f58000c1ed84009477e4f81fe9cbba353ed35b496c7261b2bbde3b29f74b896e8897c33155a08c431d4
|
|
7
|
+
data.tar.gz: 7ffa932d27f8b3d878ab65a7a81f9a2cc8a6a5f66041a5bc597aa4f4f8661aac4374eb0e971c96e078825f57388df092f62d4e052b3154e8bc9b0705df36f85d
|
data/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://travis-ci.org/hshimoyama/active_decorator-graphql)
|
|
2
|
+
|
|
1
3
|
# ActiveDecorator::GraphQL
|
|
2
4
|
|
|
3
5
|
A toolkit for decorationg GraphQL field objects using [ActiveDecorator](https://github.com/amatsuda/active_decorator).
|
|
@@ -20,6 +22,8 @@ Or install it yourself as:
|
|
|
20
22
|
|
|
21
23
|
## Usage
|
|
22
24
|
|
|
25
|
+
### Decorate All fields
|
|
26
|
+
|
|
23
27
|
- Model
|
|
24
28
|
|
|
25
29
|
```rb
|
|
@@ -49,6 +53,27 @@ end
|
|
|
49
53
|
|
|
50
54
|
then GraphQL::Field resolves `full_name` by decorated Author objects.
|
|
51
55
|
|
|
56
|
+
### Decorate only specific fields
|
|
57
|
+
|
|
58
|
+
If you want to decorate only specific fields ActiveDecorater::GraphQL provides options to control decoration default and field decoration.
|
|
59
|
+
|
|
60
|
+
- Control decoration defaults (config/initializers/active_decorator-graphql.rb)
|
|
61
|
+
|
|
62
|
+
```rb
|
|
63
|
+
ActiveDecorator::GraphQL::Config.decorate = false # default: true
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- Control specific field decoration (GraphQL Type)
|
|
67
|
+
|
|
68
|
+
```rb
|
|
69
|
+
Types::AuthorType = GraphQL::ObjectType.define do
|
|
70
|
+
name "Author"
|
|
71
|
+
field :full_name, !types.String, decorate: true
|
|
72
|
+
# true: force enabling decoration
|
|
73
|
+
# false: force disabling decoration
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
52
77
|
## Development
|
|
53
78
|
|
|
54
79
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -2,13 +2,25 @@ require "graphql"
|
|
|
2
2
|
require "rails"
|
|
3
3
|
require "active_decorator"
|
|
4
4
|
require "active_decorator/graphql/version"
|
|
5
|
+
require "active_decorator/graphql/config"
|
|
5
6
|
|
|
6
7
|
module GraphQL
|
|
7
8
|
class Field
|
|
9
|
+
attr_accessor :decorate
|
|
10
|
+
def decorate?
|
|
11
|
+
!!@decorate
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
alias resolve_org resolve
|
|
9
15
|
def resolve(object, arguments, context)
|
|
10
|
-
::ActiveDecorator::Decorator.instance.decorate(object)
|
|
16
|
+
::ActiveDecorator::Decorator.instance.decorate(object) if need_decorate?
|
|
11
17
|
resolve_org(object, arguments, context)
|
|
12
18
|
end
|
|
19
|
+
|
|
20
|
+
def need_decorate?
|
|
21
|
+
return decorate? unless self.decorate.nil?
|
|
22
|
+
::ActiveDecorator::GraphQL::Config.decorate?
|
|
23
|
+
end
|
|
13
24
|
end
|
|
25
|
+
Field.own_dictionary[:decorate] = ::GraphQL::Define::InstanceDefinable::AssignAttribute.new(:decorate)
|
|
14
26
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_decorator-graphql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shimoyama, Hiroyasu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-06-
|
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -130,6 +130,7 @@ files:
|
|
|
130
130
|
- gemfiles/rails_5_0.gemfile
|
|
131
131
|
- gemfiles/rails_5_1.gemfile
|
|
132
132
|
- lib/active_decorator/graphql.rb
|
|
133
|
+
- lib/active_decorator/graphql/config.rb
|
|
133
134
|
- lib/active_decorator/graphql/version.rb
|
|
134
135
|
homepage: https://github.com/hshimoyama/active_decorator-graphql
|
|
135
136
|
licenses:
|