graphql-fragment_cache 1.0.3 → 1.0.4
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/CHANGELOG.md +5 -0
- data/README.md +12 -0
- data/lib/.rbnext/2.3/graphql/fragment_cache/memory_store.rb +64 -0
- data/lib/.rbnext/2.7/graphql/fragment_cache/cache_key_builder.rb +2 -2
- data/lib/graphql/fragment_cache/cache_key_builder.rb +2 -2
- data/lib/graphql/fragment_cache/connections/patch.rb +5 -5
- data/lib/graphql/fragment_cache/object_helpers.rb +0 -12
- data/lib/graphql/fragment_cache/version.rb +1 -1
- metadata +10 -9
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4a52d1b703c963cd27803c1c28ca0e8c1a66775a84ad8963f88a0e414ec7ed6c
         | 
| 4 | 
            +
              data.tar.gz: 4739e71ae750d7fbb8c9366e17da84ad9ae921409308a1b109fc60d8add0557a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 889510e3937c874742624f6da651914ed98c6a996842ec57fcda8121287eead193e12b974247733b38ffc7662e542eb1a82b2fb43d18ef5a121cc41607f811fb
         | 
| 7 | 
            +
              data.tar.gz: 4e9dbeb855f55bf37fbe14900b7c4b1b398155902759fd905a87c70da6dfd67850102be48c5b350d6b3126090ced6aaf0bb5b95a7f16a990dd8b070b589e865c
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -2,6 +2,11 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            ## master
         | 
| 4 4 |  | 
| 5 | 
            +
            ## 1.0.4 (2020-10-12)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            - [PR#34](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/34) Avoid unneded default calculation in CacheKeyBuilder ([@DmitryTsepelev][])
         | 
