graphql-cache 0.2.0 → 0.2.1

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: d20a6abf5bff1dee85af2a7fe01ca15513e4553f87f255f4c4cea9f1166bfeaa
4
- data.tar.gz: 55c93f0e7fcf6f072dbd8728bddffe082fb006863786cba6d1c8cdb47a0abd75
3
+ metadata.gz: e2adeaaafa2b7714c4300a996c5ae17581269dec775277ef4f8b9ddcd90be16b
4
+ data.tar.gz: aebe2b614ab273b0e49fd7d2e5b997036196e69abd4a0db85a17db7715a084bc
5
5
  SHA512:
6
- metadata.gz: 8f586d9f2b11cf724fbf4df6f5af9a2b839a4a527029a3c67b4786da7fe30acc45d0f0889657e4df7b38e5c21b792459c56a82fcf09dc6e2d39972ea1a117a65
7
- data.tar.gz: '0669f17df94d9ecef5d14db5821c927f4747c826e87b737730e83653b2925df2834a3075d7cc635420179fe2daa493af38772744c05bbb06b7ac206132f58788'
6
+ metadata.gz: 5f57bcda1e5ae7db5cacacfde797f353b86abf1feaaf7b87a47315a0b945b32969d415ac9ab39eef837c3011f46921d7f3c48534d56741964da5ba599c244086
7
+ data.tar.gz: 9f9d0afb64baba52c851c1cfaab7142d9419abba765137187ac3853dbf48962214d093a83c73487fa225d99a849ddc1d12ca2612bb99ef4bcbbc67459cd5f5f8
data/.travis.yml CHANGED
@@ -3,10 +3,10 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
5
  before_script:
6
+ - gem install bundler
6
7
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
7
8
  - chmod +x ./cc-test-reporter
8
9
  - ./cc-test-reporter before-build
9
- - gem install bundler -v 1.16.1
10
10
  script: bundle exec rspec
11
11
  after_script:
12
12
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-cache (0.2.0)
4
+ graphql-cache (0.2.1)
5
5
  graphql (~> 1.8.0.pre10)
6
6
 
7
7
  GEM
@@ -12,7 +12,7 @@ GEM
12
12
  coderay (1.1.2)
13
13
  diff-lcs (1.3)
14
14
  docile (1.3.0)
15
- graphql (1.8.0.pre11)
15
+ graphql (1.8.0)
16
16
  json (2.1.0)
17
17
  method_source (0.9.0)
18
18
  pry (0.11.3)
@@ -2,6 +2,8 @@ require 'graphql'
2
2
 
3
3
  module GraphQL
4
4
  module Cache
5
+ # Custom field class implementation to allow for
6
+ # cache config keyword parameters
5
7
  class Field < ::GraphQL::Schema::Field
6
8
  # Override #initialize to take a new argument:
7
9
  def initialize(
@@ -10,11 +12,7 @@ module GraphQL
10
12
  **kwargs,
11
13
  &block
12
14
  )
13
- @cache_config = if cache.is_a? Hash
14
- cache
15
- else
16
- { cache: cache }
17
- end
15
+ @cache_config = cache
18
16
  super(*args, **kwargs, &block)
19
17
  end
20
18
 
@@ -30,14 +30,22 @@ module GraphQL
30
30
 
31
31
  def write(config)
32
32
  resolved = yield
33
- expiry = config[:metadata][:expiry] || GraphQL::Cache.expiry
34
-
35
33
  document = Builder[resolved].deconstruct
36
34
 
37
- cache.write(key, document, expires_in: expiry)
35
+ cache.write(key, document, expires_in: expiry(config))
38
36
  resolved
39
37
  end
40
38
 
39
+ def expiry(config)
40
+ cache_config = config[:metadata][:cache]
41
+
42
+ if cache_config.is_a?(Hash) && cache_config[:expiry]
43
+ config[:metadata][:cache][:expiry]
44
+ else
45
+ GraphQL::Cache.expiry
46
+ end
47
+ end
48
+
41
49
  def build(cached, config)
42
50
  Builder[cached].build(config)
43
51
  end
@@ -39,7 +39,7 @@ module GraphQL
39
39
  def metadata_hash
40
40
  {
41
41
  metadata: {
42
- cache: field_definition.metadata[:cache] || {}
42
+ cache: field_definition.metadata[:cache]
43
43
  }
44
44
  }
45
45
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Cache
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kelly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-16 00:00:00.000000000 Z
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler