graphql-persisted_queries 1.6.1 → 1.8.0

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: fa710e0a1af1fe00953679781bf408f3c78201b67920671f9af36ff57edefcc0
4
- data.tar.gz: cc46697bf61938af0d4359fb9b5bf4898f3bc5108b4f562f94d3003a857064a6
3
+ metadata.gz: 348a66b5ed4c013fe7c41a01a752acdca8ecf2eac99f5365ac7cc11b3a6bcd4d
4
+ data.tar.gz: 2c15c37b4f4f451d12ab946f86e7df67a393af8d897ec0ec718924520ea5ee7b
5
5
  SHA512:
6
- metadata.gz: 6028cb87dc1e0c7a78f18f29c7afbff2d2aae46fadbec983d6ebbb217016523a8722f27c993570b914b3fec6cebe0d16ad26e7091844a0e60f4bf0d80217cb11
7
- data.tar.gz: a0d0dada8b7f34298a69aed43dd988ce077e010866faf33c8d206375ee0cb2f00afed1f0794753983a5b2b01f266888f7988d77a031f33c6f55d2779abd62e35
6
+ metadata.gz: d1ec95cdd3be52b3eb1fd91eaabfffcd67642185c214272b512d0320a17e7344554ae996b0af5f43b7e9c6b69e951268ba0a34b7b0ffe850d3f0a3c38eb5d1b9
7
+ data.tar.gz: 0ed5474fe161e4f4f1dfec4582f258c33217846bd9a1a607969a9f388d56740c55cb97be0f85184f30c90df56908c7dd224eac48fc7a343d83eb9c7615ea7c71
@@ -18,13 +18,14 @@ jobs:
18
18
  strategy:
19
19
  fail-fast: false
20
20
  matrix:
21
- ruby: [2.6, 2.7, 3.0]
21
+ ruby: [2.7, '3.0', 3.1, 3.2, 3.3]
22
22
  gemfile: [
23
23
  "gemfiles/graphql_1_12_0.gemfile",
24
24
  "gemfiles/graphql_1_12_4.gemfile",
25
25
  "gemfiles/graphql_1_13_7.gemfile",
26
26
  "gemfiles/graphql_1_13_16.gemfile",
27
- "gemfiles/graphql_2_0_0.gemfile",
27
+ "gemfiles/graphql_2_1_0.gemfile",
28
+ "gemfiles/graphql_2_2_5.gemfile",
28
29
  "gemfiles/graphql_master.gemfile"
29
30
  ]
