graphql-result_cache 0.1.4 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cca173c02ac7fcc48f7167ecfe2aaf9abfe861bc783da968473cd2d8705b23c3
4
- data.tar.gz: bfaeb36f3897300d3eb9b7b8d4bd8a5ed0c9396d06b81b0861e2d7290c272a30
3
+ metadata.gz: c6f11b53f28b2c9c5bd70a0f985b106e6a8b530d1a236122db13cacd3f92229c
4
+ data.tar.gz: 37dea5a5328235136a09cb983f800b4cd91fa227fc20f2501d3a766ec7c00508
5
5
  SHA512:
6
- metadata.gz: 7817142f3cf86c97e42fe3fa11e1d84642bb81b158b36df1f6d3a039ee9284f26d7b838818d720a5ee44683a2d3845211f7206b8d83f8d68662b6e73c3656b44
7
- data.tar.gz: 1247cc3baa0720659ae71b796c0500b3c166428ac0e62792e63acd054d05565f8d40a2971d42fe2e0b225a3f7ef0409e4d039aabc0ae4dceb355e24786a9de57
6
+ metadata.gz: 64120b5bfb3d1e5ca80d3fb01d01a158cd441eaeda3640da504080edb04070669b9c0920ab2c08732f9dc6bc07162c8916c5c5361cac514b06c44fd5a781cd9e
7
+ data.tar.gz: 4080d919a8b2acc3b6dff84cace90799f13159705d2bda7aff567586bdaea982a8b5dcabb161f9b3e26d959119ce481a8821a1e830d35ec3e2508ac7714df63f
@@ -0,0 +1,45 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby 2.6
20
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
21
+ with:
22
+ ruby-version: 2.6.6
23
+
24
+ - name: Publish to GPR
25
+ run: |
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
30
+ gem build *.gemspec
31
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
32
+ env:
33
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
34
+ OWNER: ${{ github.repository_owner }}
35
+
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ mkdir -p $HOME/.gem
39
+ touch $HOME/.gem/credentials
40
+ chmod 0600 $HOME/.gem/credentials
41
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
42
+ gem build *.gemspec
43
+ gem push *.gem
44
+ env:
45
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,31 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby-version: ['2.5', '2.6', '2.7']
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
+ # uses: ruby/setup-ruby@v1
26
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
+ - name: Run tests
31
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -6,5 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /tags
9
10
 
10
- /.idea/
11
+ /.idea/
12
+ /graphql-result_cache-*.gem
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-result_cache (0.1.4)
4
+ graphql-result_cache (0.1.8)
5
5
  graphql (~> 1.9)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.3)
11
- graphql (1.9.9)
12
- rake (10.5.0)
11
+ graphql (1.9.12)
12
+ rake (13.0.1)
13
13
  rspec (3.8.0)
14
14
  rspec-core (~> 3.8.0)
15
15
  rspec-expectations (~> 3.8.0)
@@ -28,10 +28,10 @@ PLATFORMS
28
28
  ruby
29
29
 
30
30
  DEPENDENCIES
31
- bundler (~> 1.16)
31
+ bundler (>= 2.2.10)
32
32
  graphql-result_cache!
33
- rake (~> 10.0)
33
+ rake (>= 12.3.3)
34
34
  rspec (~> 3.0)
35
35
 
36
36
  BUNDLED WITH
37
- 1.17.3
37
+ 2.2.31
data/README.md CHANGED
@@ -105,6 +105,7 @@ GraphQL::ResultCache.configure do |config|
105
105
  config.namespace = "GraphQL:Result" # Cache key namespace
106
106
  config.expires_in = 1.hour # Expire time for the cache, default to 1.hour
107
107
  config.client_hash = -> { Rails.cache.read(:deploy_version) } # GraphQL client package hash key, used in cache key generation, default to nil
108
+ config.except = ->(ctx) { !ctx[:result_cacheable] } # Exception rule, skip the cache while evaluated as true, default to nil
108
109
  config.cache = Rails.cache # The cache object, default to Rails.cache in Rails
109
110
  config.logger = Rails.logger # The Logger, default to Rails.logger in Rails
110
111
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  end
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.16'
23
- spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'bundler', '>= 2.2.10'
23
+ spec.add_development_dependency 'rake', '>= 12.3.3'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
 
26
26
  spec.add_dependency 'graphql', '~> 1.9'
@@ -9,15 +9,23 @@ module GraphQL
9
9
  end
10
10
 
11
11
  def true?
12
+ return false if except?
12
13
  case @if
13
- when Symbol
14
- @obj.send(@if)
15
- when Proc
16
- @if.call(@obj, @args, @ctx)
17
- else
18
- true
14
+ when Symbol
15
+ @obj.send(@if)
16
+ when Proc
17
+ @if.call(@obj, @args, @ctx)
18
+ else
19
+ true
19
20
  end
20
21
  end
22
+
23
+ private
24
+
25
+ def except?
26
+ except = ::GraphQL::ResultCache.except
27
+ except.is_a?(Proc) ? except.call(@ctx) : except
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -39,7 +39,7 @@ module GraphQL
39
39
  def cache_or_amend_result result, config_of_query
40
40
  config_of_query.each do |config|
41
41
  if config[:result].nil?
42
- cache.write config[:key], result.dig('data', *config[:path]), expires_in: expires_in
42
+ cache.write config[:key], dig(result, 'data', *config[:path]), cache_write_options.merge(expires_in: expires_in)
43
43
  else
44
44
  # result already got from cache, need to amend to response
45
45
  result_hash = result.to_h
@@ -78,6 +78,10 @@ module GraphQL
78
78
  ::GraphQL::ResultCache.cache
79
79
  end
80
80
 
81
+ def cache_write_options
82
+ ::GraphQL::ResultCache.cache_write_options || {}
83
+ end
84
+
81
85
  def logger
82
86
  ::GraphQL::ResultCache.logger
83
87
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module ResultCache
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.8'
4
4
  end
5
5
  end
@@ -11,12 +11,16 @@ module GraphQL
11
11
  attr_accessor :expires_in
12
12
  attr_accessor :namespace
13
13
  attr_accessor :cache
14
+ attr_accessor :cache_write_options
14
15
  attr_accessor :logger
15
16
 
16
17
  # to expire the cache when client hash changes, should be a proc. eg:
17
18
  # c.client_hash = -> { Rails.cache.read(:deploy_version) }
18
19
  attr_accessor :client_hash
19
20
 
21
+ # global condition, skip the cache when the value is true, should be a proc.
22
+ attr_accessor :except
23
+
20
24
  # ```
21
25
  # GraphQL::ResultCache.configure do |c|
22
26
  # c.namespace = "GraphQL:Result"
@@ -39,4 +43,6 @@ module GraphQL
39
43
  end
40
44
  end
41
45
 
46
+ GraphQL::Schema::Field.accepts_definition(:result_cache)
47
+
42
48
  require 'graphql/result_cache/rails' if defined?(::Rails::Engine)
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-result_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ying Fu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-12 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/gem-push.yml"
77
+ - ".github/workflows/ruby.yml"
76
78
  - ".gitignore"
77
79
  - ".rspec"
78
80
  - CODE_OF_CONDUCT.md