graphql-stitching 1.4.3 → 1.5.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 +4 -4
- data/.gitignore +4 -0
- data/README.md +4 -2
- data/docs/README.md +1 -0
- data/docs/composer.md +1 -1
- data/docs/subscriptions.md +208 -0
- data/examples/subscriptions/.gitattributes +9 -0
- data/examples/subscriptions/.gitignore +35 -0
- data/examples/subscriptions/Gemfile +65 -0
- data/examples/subscriptions/README.md +38 -0
- data/examples/subscriptions/Rakefile +6 -0
- data/examples/subscriptions/app/channels/graphql_channel.rb +50 -0
- data/examples/subscriptions/app/controllers/graphql_controller.rb +44 -0
- data/examples/subscriptions/app/graphql/entities_schema.rb +42 -0
- data/examples/subscriptions/app/graphql/stitched_schema.rb +10 -0
- data/examples/subscriptions/app/graphql/subscriptions_schema.rb +54 -0
- data/examples/subscriptions/app/models/repository.rb +39 -0
- data/examples/subscriptions/app/views/graphql/client.html.erb +159 -0
- data/examples/subscriptions/bin/bundle +109 -0
- data/examples/subscriptions/bin/docker-entrypoint +8 -0
- data/examples/subscriptions/bin/importmap +4 -0
- data/examples/subscriptions/bin/rails +4 -0
- data/examples/subscriptions/bin/rake +4 -0
- data/examples/subscriptions/bin/setup +33 -0
- data/examples/subscriptions/config/application.rb +14 -0
- data/examples/subscriptions/config/boot.rb +4 -0
- data/examples/subscriptions/config/cable.yml +10 -0
- data/examples/subscriptions/config/credentials.yml.enc +1 -0
- data/examples/subscriptions/config/database.yml +25 -0
- data/examples/subscriptions/config/environment.rb +5 -0
- data/examples/subscriptions/config/environments/development.rb +74 -0
- data/examples/subscriptions/config/environments/production.rb +91 -0
- data/examples/subscriptions/config/environments/test.rb +64 -0
- data/examples/subscriptions/config/initializers/content_security_policy.rb +25 -0
- data/examples/subscriptions/config/initializers/filter_parameter_logging.rb +8 -0
- data/examples/subscriptions/config/initializers/inflections.rb +16 -0
- data/examples/subscriptions/config/initializers/permissions_policy.rb +13 -0
- data/examples/subscriptions/config/locales/en.yml +31 -0
- data/examples/subscriptions/config/master.key +1 -0
- data/examples/subscriptions/config/puma.rb +35 -0
- data/examples/subscriptions/config/routes.rb +8 -0
- data/examples/subscriptions/config/storage.yml +34 -0
- data/examples/subscriptions/config.ru +6 -0
- data/examples/subscriptions/db/seeds.rb +9 -0
- data/examples/subscriptions/public/404.html +17 -0
- data/examples/subscriptions/public/422.html +17 -0
- data/examples/subscriptions/public/500.html +16 -0
- data/examples/subscriptions/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/subscriptions/public/apple-touch-icon.png +0 -0
- data/examples/subscriptions/public/favicon.ico +0 -0
- data/examples/subscriptions/public/robots.txt +1 -0
- data/lib/graphql/stitching/client.rb +18 -11
- data/lib/graphql/stitching/composer/resolver_config.rb +1 -1
- data/lib/graphql/stitching/composer/validate_resolvers.rb +7 -1
- data/lib/graphql/stitching/composer.rb +30 -27
- data/lib/graphql/stitching/executor/shaper.rb +1 -1
- data/lib/graphql/stitching/executor.rb +19 -11
- data/lib/graphql/stitching/http_executable.rb +3 -0
- data/lib/graphql/stitching/plan.rb +1 -1
- data/lib/graphql/stitching/planner.rb +21 -5
- data/lib/graphql/stitching/{skip_include.rb → request/skip_include.rb} +2 -2
- data/lib/graphql/stitching/request.rb +42 -4
- data/lib/graphql/stitching/resolver/arguments.rb +2 -2
- data/lib/graphql/stitching/resolver/keys.rb +2 -3
- data/lib/graphql/stitching/resolver.rb +3 -3
- data/lib/graphql/stitching/supergraph.rb +5 -2
- data/lib/graphql/stitching/util.rb +1 -0
- data/lib/graphql/stitching/version.rb +1 -1
- data/lib/graphql/stitching.rb +17 -1
- metadata +49 -3
@@ -1,9 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "request/skip_include"
|
4
|
+
|
3
5
|
module GraphQL
|
4
6
|
module Stitching
|
7
|
+
# Request combines a supergraph, GraphQL document, variables,
|
8
|
+
# variable/fragment definitions, and the selected operation.
|
9
|
+
# It provides the lifecycle of validating, preparing,
|
10
|
+
# planning, and executing upon these inputs.
|
5
11
|
class Request
|
6
|
-
SUPPORTED_OPERATIONS = ["query", "mutation"].freeze
|
7
12
|
SKIP_INCLUDE_DIRECTIVE = /@(?:skip|include)/
|
8
13
|
|
9
14
|
# @return [Supergraph] supergraph instance that resolves the request.
|
@@ -83,7 +88,6 @@ module GraphQL
|
|
83
88
|
@operation ||= begin
|
84
89
|
operation_defs = @document.definitions.select do |d|
|
85
90
|
next unless d.is_a?(GraphQL::Language::Nodes::OperationDefinition)
|
86
|
-
next unless SUPPORTED_OPERATIONS.include?(d.operation_type)
|
87
91
|
@operation_name ? d.name == @operation_name : true
|
88
92
|
end
|
89
93
|
|
@@ -97,6 +101,21 @@ module GraphQL
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
104
|
+
# @return [Boolean] true if operation type is a query
|
105
|
+
def query?
|
106
|
+
operation.operation_type == QUERY_OP
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Boolean] true if operation type is a mutation
|
110
|
+
def mutation?
|
111
|
+
operation.operation_type == MUTATION_OP
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [Boolean] true if operation type is a subscription
|
115
|
+
def subscription?
|
116
|
+
operation.operation_type == SUBSCRIPTION_OP
|
117
|
+
end
|
118
|
+
|
100
119
|
# @return [String] A string of directives applied to the root operation. These are passed through in all subgraph requests.
|
101
120
|
def operation_directives
|
102
121
|
@operation_directives ||= if operation.directives.any?
|
@@ -162,7 +181,7 @@ module GraphQL
|
|
162
181
|
raise StitchingError, "Plan must be a `GraphQL::Stitching::Plan`." unless new_plan.is_a?(Plan)
|
163
182
|
@plan = new_plan
|
164
183
|
else
|
165
|
-
@plan ||=
|
184
|
+
@plan ||= Planner.new(self).perform
|
166
185
|
end
|
167
186
|
end
|
168
187
|
|
@@ -170,7 +189,26 @@ module GraphQL
|
|
170
189
|
# @param raw [Boolean] specifies the result should be unshaped without pruning or null bubbling. Useful for debugging.
|
171
190
|
# @return [Hash] the rendered GraphQL response with "data" and "errors" sections.
|
172
191
|
def execute(raw: false)
|
173
|
-
|
192
|
+
add_subscription_update_handler if subscription?
|
193
|
+
Executor.new(self).perform(raw: raw)
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
# Adds a handler into context for enriching subscription updates with stitched data
|
199
|
+
def add_subscription_update_handler
|
200
|
+
request = self
|
201
|
+
@context[:stitch_subscription_update] = -> (result) {
|
202
|
+
stitched_result = Executor.new(
|
203
|
+
request,
|
204
|
+
data: result.to_h["data"] || {},
|
205
|
+
errors: result.to_h["errors"] || [],
|
206
|
+
after: request.plan.ops.first.step,
|
207
|
+
).perform
|
208
|
+
|
209
|
+
result.to_h.merge!(stitched_result.to_h)
|
210
|
+
result
|
211
|
+
}
|
174
212
|
end
|
175
213
|
end
|
176
214
|
end
|
@@ -130,8 +130,8 @@ module GraphQL::Stitching
|
|
130
130
|
|
131
131
|
def verify_key(arg, key)
|
132
132
|
key_field = value.reduce(Resolver::KeyField.new("", inner: key)) do |field, ns|
|
133
|
-
if ns ==
|
134
|
-
Resolver::KeyField.new(
|
133
|
+
if ns == TYPENAME
|
134
|
+
Resolver::KeyField.new(TYPENAME)
|
135
135
|
elsif field
|
136
136
|
field.inner.find { _1.name == ns }
|
137
137
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module GraphQL::Stitching
|
4
4
|
class Resolver
|
5
5
|
EXPORT_PREFIX = "_export_"
|
6
|
-
TYPE_NAME = "__typename"
|
7
6
|
|
8
7
|
class FieldNode
|
9
8
|
# GraphQL Ruby changed the argument assigning Field.alias from
|
@@ -59,8 +58,8 @@ module GraphQL::Stitching
|
|
59
58
|
|
60
59
|
EMPTY_FIELD_SET = KeyFieldSet.new(GraphQL::Stitching::EMPTY_ARRAY)
|
61
60
|
TYPENAME_EXPORT_NODE = FieldNode.build(
|
62
|
-
field_alias: "#{EXPORT_PREFIX}#{
|
63
|
-
field_name:
|
61
|
+
field_alias: "#{EXPORT_PREFIX}#{TYPENAME}",
|
62
|
+
field_name: TYPENAME,
|
64
63
|
)
|
65
64
|
|
66
65
|
class Key < KeyFieldSet
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
4
|
-
require_relative "
|
3
|
+
require_relative "resolver/arguments"
|
4
|
+
require_relative "resolver/keys"
|
5
5
|
|
6
6
|
module GraphQL
|
7
7
|
module Stitching
|
8
|
-
# Defines a
|
8
|
+
# Defines a type resolver query that provides direct access to an entity type.
|
9
9
|
class Resolver
|
10
10
|
extend ArgumentsParser
|
11
11
|
extend KeysParser
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "supergraph/to_definition"
|
4
4
|
|
5
5
|
module GraphQL
|
6
6
|
module Stitching
|
7
|
+
# Supergraph is the singuar representation of a stitched graph.
|
8
|
+
# It provides the combined GraphQL schema and delegation maps
|
9
|
+
# used to route selections across subgraph locations.
|
7
10
|
class Supergraph
|
8
11
|
SUPERGRAPH_LOCATION = "__super"
|
9
12
|
|
@@ -100,7 +103,7 @@ module GraphQL
|
|
100
103
|
executable.execute(
|
101
104
|
query: source,
|
102
105
|
variables: variables,
|
103
|
-
context: request.context.
|
106
|
+
context: request.context.to_h,
|
104
107
|
validate: false,
|
105
108
|
)
|
106
109
|
elsif executable.respond_to?(:call)
|
data/lib/graphql/stitching.rb
CHANGED
@@ -4,7 +4,22 @@ require "graphql"
|
|
4
4
|
|
5
5
|
module GraphQL
|
6
6
|
module Stitching
|
7
|
+
# scope name of query operations.
|
8
|
+
QUERY_OP = "query"
|
9
|
+
|
10
|
+
# scope name of mutation operations.
|
11
|
+
MUTATION_OP = "mutation"
|
12
|
+
|
13
|
+
# scope name of subscription operations.
|
14
|
+
SUBSCRIPTION_OP = "subscription"
|
15
|
+
|
16
|
+
# introspection typename field.
|
17
|
+
TYPENAME = "__typename"
|
18
|
+
|
19
|
+
# @api private
|
7
20
|
EMPTY_OBJECT = {}.freeze
|
21
|
+
|
22
|
+
# @api private
|
8
23
|
EMPTY_ARRAY = [].freeze
|
9
24
|
|
10
25
|
class StitchingError < StandardError; end
|
@@ -18,6 +33,8 @@ module GraphQL
|
|
18
33
|
|
19
34
|
attr_writer :stitch_directive
|
20
35
|
|
36
|
+
# Names of stitching directives to omit from the composed supergraph.
|
37
|
+
# @returns [Array<String>] list of stitching directive names.
|
21
38
|
def stitching_directive_names
|
22
39
|
[stitch_directive]
|
23
40
|
end
|
@@ -34,6 +51,5 @@ require_relative "stitching/plan"
|
|
34
51
|
require_relative "stitching/planner"
|
35
52
|
require_relative "stitching/request"
|
36
53
|
require_relative "stitching/resolver"
|
37
|
-
require_relative "stitching/skip_include"
|
38
54
|
require_relative "stitching/util"
|
39
55
|
require_relative "stitching/version"
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg MacWilliam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- docs/mechanics.md
|
91
91
|
- docs/request.md
|
92
92
|
- docs/resolver.md
|
93
|
+
- docs/subscriptions.md
|
93
94
|
- docs/supergraph.md
|
94
95
|
- examples/file_uploads/Gemfile
|
95
96
|
- examples/file_uploads/Procfile
|
@@ -105,6 +106,51 @@ files:
|
|
105
106
|
- examples/merged_types/graphiql.html
|
106
107
|
- examples/merged_types/remote1.rb
|
107
108
|
- examples/merged_types/remote2.rb
|
109
|
+
- examples/subscriptions/.gitattributes
|
110
|
+
- examples/subscriptions/.gitignore
|
111
|
+
- examples/subscriptions/Gemfile
|
112
|
+
- examples/subscriptions/README.md
|
113
|
+
- examples/subscriptions/Rakefile
|
114
|
+
- examples/subscriptions/app/channels/graphql_channel.rb
|
115
|
+
- examples/subscriptions/app/controllers/graphql_controller.rb
|
116
|
+
- examples/subscriptions/app/graphql/entities_schema.rb
|
117
|
+
- examples/subscriptions/app/graphql/stitched_schema.rb
|
118
|
+
- examples/subscriptions/app/graphql/subscriptions_schema.rb
|
119
|
+
- examples/subscriptions/app/models/repository.rb
|
120
|
+
- examples/subscriptions/app/views/graphql/client.html.erb
|
121
|
+
- examples/subscriptions/bin/bundle
|
122
|
+
- examples/subscriptions/bin/docker-entrypoint
|
123
|
+
- examples/subscriptions/bin/importmap
|
124
|
+
- examples/subscriptions/bin/rails
|
125
|
+
- examples/subscriptions/bin/rake
|
126
|
+
- examples/subscriptions/bin/setup
|
127
|
+
- examples/subscriptions/config.ru
|
128
|
+
- examples/subscriptions/config/application.rb
|
129
|
+
- examples/subscriptions/config/boot.rb
|
130
|
+
- examples/subscriptions/config/cable.yml
|
131
|
+
- examples/subscriptions/config/credentials.yml.enc
|
132
|
+
- examples/subscriptions/config/database.yml
|
133
|
+
- examples/subscriptions/config/environment.rb
|
134
|
+
- examples/subscriptions/config/environments/development.rb
|
135
|
+
- examples/subscriptions/config/environments/production.rb
|
136
|
+
- examples/subscriptions/config/environments/test.rb
|
137
|
+
- examples/subscriptions/config/initializers/content_security_policy.rb
|
138
|
+
- examples/subscriptions/config/initializers/filter_parameter_logging.rb
|
139
|
+
- examples/subscriptions/config/initializers/inflections.rb
|
140
|
+
- examples/subscriptions/config/initializers/permissions_policy.rb
|
141
|
+
- examples/subscriptions/config/locales/en.yml
|
142
|
+
- examples/subscriptions/config/master.key
|
143
|
+
- examples/subscriptions/config/puma.rb
|
144
|
+
- examples/subscriptions/config/routes.rb
|
145
|
+
- examples/subscriptions/config/storage.yml
|
146
|
+
- examples/subscriptions/db/seeds.rb
|
147
|
+
- examples/subscriptions/public/404.html
|
148
|
+
- examples/subscriptions/public/422.html
|
149
|
+
- examples/subscriptions/public/500.html
|
150
|
+
- examples/subscriptions/public/apple-touch-icon-precomposed.png
|
151
|
+
- examples/subscriptions/public/apple-touch-icon.png
|
152
|
+
- examples/subscriptions/public/favicon.ico
|
153
|
+
- examples/subscriptions/public/robots.txt
|
108
154
|
- gemfiles/graphql_1.13.9.gemfile
|
109
155
|
- gemfiles/graphql_2.0.0.gemfile
|
110
156
|
- gemfiles/graphql_2.1.0.gemfile
|
@@ -126,10 +172,10 @@ files:
|
|
126
172
|
- lib/graphql/stitching/planner.rb
|
127
173
|
- lib/graphql/stitching/planner/step.rb
|
128
174
|
- lib/graphql/stitching/request.rb
|
175
|
+
- lib/graphql/stitching/request/skip_include.rb
|
129
176
|
- lib/graphql/stitching/resolver.rb
|
130
177
|
- lib/graphql/stitching/resolver/arguments.rb
|
131
178
|
- lib/graphql/stitching/resolver/keys.rb
|
132
|
-
- lib/graphql/stitching/skip_include.rb
|
133
179
|
- lib/graphql/stitching/supergraph.rb
|
134
180
|
- lib/graphql/stitching/supergraph/key_directive.rb
|
135
181
|
- lib/graphql/stitching/supergraph/resolver_directive.rb
|