30
31
 
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.8.0 (2024-03-31)
6
+
7
+ - [PR#73](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/73)
8
+ Use trace_with instead of instrument for modern versions of graphql ([@DmitryTsepelev][])
9
+
10
+ ## 1.7.0 (2023-02-02)
11
+
12
+ - [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62)
13
+ Fix double hashing of keys in case of redis_with_local_cache_store adapter ([@mpospelov][])
14
+ - [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62) Drop tracers= implementation as it's no longer valid ([@mpospelov][])
15
+
5
16
  ## 1.6.1 (2022-11-17)
6
17
 
7
18
  - [PR#60](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/60)
@@ -112,3 +123,4 @@ Handle situations when prepare_ast happens before instrumentation ([@DmitryTsepe
112
123
  [@ogidow]: https://github.com/ogidow
113
124
  [@rbviz]: https://github.com/rbviz
114
125
  [@louim]: https://github.com/louim
126
+ [@mpospelov]: https://github.com/mpospelov
data/README.md CHANGED
@@ -6,6 +6,12 @@
6
6
  - 🤝**Clients share cached queries** – it's enough to miss cache only once for each unique query
7
7
  - 🎅**Works for clients without persisted query support**
8
8
 
9
+ Used in production by:
10
+
11
+ - [Yammer by Microsoft](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/issues/20#issuecomment-587945989)
12
+ - Toptal
13
+ - _Want to be here? Let me know_ 🙂
14
+
9
15
  ## Getting started
10
16
 
11
17
  First of all, install and configure [apollo's persisted queries](https://www.apollographql.com/docs/react/api/link/persisted-queries/) on the front–end side:
@@ -80,6 +86,8 @@ Since our queries are slim now, we can switch back to HTTP GET, you can find a [
80
86
 
81
87
  [persisted-queries-link](https://www.apollographql.com/docs/react/api/link/persisted-queries/) uses _SHA256_ for building hashes by default. Check out this [guide](docs/hash.md) if you want to override this behavior.
82
88
 
89
+ It is possible to skip some parts of the query lifecycle for cases when query is persisted - read more [here](docs/skip_query_preprocessing.md).
90
+
83
91
  An experimental tracing feature can be enabled by setting `tracing: true` when configuring the plugin. Read more about this feature in the [Tracing guide](docs/tracing.md).
84
92
 
85
93
  > 📖 Read more about the gem internals: [Persisted queries in GraphQL:
@@ -0,0 +1,17 @@
1
+ # Skipping some preprocessing steps
2
+
3
+ It does not make much sense to revalidate persisted query—we did it earlier, so it can be disabled in the `#execute` call:
4
+
5
+ ```ruby
6
+ GraphqlSchema.execute(
7
+ params[:query],
8
+ variables: ensure_hash(params[:variables]),
9
+ context: {
10
+ extensions: ensure_hash(params[:extensions])
11
+ },
12
+ operation_name: params[:operationName],
13
+ validate: params[:query].present?
14
+ )
15
+ ```
16
+
17
+ Moreover, some analyzers can be disabled as well: in order to do that just pass the same check `params[:query].present?` to the context and then add early exit to your analyzers based on this flag.
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "graphql", "~> 2.1.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "graphql", "~> 2.2.5"
4
+
5
+ gemspec path: "../"
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.required_ruby_version = ">= 2.6"
23
+ spec.required_ruby_version = ">= 2.7"
24
24
 
25
25
  spec.add_dependency "graphql", ">= 1.12"
26
26
 
@@ -15,12 +15,31 @@ module GraphQL
15
15
  schema.singleton_class.prepend(SchemaPatch)
16
16
 
17
17
  if compiled_queries
18
- schema.instrument :query, CompiledQueries::Instrumentation
18
+ configure_compiled_queries(schema)
19
19
  else
20
20
  schema.singleton_class.class_eval { alias_method :multiplex_original, :multiplex }
21
21
  schema.singleton_class.prepend(MultiplexPatch)
22
22
  end
23
23
  end
24
+
25
+ private
26
+
27
+ def configure_compiled_queries(schema)
28
+ if graphql_ruby_after_2_2_5?
29
+ schema.trace_with(GraphQL::Tracing::LegacyHooksTrace)
30
+ schema.instance_exec { own_instrumenters[:query] << CompiledQueries::Instrumentation }
31
+ else
32
+ schema.instrument :query, CompiledQueries::Instrumentation
33
+ end
34
+ end
35
+
36
+ def graphql_ruby_after_2_2_5?
37
+ check_graphql_version "> 2.2.5"
38
+ end
39
+
40
+ def check_graphql_version(predicate)
41
+ Gem::Dependency.new("graphql", predicate).match?("graphql", GraphQL::VERSION)
42
+ end
24
43
  end
25
44
 
26
45
  # Patches GraphQL::Schema to override multiplex (not needed for compiled queries)
@@ -12,7 +12,8 @@ module GraphQL
12
12
  @name = :base
13
13
  end
14
14
 
15
- def fetch_query(hash, compiled_query: false)
15
+ def fetch_query(hash, options = {})
16
+ compiled_query = options[:compiled_query] || false
16
17
  key = build_key(hash, compiled_query)
17
18
 
18
19
  fetch(key).tap do |result|
@@ -26,8 +27,6 @@ module GraphQL
26
27
  trace("save_query", adapter: @name) { save(key, query) }
27
28
  end
28
29
 
29
- protected
30
-
31
30
  def fetch(_hash)
32
31
  raise NotImplementedError
33
32
  end
@@ -17,8 +17,6 @@ module GraphQL
17
17
  @name = :memcached
18
18
  end
19
19
 
20
- protected
21
-
22
20
  def fetch(hash)
23
21
  @dalli_proc.call { |dalli| dalli.get(key_for(hash)) }
24
22
  end
@@ -10,8 +10,6 @@ module GraphQL
10
10
  @name = :memory
11
11
  end
12
12
 
13
- protected
14
-
15
13
  def fetch(hash)
16
14
  @storage[hash]
17
15
  end
@@ -17,8 +17,6 @@ module GraphQL
17
17
  @name = :redis
18
18
  end
19
19
 
20
- protected
21
-
22
20
  def fetch(hash)
23
21
  @redis_proc.call { |redis| redis.get(key_for(hash)) }
24
22
  end
@@ -22,29 +22,19 @@ module GraphQL
22
22
  @name = :redis_with_local_cache
23
23
  end
24
24
 
25
- # We don't need to implement our own traces for this adapter since the
26
- # underlying adapters will emit the proper events for us. However,
27
- # since tracers can be defined at any time, we need to pass them through.
28
- def tracers=(tracers)
29
- @memory_adapter.tracers = tracers
30
- @redis_adapter.tracers = tracers
31
- end
32
-
33
- protected
34
-
35
25
  def fetch(hash)
36
- result = @memory_adapter.fetch_query(hash)
26
+ result = @memory_adapter.fetch(hash)
37
27
  result ||= begin
38
- inner_result = @redis_adapter.fetch_query(hash)
39
- @memory_adapter.save_query(hash, inner_result) if inner_result
28
+ inner_result = @redis_adapter.fetch(hash)
29
+ @memory_adapter.save(hash, inner_result) if inner_result
40
30
  inner_result
41
31
  end
42
32
  result
43
33
  end
44
34
 
45
35
  def save(hash, query)
46
- @redis_adapter.save_query(hash, query)
47
- @memory_adapter.save_query(hash, query)
36
+ @redis_adapter.save(hash, query)
37
+ @memory_adapter.save(hash, query)
48
38
  end
49
39
 
50
40
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module PersistedQueries
5
- VERSION = "1.6.1"
5
+ VERSION = "1.8.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-persisted_queries
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2024-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -135,12 +135,15 @@ files:
135
135
  - docs/error_handling.md
136
136
  - docs/hash.md
137
137
  - docs/http_cache.md
138
+ - docs/skip_query_preprocessing.md
138
139
  - docs/tracing.md
139
140
  - gemfiles/graphql_1_12_0.gemfile
140
141
  - gemfiles/graphql_1_12_4.gemfile
141
142
  - gemfiles/graphql_1_13_16.gemfile
142
143
  - gemfiles/graphql_1_13_7.gemfile
143
144
  - gemfiles/graphql_2_0_0.gemfile
145
+ - gemfiles/graphql_2_1_0.gemfile
146
+ - gemfiles/graphql_2_2_5.gemfile
144
147
  - gemfiles/graphql_master.gemfile
145
148
  - graphql-persisted_queries.gemspec
146
149
  - lib/graphql/persisted_queries.rb
@@ -182,14 +185,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
185
  requirements:
183
186
  - - ">="
184
187
  - !ruby/object:Gem::Version
185
- version: '2.6'
188
+ version: '2.7'
186
189
  required_rubygems_version: !ruby/object:Gem::Requirement
187
190
  requirements:
188
191
  - - ">="
189
192
  - !ruby/object:Gem::Version
190
193
  version: '0'
191
194
  requirements: []
192
- rubygems_version: 3.3.7
195
+ rubygems_version: 3.4.6
193
196
  signing_key:
194
197
  specification_version: 4
195
198
  summary: Persisted queries for graphql-ruby