| 8 | 
            +
            - [PR#31](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/31) Do not patch Connection#wrap in graphql >= 1.10.5 ([@DmitryTsepelev][])
         | 
| 9 | 
            +
             | 
| 5 10 | 
             
            ## 1.0.3 (2020-08-31)
         | 
| 6 11 |  | 
| 7 12 | 
             
            - [PR#29](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/29) Cache result JSON instead of connection objects ([@DmitryTsepelev][])
         | 
    
        data/README.md
    CHANGED
    
    | @@ -275,6 +275,18 @@ class QueryType < BaseObject | |
| 275 275 | 
             
            end
         | 
| 276 276 | 
             
            ```
         | 
| 277 277 |  | 
| 278 | 
            +
            ## Limitations
         | 
| 279 | 
            +
             | 
| 280 | 
            +
            Caching does not work for Union types, because of the `Lookahead` implementation: it requires the exact type to be passed to the `selection` method (you can find the [discussion](https://github.com/rmosolgo/graphql-ruby/pull/3007) here). This method is used for cache key building, and I haven't found a workaround yet ([PR in progress](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/30)). If you get `Failed to look ahead the field` error — please pass `query_cache_key` explicitly:
         | 
| 281 | 
            +
             | 
| 282 | 
            +
            ```ruby
         | 
| 283 | 
            +
            field :cached_avatar_url, String, null: false
         | 
| 284 | 
            +
             | 
| 285 | 
            +
            def cached_avatar_url
         | 
| 286 | 
            +
              cache_fragment(query_cache_key: "post_avatar_url(#{object.id})") { object.avatar_url }
         | 
| 287 | 
            +
            end
         | 
| 288 | 
            +
            ```
         | 
| 289 | 
            +
             | 
| 278 290 | 
             
            ## Credits
         | 
| 279 291 |  | 
| 280 292 | 
             
            Based on the original [gist](https://gist.github.com/palkan/faad9f6ff1db16fcdb1c071ec50e4190) by [@palkan](https://github.com/palkan) and [@ssnickolay](https://github.com/ssnickolay).
         | 
| @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            using RubyNext
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module GraphQL
         | 
| 6 | 
            +
              module FragmentCache
         | 
| 7 | 
            +
                # Memory adapter for storing cached fragments
         | 
| 8 | 
            +
                class MemoryStore
         | 
| 9 | 
            +
                  using RubyNext
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  class Entry < Struct.new(:value, :expires_at, keyword_init: true)
         | 
| 12 | 
            +
                    def expired?
         | 
| 13 | 
            +
                      expires_at && expires_at < Time.now
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  attr_reader :default_expires_in
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def initialize(expires_in: nil, **other)
         | 
| 20 | 
            +
                    raise ArgumentError, "Unsupported options: #{other.keys.join(",")}" unless other.empty?
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    @default_expires_in = expires_in
         | 
| 23 | 
            +
                    @storage = {}
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def keys
         | 
| 27 | 
            +
                    storage.keys
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def exist?(key)
         | 
| 31 | 
            +
                    storage.key?(key)
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def read(key)
         | 
| 35 | 
            +
                    key = key.to_s
         | 
| 36 | 
            +
                    ((!storage[key].nil?) || nil) && storage[key].then do |entry|
         | 
| 37 | 
            +
              if entry.expired?
         | 
| 38 | 
            +
                delete(key)
         | 
| 39 | 
            +
                next
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              entry.value
         | 
| 42 | 
            +
            end
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  def write(key, value, expires_in: default_expires_in, **options)
         | 
| 46 | 
            +
                    key = key.to_s
         | 
| 47 | 
            +
                    @storage[key] = Entry.new(value: value, expires_at: expires_in ? Time.now + expires_in : nil)
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  def delete(key)
         | 
| 51 | 
            +
                    key = key.to_s
         | 
| 52 | 
            +
                    storage.delete(key)
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def clear
         | 
| 56 | 
            +
                    storage.clear
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  private
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  attr_reader :storage
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
            end
         | 
| @@ -121,11 +121,11 @@ module GraphQL | |
| 121 121 | 
             
                  private
         | 
| 122 122 |  | 
| 123 123 | 
             
                  def schema_cache_key
         | 
| 124 | 
            -
                    @options.fetch(:schema_cache_key | 
| 124 | 
            +
                    @options.fetch(:schema_cache_key) { schema.schema_cache_key }
         | 
| 125 125 | 
             
                  end
         | 
| 126 126 |  | 
| 127 127 | 
             
                  def query_cache_key
         | 
| 128 | 
            -
                    @options.fetch(:query_cache_key | 
| 128 | 
            +
                    @options.fetch(:query_cache_key) { "#{path_cache_key}[#{selections_cache_key}]" }
         | 
| 129 129 | 
             
                  end
         | 
| 130 130 |  | 
| 131 131 | 
             
                  def selections_cache_key
         | 
| @@ -121,11 +121,11 @@ module GraphQL | |
| 121 121 | 
             
                  private
         | 
| 122 122 |  | 
| 123 123 | 
             
                  def schema_cache_key
         | 
| 124 | 
            -
                    @options.fetch(:schema_cache_key | 
| 124 | 
            +
                    @options.fetch(:schema_cache_key) { schema.schema_cache_key }
         | 
| 125 125 | 
             
                  end
         | 
| 126 126 |  | 
| 127 127 | 
             
                  def query_cache_key
         | 
| 128 | 
            -
                    @options.fetch(:query_cache_key | 
| 128 | 
            +
                    @options.fetch(:query_cache_key) { "#{path_cache_key}[#{selections_cache_key}]" }
         | 
| 129 129 | 
             
                  end
         | 
| 130 130 |  | 
| 131 131 | 
             
                  def selections_cache_key
         | 
| @@ -5,14 +5,14 @@ module GraphQL | |
| 5 5 | 
             
                module Connections
         | 
| 6 6 | 
             
                  # Patches GraphQL::Pagination::Connections to support raw values
         | 
| 7 7 | 
             
                  module Patch
         | 
| 8 | 
            -
                    if Gem::Dependency.new("graphql", " | 
| 9 | 
            -
                      def wrap(field, parent, items, arguments, context, *options)
         | 
| 10 | 
            -
                        raw_value?(items) ? items : super
         | 
| 11 | 
            -
                      end
         | 
| 12 | 
            -
                    else
         | 
| 8 | 
            +
                    if Gem::Dependency.new("graphql", "< 1.11.0").match?("graphql", GraphQL::VERSION)
         | 
| 13 9 | 
             
                      def wrap(field, object, arguments, context, *options)
         | 
| 14 10 | 
             
                        raw_value?(object) ? object : super
         | 
| 15 11 | 
             
                      end
         | 
| 12 | 
            +
                    elsif Gem::Dependency.new("graphql", "< 1.11.5").match?("graphql", GraphQL::VERSION)
         | 
| 13 | 
            +
                      def wrap(field, parent, items, arguments, context, *options)
         | 
| 14 | 
            +
                        raw_value?(items) ? items : super
         | 
| 15 | 
            +
                      end
         | 
| 16 16 | 
             
                    end
         | 
| 17 17 |  | 
| 18 18 | 
             
                    private
         | 
| @@ -12,8 +12,6 @@ module GraphQL | |
| 12 12 |  | 
| 13 13 | 
             
                  NO_OBJECT = Object.new
         | 
| 14 14 |  | 
| 15 | 
            -
                  def_delegator :field, :connection?
         | 
| 16 | 
            -
             | 
| 17 15 | 
             
                  def cache_fragment(object_to_cache = NO_OBJECT, **options, &block)
         | 
| 18 16 | 
             
                    raise ArgumentError, "Block or argument must be provided" unless block_given? || object_to_cache != NO_OBJECT
         | 
| 19 17 |  | 
| @@ -29,16 +27,6 @@ module GraphQL | |
| 29 27 | 
             
                      context.fragments << fragment
         | 
| 30 28 | 
             
                    end
         | 
| 31 29 | 
             
                  end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                  private
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  def field
         | 
| 36 | 
            -
                    interpreter_context[:current_field]
         | 
| 37 | 
            -
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                  def interpreter_context
         | 
| 40 | 
            -
                    @interpreter_context ||= context.namespace(:interpreter)
         | 
| 41 | 
            -
                  end
         | 
| 42 30 | 
             
                end
         | 
| 43 31 | 
             
              end
         | 
| 44 32 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: graphql-fragment_cache
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - DmitryTsepelev
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-10-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: graphql
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 0. | 
| 33 | 
            +
                    version: 0.10.0
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 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: 0. | 
| 40 | 
            +
                    version: 0.10.0
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: combustion
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -128,28 +128,28 @@ dependencies: | |
| 128 128 | 
             
                requirements:
         | 
| 129 129 | 
             
                - - ">="
         | 
| 130 130 | 
             
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            -
                    version: '0. | 
| 131 | 
            +
                    version: '0.10'
         | 
| 132 132 | 
             
              type: :development
         | 
| 133 133 | 
             
              prerelease: false
         | 
| 134 134 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 135 | 
             
                requirements:
         | 
| 136 136 | 
             
                - - ">="
         | 
| 137 137 | 
             
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            -
                    version: '0. | 
| 138 | 
            +
                    version: '0.10'
         | 
| 139 139 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            -
              name:  | 
| 140 | 
            +
              name: unparser
         | 
| 141 141 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 142 | 
             
                requirements:
         | 
| 143 143 | 
             
                - - '='
         | 
| 144 144 | 
             
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            -
                    version:  | 
| 145 | 
            +
                    version: 0.4.9
         | 
| 146 146 | 
             
              type: :development
         | 
| 147 147 | 
             
              prerelease: false
         | 
| 148 148 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 149 | 
             
                requirements:
         | 
| 150 150 | 
             
                - - '='
         | 
| 151 151 | 
             
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            -
                    version:  | 
| 152 | 
            +
                    version: 0.4.9
         | 
| 153 153 | 
             
            description: Fragment cache for graphql-ruby
         | 
| 154 154 | 
             
            email:
         | 
| 155 155 | 
             
            - dmitry.a.tsepelev@gmail.com
         | 
| @@ -162,6 +162,7 @@ files: | |
| 162 162 | 
             
            - README.md
         | 
| 163 163 | 
             
            - bin/console
         | 
| 164 164 | 
             
            - bin/setup
         | 
| 165 | 
            +
            - lib/.rbnext/2.3/graphql/fragment_cache/memory_store.rb
         | 
| 165 166 | 
             
            - lib/.rbnext/2.7/graphql/fragment_cache/cache_key_builder.rb
         | 
| 166 167 | 
             
            - lib/.rbnext/2.7/graphql/fragment_cache/ext/graphql_cache_key.rb
         | 
| 167 168 | 
             
            - lib/graphql-fragment_cache.rb
         |