graphql-cache 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 90827abbbae2111c06ea2a0afc7f9daea103098064949eba4bbd84cd791c2fdb
4
- data.tar.gz: 2efebce54277a3fef786d189b9c9bcb9a46dfa22c412a9b51f29f6652e3031c6
3
+ metadata.gz: c6f7002428257c6c015fc0a9db823de56c129732591098f7c44a7ce254fe769e
4
+ data.tar.gz: 74581f477076619693e234c3d7082ab518d463d98de40947f66625901ce24079
5
5
  SHA512:
6
- metadata.gz: d85a82ed4c3dae977475ad723fd6a2c61c676f3e887db196ef1aaa5100c81c2a54a5fc3874ae427baa023a2d00b8e9446a16536cef656c7c7c623b670118032a
7
- data.tar.gz: b0abbd392cc526d552dc5a1296187f053e1a1d66d6f7127eb779602bdbb74b9dec6848308e6d6d94bb199ef94a8b4071def6126a262d6e90b8c8048a3a124a67
6
+ metadata.gz: d6abff3fd6c798263f98da3c4ff2f7f443c14c8e59a9f9d221b37199d7e8a635bab9a32f22c976c4c428facb72c455c82af3c996c5afd4ec7a9bab49489d297a
7
+ data.tar.gz: 7c86dbe1316af159b5872ba668a1600e79d1affbe8b8592a1981f7fbe14842117af3bc09782965e1240240f992ea96af60a217af09e4e7dee41041e7d3b871f9
@@ -1,6 +1,16 @@
1
1
  module GraphQL
2
2
  module Cache
3
+ # Represents the "instrumenter" passed to GraphQL::Schema#instrument
4
+ # when the plugin in initialized (i.e. `use GraphQL::Cache`)
3
5
  class Fetcher
6
+ # Redefines the given field's resolve proc to use our
7
+ # custom cache wrapping resolver proc. Called from
8
+ # graphql-ruby internals. This is the "instrumenter"
9
+ # entrypoint.
10
+ #
11
+ # @param type [GraphQL::Schema::Object] graphql-ruby passes the defined type for the field being instrumented
12
+ # @param field [GraphQL::Schema::Field] graphql-ruby passes the field definition to be re-defined
13
+ # @return [GraphQL::Schema::Field]
4
14
  def instrument(type, field)
5
15
  return field unless field.metadata[:cache]
6
16
 
@@ -5,7 +5,7 @@ module GraphQL
5
5
  # Custom field class implementation to allow for
6
6
  # cache config keyword parameters
7
7
  class Field < ::GraphQL::Schema::Field
8
- # Override #initialize to take a new argument:
8
+ # Overriden to take a new cache keyword argument
9
9
  def initialize(
10
10
  *args,
11
11
  cache: false,
@@ -16,6 +16,7 @@ module GraphQL
16
16
  super(*args, **kwargs, &block)
17
17
  end
18
18
 
19
+ # Overriden to provide custom cache config to internal definition
19
20
  def to_graphql
20
21
  field_defn = super # Returns a GraphQL::Field
21
22
  field_defn.metadata[:cache] = @cache_config
@@ -19,6 +19,11 @@ module GraphQL
19
19
  attr_accessor :metadata
20
20
 
21
21
  # Initializes a new Key with the given graphql query context
22
+ #
23
+ # @param obj [Object] The resolved parent object for a field's resolution
24
+ # @param args [GraphQL::Arguments] The internal graphql-ruby wrapper for field arguments
25
+ # @param type [GraphQL::Schema::Type] The type definition of the parent object
26
+ # @param field [GraphQL::Schema::Field] The field being resolved
22
27
  def initialize(obj, args, type, field)
23
28
  @object = obj.object
24
29
  @arguments = args
@@ -31,6 +36,12 @@ module GraphQL
31
36
 
32
37
  # Returns the string representation of this cache key
33
38
  # suitable for using as a key when writing to cache
39
+ #
40
+ # The key is constructed with this structure:
41
+ #
42
+ # ```
43
+ # namespace:type:field:arguments:object-id
44
+ # ```
34
45
  def to_s
35
46
  @to_s ||= [
36
47
  GraphQL::Cache.namespace,
@@ -79,6 +90,7 @@ module GraphQL
79
90
 
80
91
  # @private
81
92
  def guess_id
93
+ return object.cache_key_with_version if object.respond_to?(:cache_key_with_version)
82
94
  return object.cache_key if object.respond_to?(:cache_key)
83
95
  return object.id if object.respond_to?(:id)
84
96
  object.object_id
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Cache
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  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.4.0
4
+ version: 0.5.0
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-08-03 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal