active_decorator-graphql 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: d537f2d8be3368ddfeb622316a82190d8619a934
4
- data.tar.gz: b92460477dfb3a3f6fd63eba0cb4397456d97d1a
3
+ metadata.gz: 108e2d8ff610ce64f923477f0bfcc2ec6345cfff
4
+ data.tar.gz: d4fa650fcdee5fb6e8ca9bd86ecda1e5a30181d1
5
5
  SHA512:
6
- metadata.gz: bfabc619c127b2b0f290ce84cfa1e216031ad085d2191722ace967910731ce77c0fdbc34cd3c0184395850dc3c5cdb685b96b058d9cae811f33b3e799c940c14
7
- data.tar.gz: a25dc78e8c2c06e5d6a0d03dd01a78468855a133872a8634f58a2e7faece9b25ab2d346c1523103532929e93cae6e6904d9bccc4fa5409163d92d3f55cb77a07
6
+ metadata.gz: d0838c082fdcd41bc8a2c5797976558878302bd392003f58000c1ed84009477e4f81fe9cbba353ed35b496c7261b2bbde3b29f74b896e8897c33155a08c431d4
7
+ data.tar.gz: 7ffa932d27f8b3d878ab65a7a81f9a2cc8a6a5f66041a5bc597aa4f4f8661aac4374eb0e971c96e078825f57388df092f62d4e052b3154e8bc9b0705df36f85d
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/hshimoyama/active_decorator-graphql.svg?branch=master)](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
@@ -0,0 +1,13 @@
1
+ module ActiveDecorator
2
+ module GraphQL
3
+ module Config
4
+ class << self
5
+ attr_accessor :decorate
6
+ def decorate?
7
+ !!@decorate
8
+ end
9
+ end
10
+ end
11
+ Config.decorate = true
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveDecorator
2
2
  module GraphQL
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.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-21 00:00:00.000000000 Z
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: