graphql-stitching 1.0.5 → 1.0.6
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/docs/client.md +4 -4
- data/lib/graphql/stitching/client.rb +2 -2
- data/lib/graphql/stitching/composer.rb +8 -7
- data/lib/graphql/stitching/executor/boundary_source.rb +2 -1
- data/lib/graphql/stitching/request.rb +18 -14
- data/lib/graphql/stitching/skip_include.rb +5 -1
- data/lib/graphql/stitching/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbeabcd8c2327504cc5ccc613942d163bddddb2087e7eb90c966861777d67b9d
|
4
|
+
data.tar.gz: cf03589e91ef96fb8dc9b74ca2703c20095e586bab45f91a89b3579376edbdac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b5d6bbf4abccb99795c6225e1a61807ed74f94ad9ce5bdde0be534133e101c7d51f677d3c89aebaad7ebe2b125ff11a192a3d1a29cdacb3d3b51049801212f
|
7
|
+
data.tar.gz: ade024c4ace1474d9c7a7cd80fb8820fc71e456e566d89fe656d07bf4b64e60db83561546a908b5d2fcbec9d88ac740a7080946e981a74f7bd904b3da0aeebfb
|
data/docs/client.md
CHANGED
@@ -61,16 +61,16 @@ Arguments for the `execute` method include:
|
|
61
61
|
The client provides cache hooks to enable caching query plans across requests. Without caching, every request made to the client will be planned individually. With caching, a query may be planned once, cached, and then executed from cache for subsequent requests. Cache keys are a normalized digest of each query string.
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
client.on_cache_read do |key, _context|
|
64
|
+
client.on_cache_read do |key, _context, _request|
|
65
65
|
$redis.get(key) # << 3P code
|
66
66
|
end
|
67
67
|
|
68
|
-
client.on_cache_write do |key, payload, _context|
|
68
|
+
client.on_cache_write do |key, payload, _context, _request|
|
69
69
|
$redis.set(key, payload) # << 3P code
|
70
70
|
end
|
71
71
|
```
|
72
72
|
|
73
|
-
Note that inlined input data works against caching, so you should _avoid_ this:
|
73
|
+
Note that inlined input data works against caching, so you should _avoid_ this when possible:
|
74
74
|
|
75
75
|
```graphql
|
76
76
|
query {
|
@@ -78,7 +78,7 @@ query {
|
|
78
78
|
}
|
79
79
|
```
|
80
80
|
|
81
|
-
Instead,
|
81
|
+
Instead, leverage query variables so that the document body remains consistent across requests:
|
82
82
|
|
83
83
|
```graphql
|
84
84
|
query($id: ID!) {
|
@@ -75,14 +75,14 @@ module GraphQL
|
|
75
75
|
|
76
76
|
def fetch_plan(request)
|
77
77
|
if @on_cache_read
|
78
|
-
cached_plan = @on_cache_read.call(request.digest, request.context)
|
78
|
+
cached_plan = @on_cache_read.call(request.digest, request.context, request)
|
79
79
|
return GraphQL::Stitching::Plan.from_json(JSON.parse(cached_plan)) if cached_plan
|
80
80
|
end
|
81
81
|
|
82
82
|
plan = yield
|
83
83
|
|
84
84
|
if @on_cache_write
|
85
|
-
@on_cache_write.call(request.digest, JSON.generate(plan.as_json), request.context)
|
85
|
+
@on_cache_write.call(request.digest, JSON.generate(plan.as_json), request.context, request)
|
86
86
|
end
|
87
87
|
|
88
88
|
plan
|
@@ -53,7 +53,7 @@ module GraphQL
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
# "
|
56
|
+
# "directive_name" => merged_directive
|
57
57
|
@schema_directives = @candidate_directives_by_name_and_location.each_with_object({}) do |(directive_name, directives_by_location), memo|
|
58
58
|
memo[directive_name] = build_directive(directive_name, directives_by_location)
|
59
59
|
end
|
@@ -88,19 +88,20 @@ module GraphQL
|
|
88
88
|
|
89
89
|
# "Typename" => merged_type
|
90
90
|
schema_types = @candidate_types_by_name_and_location.each_with_object({}) do |(type_name, types_by_location), memo|
|
91
|
-
kinds = types_by_location.values.map { _1.kind.name }.uniq
|
91
|
+
kinds = types_by_location.values.map { _1.kind.name }.tap(&:uniq!)
|
92
92
|
|
93
93
|
if kinds.length > 1
|
94
94
|
raise ComposerError, "Cannot merge different kinds for `#{type_name}`. Found: #{kinds.join(", ")}."
|
95
95
|
end
|
96
96
|
|
97
|
+
extract_boundaries(type_name, types_by_location) if type_name == @query_name
|
98
|
+
|
97
99
|
memo[type_name] = case kinds.first
|
98
100
|
when "SCALAR"
|
99
101
|
build_scalar_type(type_name, types_by_location)
|
100
102
|
when "ENUM"
|
101
103
|
build_enum_type(type_name, types_by_location, enum_usage)
|
102
104
|
when "OBJECT"
|
103
|
-
extract_boundaries(type_name, types_by_location) if type_name == @query_name
|
104
105
|
build_object_type(type_name, types_by_location)
|
105
106
|
when "INTERFACE"
|
106
107
|
build_interface_type(type_name, types_by_location)
|
@@ -200,7 +201,7 @@ module GraphQL
|
|
200
201
|
graphql_name(directive_name)
|
201
202
|
description(builder.merge_descriptions(directive_name, directives_by_location))
|
202
203
|
repeatable(directives_by_location.values.any?(&:repeatable?))
|
203
|
-
locations(*directives_by_location.values.flat_map(&:locations).uniq)
|
204
|
+
locations(*directives_by_location.values.flat_map(&:locations).tap(&:uniq!))
|
204
205
|
builder.build_merged_arguments(directive_name, directives_by_location, self, directive_name: directive_name)
|
205
206
|
end
|
206
207
|
end
|
@@ -262,7 +263,7 @@ module GraphQL
|
|
262
263
|
description(builder.merge_descriptions(type_name, types_by_location))
|
263
264
|
|
264
265
|
interface_names = types_by_location.values.flat_map { _1.interfaces.map(&:graphql_name) }
|
265
|
-
interface_names.uniq.each do |interface_name|
|
266
|
+
interface_names.tap(&:uniq!).each do |interface_name|
|
266
267
|
implements(builder.build_type_binding(interface_name))
|
267
268
|
end
|
268
269
|
|
@@ -280,7 +281,7 @@ module GraphQL
|
|
280
281
|
description(builder.merge_descriptions(type_name, types_by_location))
|
281
282
|
|
282
283
|
interface_names = types_by_location.values.flat_map { _1.interfaces.map(&:graphql_name) }
|
283
|
-
interface_names.uniq.each do |interface_name|
|
284
|
+
interface_names.tap(&:uniq!).each do |interface_name|
|
284
285
|
implements(builder.build_type_binding(interface_name))
|
285
286
|
end
|
286
287
|
|
@@ -296,7 +297,7 @@ module GraphQL
|
|
296
297
|
graphql_name(type_name)
|
297
298
|
description(builder.merge_descriptions(type_name, types_by_location))
|
298
299
|
|
299
|
-
possible_names = types_by_location.values.flat_map { _1.possible_types.map(&:graphql_name) }.uniq
|
300
|
+
possible_names = types_by_location.values.flat_map { _1.possible_types.map(&:graphql_name) }.tap(&:uniq!)
|
300
301
|
possible_types(*possible_names.map { builder.build_type_binding(_1) })
|
301
302
|
builder.build_merged_directives(type_name, types_by_location, self)
|
302
303
|
end
|
@@ -4,14 +4,13 @@ module GraphQL
|
|
4
4
|
module Stitching
|
5
5
|
class Request
|
6
6
|
SUPPORTED_OPERATIONS = ["query", "mutation"].freeze
|
7
|
+
SKIP_INCLUDE_DIRECTIVE = /@(?:skip|include)/
|
7
8
|
|
8
9
|
attr_reader :document, :variables, :operation_name, :context
|
9
10
|
|
10
11
|
def initialize(document, operation_name: nil, variables: nil, context: nil)
|
11
|
-
@may_contain_runtime_directives = true
|
12
|
-
|
13
12
|
@document = if document.is_a?(String)
|
14
|
-
@
|
13
|
+
@string = document
|
15
14
|
GraphQL.parse(document)
|
16
15
|
else
|
17
16
|
document
|
@@ -23,13 +22,21 @@ module GraphQL
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def string
|
26
|
-
@string
|
25
|
+
@string || normalized_string
|
26
|
+
end
|
27
|
+
|
28
|
+
def normalized_string
|
29
|
+
@normalized_string ||= @document.to_query_string
|
27
30
|
end
|
28
31
|
|
29
32
|
def digest
|
30
33
|
@digest ||= Digest::SHA2.hexdigest(string)
|
31
34
|
end
|
32
35
|
|
36
|
+
def normalized_digest
|
37
|
+
@normalized_digest ||= Digest::SHA2.hexdigest(normalized_string)
|
38
|
+
end
|
39
|
+
|
33
40
|
def operation
|
34
41
|
@operation ||= begin
|
35
42
|
operation_defs = @document.definitions.select do |d|
|
@@ -69,18 +76,15 @@ module GraphQL
|
|
69
76
|
|
70
77
|
def prepare!
|
71
78
|
operation.variables.each do |v|
|
72
|
-
@variables[v.name] = v.default_value if @variables[v.name].nil?
|
79
|
+
@variables[v.name] = v.default_value if @variables[v.name].nil? && !v.default_value.nil?
|
73
80
|
end
|
74
81
|
|
75
|
-
if @
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
@
|
80
|
-
@
|
81
|
-
@operation = nil
|
82
|
-
@variable_definitions = nil
|
83
|
-
@fragment_definitions = nil
|
82
|
+
if @string.nil? || @string.match?(SKIP_INCLUDE_DIRECTIVE)
|
83
|
+
SkipInclude.render(@document, @variables) do |modified_ast|
|
84
|
+
@document = modified_ast
|
85
|
+
@string = @normalized_string = nil
|
86
|
+
@digest = @normalized_digest = nil
|
87
|
+
@operation = @operation_directives = @variable_definitions = nil
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
@@ -15,7 +15,11 @@ module GraphQL
|
|
15
15
|
definition
|
16
16
|
end
|
17
17
|
|
18
|
-
return document
|
18
|
+
return document unless changed
|
19
|
+
|
20
|
+
document = document.merge(definitions: definitions)
|
21
|
+
yield(document) if block_given?
|
22
|
+
document
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-stitching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg MacWilliam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|