graphql-persisted_queries 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +2 -1
- data/CHANGELOG.md +12 -0
- data/README.md +9 -6
- data/gemfiles/graphql_1_13_16.gemfile +5 -0
- data/graphql-persisted_queries.gemspec +1 -1
- data/lib/graphql/persisted_queries/compiled_queries/instrumentation.rb +2 -14
- data/lib/graphql/persisted_queries/compiled_queries/query_patch.rb +14 -10
- data/lib/graphql/persisted_queries/store_adapters/base_store_adapter.rb +2 -3
- data/lib/graphql/persisted_queries/store_adapters/memcached_store_adapter.rb +0 -2
- data/lib/graphql/persisted_queries/store_adapters/memory_store_adapter.rb +0 -2
- data/lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb +0 -2
- data/lib/graphql/persisted_queries/store_adapters/redis_with_local_cache_store_adapter.rb +5 -15
- data/lib/graphql/persisted_queries/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 430993c73790f83784c3e048a8fa0a4032f2fa5809b725265b5600b6ca8b5a01
|
4
|
+
data.tar.gz: 10aaa0422835323129d2e771f9bcfa68c4b8d24563ff7b8fb0f341b29dc92dd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8cf0e07efa3c4a2ea92af6014333c3adc08f1471357b3cc31f1d93779e5af3920e7c71b308bff62f34366211fd5912baadd9780cc2978c9b4185582524f9181
|
7
|
+
data.tar.gz: f001860c11580ae570e25875f548a167ec878d87545befb39b7ee13a58385e2d2fda86a0919745030b915fed8bd84b3cc6200462c467b320e823cb43a9785047
|
data/.github/workflows/rspec.yml
CHANGED
@@ -18,11 +18,12 @@ jobs:
|
|
18
18
|
strategy:
|
19
19
|
fail-fast: false
|
20
20
|
matrix:
|
21
|
-
ruby: [2.
|
21
|
+
ruby: [2.7, '3.0', 3.1]
|
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
|
+
"gemfiles/graphql_1_13_16.gemfile",
|
26
27
|
"gemfiles/graphql_2_0_0.gemfile",
|
27
28
|
"gemfiles/graphql_master.gemfile"
|
28
29
|
]
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.7.0 (2023-02-02)
|
6
|
+
|
7
|
+
- [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62)
|
8
|
+
Fix double hashing of keys in case of redis_with_local_cache_store adapter ([@mpospelov][])
|
9
|
+
- [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62) Drop tracers= implementation as it's no longer valid ([@mpospelov][])
|
10
|
+
|
11
|
+
## 1.6.1 (2022-11-17)
|
12
|
+
|
13
|
+
- [PR#60](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/60)
|
14
|
+
Handle situations when prepare_ast happens before instrumentation ([@DmitryTsepelev][])
|
15
|
+
|
5
16
|
## 1.6.0 (2022-10-10)
|
6
17
|
|
7
18
|
- [PR#57](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/57) Refactor code to use instrumentation instead of a monkey patch, deprecate graphql-ruby 1.10 and 1.11 ([@DmitryTsepelev][])
|
@@ -107,3 +118,4 @@
|
|
107
118
|
[@ogidow]: https://github.com/ogidow
|
108
119
|
[@rbviz]: https://github.com/rbviz
|
109
120
|
[@louim]: https://github.com/louim
|
121
|
+
[@mpospelov]: https://github.com/mpospelov
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GraphQL::PersistedQueries
|
1
|
+
# GraphQL::PersistedQueries ![](https://ruby-gem-downloads-badge.herokuapp.com/graphql-persisted_queries?type=total)
|
2
2
|
|
3
3
|
`GraphQL::PersistedQueries` is the implementation of [persisted queries](https://www.apollographql.com/docs/react/api/link/persisted-queries/) for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby). With this plugin your backend will cache all the queries, while frontend will send the full query only when it's not found at the backend storage.
|
4
4
|
|
@@ -6,12 +6,11 @@
|
|
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:
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
</a>
|
14
|
-
</p>
|
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_ 🙂
|
15
14
|
|
16
15
|
## Getting started
|
17
16
|
|
@@ -92,6 +91,10 @@ An experimental tracing feature can be enabled by setting `tracing: true` when c
|
|
92
91
|
> 📖 Read more about the gem internals: [Persisted queries in GraphQL:
|
93
92
|
Slim down Apollo requests to your Ruby application](https://evilmartians.com/chronicles/persisted-queries-in-graphql-slim-down-apollo-requests-to-your-ruby-application)
|
94
93
|
|
94
|
+
## Credits
|
95
|
+
|
96
|
+
Initially sponsored by [Evil Martians](http://evilmartians.com).
|
97
|
+
|
95
98
|
## Contributing
|
96
99
|
|
97
100
|
Bug reports and pull requests are welcome on GitHub at https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries.
|
@@ -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.
|
23
|
+
spec.required_ruby_version = ">= 2.7"
|
24
24
|
|
25
25
|
spec.add_dependency "graphql", ">= 1.12"
|
26
26
|
|
@@ -10,26 +10,14 @@ module GraphQL
|
|
10
10
|
def before_query(query)
|
11
11
|
return unless query.context[:extensions]
|
12
12
|
|
13
|
-
|
14
|
-
if
|
15
|
-
query.fulfill_document(document)
|
16
|
-
else
|
17
|
-
query.not_loaded_document!
|
18
|
-
end
|
19
|
-
|
20
|
-
return if document || query.query_string
|
13
|
+
query.try_load_document!
|
14
|
+
return if query.document || query.query_string
|
21
15
|
|
22
16
|
query.persisted_query_not_found!
|
23
17
|
query.context.errors << GraphQL::ExecutionError.new(NotFound::MESSAGE)
|
24
18
|
end
|
25
19
|
|
26
20
|
def after_query(*); end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def resolver_for(query)
|
31
|
-
CompiledQueries::Resolver.new(query.schema, query.context[:extensions])
|
32
|
-
end
|
33
21
|
end
|
34
22
|
end
|
35
23
|
end
|
@@ -5,14 +5,6 @@ module GraphQL
|
|
5
5
|
module CompiledQueries
|
6
6
|
# Patches GraphQL::Query to support compiled queries
|
7
7
|
module QueryPatch
|
8
|
-
def fulfill_document(document)
|
9
|
-
@document = document
|
10
|
-
end
|
11
|
-
|
12
|
-
def not_loaded_document!
|
13
|
-
@not_loaded_document = true
|
14
|
-
end
|
15
|
-
|
16
8
|
def persisted_query_not_found!
|
17
9
|
@persisted_query_not_found = true
|
18
10
|
end
|
@@ -22,17 +14,29 @@ module GraphQL
|
|
22
14
|
end
|
23
15
|
|
24
16
|
def prepare_ast
|
25
|
-
return super
|
17
|
+
return super if @context[:extensions].nil? || @document
|
18
|
+
|
19
|
+
try_load_document!
|
26
20
|
|
27
21
|
super.tap do
|
28
22
|
if @context.errors.any?(&method(:not_found_error?))
|
29
23
|
@context.errors.select!(&method(:not_found_error?))
|
30
24
|
end
|
31
25
|
|
32
|
-
|
26
|
+
if @persisted_document_not_found && query_string
|
27
|
+
resolver.persist(query_string, @document)
|
28
|
+
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
32
|
+
def try_load_document!
|
33
|
+
return if @document || @persisted_document_not_found
|
34
|
+
|
35
|
+
compiled_query_resolver = CompiledQueries::Resolver.new(schema, context[:extensions])
|
36
|
+
@document = compiled_query_resolver.fetch
|
37
|
+
@persisted_document_not_found = @document.nil?
|
38
|
+
end
|
39
|
+
|
36
40
|
private
|
37
41
|
|
38
42
|
def resolver
|
@@ -12,7 +12,8 @@ module GraphQL
|
|
12
12
|
@name = :base
|
13
13
|
end
|
14
14
|
|
15
|
-
def fetch_query(hash,
|
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
|
@@ -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.
|
26
|
+
result = @memory_adapter.fetch(hash)
|
37
27
|
result ||= begin
|
38
|
-
inner_result = @redis_adapter.
|
39
|
-
@memory_adapter.
|
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.
|
47
|
-
@memory_adapter.
|
36
|
+
@redis_adapter.save(hash, query)
|
37
|
+
@memory_adapter.save(hash, query)
|
48
38
|
end
|
49
39
|
|
50
40
|
private
|
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.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- docs/tracing.md
|
139
139
|
- gemfiles/graphql_1_12_0.gemfile
|
140
140
|
- gemfiles/graphql_1_12_4.gemfile
|
141
|
+
- gemfiles/graphql_1_13_16.gemfile
|
141
142
|
- gemfiles/graphql_1_13_7.gemfile
|
142
143
|
- gemfiles/graphql_2_0_0.gemfile
|
143
144
|
- gemfiles/graphql_master.gemfile
|
@@ -181,14 +182,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
182
|
requirements:
|
182
183
|
- - ">="
|
183
184
|
- !ruby/object:Gem::Version
|
184
|
-
version: '2.
|
185
|
+
version: '2.7'
|
185
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
187
|
requirements:
|
187
188
|
- - ">="
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.4.1
|
192
193
|
signing_key:
|
193
194
|
specification_version: 4
|
194
195
|
summary: Persisted queries for graphql-ruby
|