graphql-stitching 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/graphql/stitching/planner.rb +9 -9
- data/lib/graphql/stitching/shaper.rb +8 -2
- 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: 10489fd6a8670d5a23a7afa132d7941a242848783f3697a4d3ddd519b208a4d8
|
4
|
+
data.tar.gz: 7a2e8dda124bdc6e96da43e1a4ed64bbb4baeaf0065f6d8411edaeba2c52e064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9243880e3b41fcede7fddb5947a962f1d4c43882ba07cc0ab63d1ba154527ef4cc8e5cc130bb2524b40fcbe093ecfd2f3b8fb0bafc9a2a7324050c30d2af00
|
7
|
+
data.tar.gz: a2b37c3ab8b98065a0910a458e177b71576c5d8f52c6f6eba0e31d25ae7797f1517a168aeef2f39c7295d27e4f981373b7a90066dc7ab8651670ecbd41fc70d5
|
data/README.md
CHANGED
@@ -305,13 +305,13 @@ class MyExecutable
|
|
305
305
|
end
|
306
306
|
```
|
307
307
|
|
308
|
-
A [Supergraph](./docs/supergraph.md) is composed with executable
|
308
|
+
A [Supergraph](./docs/supergraph.md) is composed with executable resources provided for each location. Any location that omits the `executable` option will use the provided `schema` as its default executable:
|
309
309
|
|
310
310
|
```ruby
|
311
311
|
supergraph = GraphQL::Stitching::Composer.new.perform({
|
312
312
|
first: {
|
313
313
|
schema: FirstSchema,
|
314
|
-
# executable
|
314
|
+
# executable:^^^^^^ delegates to FirstSchema,
|
315
315
|
},
|
316
316
|
second: {
|
317
317
|
schema: SecondSchema,
|
@@ -53,18 +53,16 @@ module GraphQL
|
|
53
53
|
|
54
54
|
when "mutation"
|
55
55
|
parent_type = @supergraph.schema.mutation
|
56
|
-
location_groups = []
|
57
56
|
|
58
|
-
@request.operation.selections.
|
57
|
+
location_groups = @request.operation.selections.each_with_object([]) do |node, memo|
|
59
58
|
# root fields currently just delegate to the last location that defined them; this should probably be smarter
|
60
59
|
next_location = @supergraph.locations_by_type_and_field[parent_type.graphql_name][node.name].last
|
61
60
|
|
62
|
-
if
|
63
|
-
|
61
|
+
if memo.none? || memo.last[:location] != next_location
|
62
|
+
memo << { location: next_location, selections: [] }
|
64
63
|
end
|
65
64
|
|
66
|
-
|
67
|
-
next_location
|
65
|
+
memo.last[:selections] << node
|
68
66
|
end
|
69
67
|
|
70
68
|
location_groups.reduce(0) do |after_key, group|
|
@@ -144,7 +142,7 @@ module GraphQL
|
|
144
142
|
implements_fragments = false
|
145
143
|
|
146
144
|
if parent_type.kind.interface?
|
147
|
-
expand_interface_selections(current_location, parent_type, input_selections)
|
145
|
+
input_selections = expand_interface_selections(current_location, parent_type, input_selections)
|
148
146
|
end
|
149
147
|
|
150
148
|
input_selections.each do |node|
|
@@ -328,8 +326,8 @@ module GraphQL
|
|
328
326
|
local_interface_fields = @supergraph.fields_by_type_and_location[parent_type.graphql_name][current_location]
|
329
327
|
|
330
328
|
expanded_selections = nil
|
331
|
-
input_selections.reject
|
332
|
-
if node.is_a?(GraphQL::Language::Nodes::Field) && !local_interface_fields.include?(node.name)
|
329
|
+
input_selections = input_selections.reject do |node|
|
330
|
+
if node.is_a?(GraphQL::Language::Nodes::Field) && node.name != "__typename" && !local_interface_fields.include?(node.name)
|
333
331
|
expanded_selections ||= []
|
334
332
|
expanded_selections << node
|
335
333
|
true
|
@@ -344,6 +342,8 @@ module GraphQL
|
|
344
342
|
input_selections << GraphQL::Language::Nodes::InlineFragment.new(type: type_name, selections: expanded_selections)
|
345
343
|
end
|
346
344
|
end
|
345
|
+
|
346
|
+
input_selections
|
347
347
|
end
|
348
348
|
|
349
349
|
# expand concrete type selections into typed fragments when sending to abstract boundaries
|
@@ -42,15 +42,16 @@ module GraphQL
|
|
42
42
|
return nil if raw_object[field_name].nil? && node_type.non_null?
|
43
43
|
|
44
44
|
when GraphQL::Language::Nodes::InlineFragment
|
45
|
-
next unless typename == node.type.name
|
46
45
|
fragment_type = @schema.types[node.type.name]
|
46
|
+
next unless fragment_matches_typename?(fragment_type, typename)
|
47
|
+
|
47
48
|
result = resolve_object_scope(raw_object, fragment_type, node.selections, typename)
|
48
49
|
return nil if result.nil?
|
49
50
|
|
50
51
|
when GraphQL::Language::Nodes::FragmentSpread
|
51
52
|
fragment = @request.fragment_definitions[node.name]
|
52
53
|
fragment_type = @schema.types[fragment.type.name]
|
53
|
-
next unless typename
|
54
|
+
next unless fragment_matches_typename?(fragment_type, typename)
|
54
55
|
|
55
56
|
result = resolve_object_scope(raw_object, fragment_type, fragment.selections, typename)
|
56
57
|
return nil if result.nil?
|
@@ -91,6 +92,11 @@ module GraphQL
|
|
91
92
|
|
92
93
|
resolved_list
|
93
94
|
end
|
95
|
+
|
96
|
+
def fragment_matches_typename?(fragment_type, typename)
|
97
|
+
return true if fragment_type.graphql_name == typename
|
98
|
+
fragment_type.kind.interface? && @schema.possible_types(fragment_type).any? { _1.graphql_name == typename }
|
99
|
+
end
|
94
100
|
end
|
95
101
|
end
|
96
102
|
end
|
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: 0.3.
|
4
|
+
version: 0.3.1
|
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
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|