Sha256: e3880aa491e6bee075ba5d9e458e9f27932790e679f27c0eb5988f7160e02bd9

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'graphql'
require 'graphql/result_cache/version'
require 'graphql/result_cache/field'
require 'graphql/result_cache/result'
require 'graphql/result_cache/field_instrument'
require 'graphql/result_cache/introspection'

module GraphQL
  module ResultCache
    class << self
      attr_accessor :expires_in
      attr_accessor :namespace
      attr_accessor :cache
      attr_accessor :logger

      # to expire the cache when client hash changes, should be a proc. eg:
      # c.client_hash = -> { Rails.cache.read(:deploy_version) }
      attr_accessor :client_hash

      # ```
      # GraphQL::ResultCache.configure do |c|
      #   c.namespace = "GraphQL:Result"
      #   c.expires_in = 1.hour
      #   c.client_hash = -> { Rails.cache.read(:deploy_version) }
      # end
      # ```
      def configure
        yield self
      end
    end

    # Default configuration
    @expires_in = 3600              # 1.hour
    @namespace = 'GraphQL:Result'

    def self.use(schema_def, options: {})
      schema_def.instrument(:field, ::GraphQL::ResultCache::FieldInstrument.new)
    end
  end
end

require 'graphql/result_cache/rails' if defined?(::Rails::Engine)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-result_cache-0.1.4 lib/graphql/result_cache.rb
graphql-result_cache-0.1.3 lib/graphql/result_cache.rb