lighthouse-graphql 0.7.3 → 0.8.1
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/CHANGELOG.md +120 -1
- data/docs/authorization.md +46 -3
- data/docs/configuration.md +38 -0
- data/docs/directives.md +44 -0
- data/docs/events.md +17 -3
- data/docs/getting-started.md +63 -10
- data/docs/performance.md +9 -0
- data/docs/relay.md +6 -2
- data/docs/uploads.md +28 -2
- data/lib/lighthouse/config.rb +19 -5
- data/lib/lighthouse/controller.rb +6 -67
- data/lib/lighthouse/directive_resolvers/argument_transforms_resolver.rb +7 -1
- data/lib/lighthouse/directive_resolvers/attachment_resolver.rb +139 -0
- data/lib/lighthouse/directive_resolvers/auth_resolver.rb +1 -1
- data/lib/lighthouse/directive_resolvers/can_resolvers.rb +29 -5
- data/lib/lighthouse/directive_resolvers/guard_resolver.rb +4 -3
- data/lib/lighthouse/directives/registry.rb +1 -1
- data/lib/lighthouse/directives/soft_deletes_directive.rb +23 -6
- data/lib/lighthouse/errors.rb +17 -3
- data/lib/lighthouse/events/execution_trace.rb +2 -2
- data/lib/lighthouse/events/lifecycle.rb +20 -6
- data/lib/lighthouse/field_resolver_stack.rb +32 -0
- data/lib/lighthouse/global_id.rb +16 -5
- data/lib/lighthouse/graphql/version.rb +1 -1
- data/lib/lighthouse/operations.rb +111 -0
- data/lib/lighthouse/pagination.rb +21 -1
- data/lib/lighthouse/persisted_queries/manifest.rb +40 -0
- data/lib/lighthouse/persisted_queries.rb +9 -27
- data/lib/lighthouse/railtie.rb +8 -1
- data/lib/lighthouse/rb_lighthouse.rb +6 -0
- data/lib/lighthouse/relation_batch.rb +1 -1
- data/lib/lighthouse/schema_generator.rb +2 -0
- data/lib/lighthouse/schema_printer.rb +100 -0
- data/lib/lighthouse/schema_report.rb +161 -0
- data/lib/lighthouse/server_directives.rb +63 -0
- data/lib/lighthouse/tasks/lighthouse.rake +25 -6
- data/lib/lighthouse/upload.rb +2 -1
- data/lib/lighthouse/upload_store.rb +53 -2
- data/sig/lighthouse/controller.rbs +23 -11
- data/sig/lighthouse/directives.rbs +51 -18
- data/sig/lighthouse/events.rbs +52 -27
- data/sig/lighthouse/graphql.rbs +29 -24
- data/sig/lighthouse.rbs +207 -20
- metadata +7 -1
|
@@ -7,12 +7,31 @@ namespace :lighthouse do
|
|
|
7
7
|
Lighthouse::IdeHelper.write(output_dir: output_dir).each { |path| puts "Wrote #{path}" }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
desc 'Print the
|
|
10
|
+
desc 'Print the schema clients see (SCHEMA=AppSchema FORMAT=sdl|json|federation; WRITE=1 or WRITE=path writes a file)'
|
|
11
11
|
task print_schema: :environment do
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
printer = Lighthouse::GraphQL::SchemaPrinter
|
|
13
|
+
output = printer.output
|
|
14
|
+
schema = printer.app_schema(ENV.fetch('SCHEMA', nil))
|
|
15
|
+
format = ENV.fetch('FORMAT') { ENV['WRITE'] == '1' && output ? output[:format] : 'sdl' }
|
|
16
|
+
content = printer.print(schema, format: format)
|
|
17
|
+
if (write = ENV.fetch('WRITE', nil))
|
|
18
|
+
path = write == '1' ? (output&.fetch(:path) || Rails.root.join(printer::FILENAMES.fetch(format))) : Rails.root.join(write)
|
|
19
|
+
puts printer.write(path, content) ? "Wrote #{path}" : "#{path} is up to date"
|
|
20
|
+
else
|
|
21
|
+
puts content
|
|
22
|
+
end
|
|
14
23
|
rescue StandardError => e
|
|
15
|
-
abort("#{schema || '
|
|
24
|
+
abort("#{schema || 'The schema'} can not be printed: #{e.message}")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
namespace :schema_output do
|
|
28
|
+
desc 'Fail when the file config.schema_output names is missing or out of date (for CI)'
|
|
29
|
+
task verify: :environment do
|
|
30
|
+
printer = Lighthouse::GraphQL::SchemaPrinter
|
|
31
|
+
output = printer.output || abort('config.schema_output is not set.')
|
|
32
|
+
abort("#{output[:path]} is out of date: run bin/rails lighthouse:print_schema WRITE=1") if printer.stale?(output)
|
|
33
|
+
puts "#{output[:path]} is up to date."
|
|
34
|
+
end
|
|
16
35
|
end
|
|
17
36
|
|
|
18
37
|
desc 'Build the schema cache in tmp/cache (for config.schema_cache; e.g. during a Docker build)'
|
|
@@ -28,7 +47,7 @@ namespace :lighthouse do
|
|
|
28
47
|
|
|
29
48
|
desc 'Build the schema, dispatch the ValidateSchema event and check graphql-ruby accepts it (SCHEMA=AppSchema)'
|
|
30
49
|
task validate_schema: :environment do
|
|
31
|
-
schema =
|
|
50
|
+
schema = Lighthouse::GraphQL::SchemaPrinter.app_schema(ENV.fetch('SCHEMA', nil))
|
|
32
51
|
Lighthouse::Events.dispatch(Lighthouse::Events::ValidateSchema.new(schema))
|
|
33
52
|
schema.to_definition # builds every type: unresolvable references and duplicate names raise
|
|
34
53
|
puts "#{schema} is valid."
|
|
@@ -39,7 +58,7 @@ namespace :lighthouse do
|
|
|
39
58
|
namespace :persisted_queries do
|
|
40
59
|
desc 'Validate every operation of the persisted query manifest against the schema (SCHEMA=AppSchema)'
|
|
41
60
|
task verify: :environment do
|
|
42
|
-
schema =
|
|
61
|
+
schema = Lighthouse::GraphQL::SchemaPrinter.app_schema(ENV.fetch('SCHEMA', nil))
|
|
43
62
|
failures = Lighthouse::GraphQL::PersistedQueries.manifest.filter_map do |hash, body|
|
|
44
63
|
errors = schema.validate(body)
|
|
45
64
|
"#{hash}: #{errors.map(&:message).join('; ')}" if errors.any?
|
data/lib/lighthouse/upload.rb
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
class Lighthouse::GraphQL::Upload < GraphQL::Schema::Scalar
|
|
11
11
|
graphql_name 'Upload'
|
|
12
12
|
|
|
13
|
+
# An optional Upload the client sets to null stays null.
|
|
13
14
|
def self.coerce_input(value, _context)
|
|
14
|
-
return value if file?(value)
|
|
15
|
+
return value if value.nil? || file?(value)
|
|
15
16
|
|
|
16
17
|
raise ::GraphQL::CoercionError,
|
|
17
18
|
'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: ' \
|
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
# which a has_one_attached / has_many_attached attribute attaches (where Laravel
|
|
11
11
|
# hands the stored path, for a model to keep). To store files elsewhere, declare
|
|
12
12
|
# an ActiveStorage service for it, as a Laravel app declares a disk.
|
|
13
|
+
#
|
|
14
|
+
# A blob is stored before the field resolves (after @guard, @can* and
|
|
15
|
+
# @validator), and the model's own validations run after. When the field
|
|
16
|
+
# fails, the blobs it stored are purged, so a refused mutation leaves no blob
|
|
17
|
+
# and no file behind: see purge_on_failure.
|
|
13
18
|
module Lighthouse::GraphQL::UploadStore
|
|
19
|
+
# The fiber-local list of the blobs stored for the field resolving: graphql-ruby's
|
|
20
|
+
# dataloader runs each field in a fiber of its own.
|
|
21
|
+
STORED = :lighthouse_uploads_stored
|
|
22
|
+
|
|
14
23
|
module_function
|
|
15
24
|
|
|
16
25
|
def call(file, argument:, disk: nil, path: nil, public: nil)
|
|
@@ -23,9 +32,51 @@ module Lighthouse::GraphQL::UploadStore
|
|
|
23
32
|
|
|
24
33
|
service = service(argument, disk, public == true)
|
|
25
34
|
file.rewind if file.respond_to?(:rewind) # a @validator, or another argument the multipart map sent it to, may have read it
|
|
26
|
-
::ActiveStorage::Blob.create_and_upload!(
|
|
35
|
+
blob = ::ActiveStorage::Blob.create_and_upload!(
|
|
27
36
|
io: file, filename: filename(file), content_type: file.try(:content_type), key: key(path), service_name: service.name
|
|
28
|
-
)
|
|
37
|
+
)
|
|
38
|
+
Thread.current[STORED]&.push(blob)
|
|
39
|
+
blob.signed_id
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Runs the block, a field's resolution, and purges the blobs @upload stored
|
|
43
|
+
# meanwhile when it fails: it raises, returns a GraphQL::ExecutionError, or
|
|
44
|
+
# adds an error to the query's `context`. Nested in another, a success
|
|
45
|
+
# hands its blobs to the outer one.
|
|
46
|
+
def purge_on_failure(context)
|
|
47
|
+
outer = Thread.current[STORED]
|
|
48
|
+
blobs = Thread.current[STORED] = []
|
|
49
|
+
errors = error_count(context)
|
|
50
|
+
result = yield
|
|
51
|
+
failed?(result, context, errors) ? purge(blobs) : outer&.concat(blobs)
|
|
52
|
+
result
|
|
53
|
+
rescue StandardError
|
|
54
|
+
purge(blobs || [])
|
|
55
|
+
raise
|
|
56
|
+
ensure
|
|
57
|
+
Thread.current[STORED] = outer
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Not Array(result): a relation would be loaded.
|
|
61
|
+
def failed?(result, context, errors_before)
|
|
62
|
+
result.is_a?(::GraphQL::ExecutionError) || (result.is_a?(Array) && result.any?(::GraphQL::ExecutionError)) ||
|
|
63
|
+
error_count(context) > errors_before
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def error_count(context)
|
|
67
|
+
context.respond_to?(:errors) ? context.errors.size : 0
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Now, not later: the blobs are attached to nothing, and the client is told
|
|
71
|
+
# the mutation failed, so none outlives the response. One the service fails
|
|
72
|
+
# to delete is left to ActiveStorage's job to retry.
|
|
73
|
+
def purge(blobs)
|
|
74
|
+
blobs.each do |blob|
|
|
75
|
+
blob.purge
|
|
76
|
+
rescue StandardError
|
|
77
|
+
blob.purge_later
|
|
78
|
+
end
|
|
79
|
+
blobs.clear
|
|
29
80
|
end
|
|
30
81
|
|
|
31
82
|
# The service `disk` names, or the default one, checked to be as public as asked.
|
|
@@ -1,30 +1,42 @@
|
|
|
1
|
-
# The Rails controller
|
|
1
|
+
# The Rails controller concerns that run and serve a schema. See docs/getting-started.md.
|
|
2
2
|
module Lighthouse
|
|
3
3
|
module GraphQL
|
|
4
|
-
|
|
4
|
+
# Run an operation from any action, with the context the endpoint gives it.
|
|
5
|
+
module Operations
|
|
5
6
|
module ClassMethods
|
|
6
|
-
# The schema
|
|
7
|
-
# request) or a block (evaluated in the controller, per request).
|
|
8
|
-
def lighthouse_schema: (?(
|
|
7
|
+
# The schema the operations run on: a schema class, its name (constantized
|
|
8
|
+
# per request) or a block (evaluated in the controller, per request).
|
|
9
|
+
def lighthouse_schema: (?(_Schema | String | Symbol)? schema) ?{ () -> _Schema } -> (_Schema | String | Symbol | Proc)?
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
# The action: dispatches StartRequest, runs the operation (or a batch),
|
|
12
|
-
# sets Cache-Control, renders JSON, dispatches EndRequest.
|
|
13
|
-
def execute: () -> untyped
|
|
14
|
-
|
|
15
12
|
private
|
|
16
13
|
|
|
14
|
+
# The operation's result, or nil when a @throttle performed the response.
|
|
15
|
+
def lighthouse_execute: (String? query, ?variables: (Hash[String | Symbol, untyped] | String | _Parameters)?, ?operation_name: String?,
|
|
16
|
+
?extensions: GraphQL::PersistedQueries::extensions?, ?context: Hash[Symbol, untyped]) -> Hash[String, json]?
|
|
17
|
+
|
|
17
18
|
# Dispatch StartRequest, yield, dispatch EndRequest; only the outermost call does.
|
|
18
19
|
def lighthouse_request: [T] () { () -> T } -> T
|
|
19
20
|
|
|
20
21
|
# The operation's context; { current_user: current_user } when the controller has one.
|
|
21
22
|
def graphql_context: () -> Hash[Symbol, untyped]
|
|
22
23
|
|
|
24
|
+
# graphql_context, with what @throttle reads: remote_ip and the controller.
|
|
25
|
+
def lighthouse_context: () -> Hash[Symbol, untyped]
|
|
26
|
+
|
|
23
27
|
# The schema class `lighthouse_schema` names.
|
|
24
|
-
def graphql_schema: () ->
|
|
28
|
+
def graphql_schema: () -> _Schema
|
|
25
29
|
|
|
26
30
|
# The `variables` parameter as a Hash: from a JSON String, a Hash or parameters.
|
|
27
|
-
def graphql_variables: (untyped param) -> Hash[String, untyped]
|
|
31
|
+
def graphql_variables: ((Hash[String | Symbol, untyped] | String | _Parameters)? param) -> Hash[String | Symbol, untyped]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module Controller
|
|
35
|
+
include Operations
|
|
36
|
+
|
|
37
|
+
# The action: dispatches StartRequest, runs the operation (or a batch),
|
|
38
|
+
# sets Cache-Control, renders JSON, dispatches EndRequest.
|
|
39
|
+
def execute: () -> void
|
|
28
40
|
end
|
|
29
41
|
end
|
|
30
42
|
end
|
|
@@ -88,6 +88,36 @@ module Lighthouse
|
|
|
88
88
|
def manipulate_sdl: (String sdl) -> String
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
module GraphQL
|
|
92
|
+
# The schema clients see, printed (`bin/rails lighthouse:print_schema`), and
|
|
93
|
+
# Config.schema_output's file, kept up to date in development.
|
|
94
|
+
module SchemaPrinter
|
|
95
|
+
FORMATS: Array[String]
|
|
96
|
+
FILENAMES: Hash[String, String]
|
|
97
|
+
|
|
98
|
+
# Config.schema_output, resolved: an absolute path, the schema's class name, the format.
|
|
99
|
+
type output = { path: Pathname, schema: String?, format: String }
|
|
100
|
+
|
|
101
|
+
def self?.print: (_Schema schema, ?format: String | Symbol) -> String
|
|
102
|
+
def self?.app_schema: (?String? name) -> _Schema
|
|
103
|
+
def self?.output: () -> output?
|
|
104
|
+
def self?.output_content: (?output? setting) -> String
|
|
105
|
+
# Writes unless the file holds `content` already; true when it wrote.
|
|
106
|
+
def self?.write: (path path, String content) -> bool
|
|
107
|
+
def self?.stale?: (?output? setting) -> bool
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Development's report on the schema, on boot and every reload: logged
|
|
111
|
+
# with Config.schema_log; schema_output's file rewritten.
|
|
112
|
+
module SchemaReport
|
|
113
|
+
LIST_LIMIT: Integer
|
|
114
|
+
|
|
115
|
+
# The report's [level, text] lines; nil when there is nothing to do.
|
|
116
|
+
def self?.refresh: (?logger: _Logger?) -> Array[[Symbol, String]]?
|
|
117
|
+
def self?.report: (SchemaPrinter::output? output) -> Array[[Symbol, String]]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
91
121
|
# Writes the SDL an IDE needs next to the app's own: `bin/rails lighthouse:ide_helper`.
|
|
92
122
|
module IdeHelper
|
|
93
123
|
DIRECTIVES_FILE: String
|
|
@@ -106,30 +136,32 @@ module Lighthouse
|
|
|
106
136
|
# The base of the built-in field directives, and of a custom one:
|
|
107
137
|
# subclass it and implement `define_resolver`.
|
|
108
138
|
class BaseDirectiveResolver
|
|
109
|
-
# graphql-ruby's field and type definitions, and the directive's AST node
|
|
110
|
-
|
|
111
|
-
@
|
|
112
|
-
@
|
|
139
|
+
# graphql-ruby's field and type definitions, and the directive's AST node
|
|
140
|
+
# (nil for a resolver no directive names, as the conventional ones).
|
|
141
|
+
@field_def: _FieldDefinition
|
|
142
|
+
@type_def: _NamedType
|
|
143
|
+
@directive_node: _DirectiveNode?
|
|
144
|
+
# Options FieldResolverStack passes: :root_kind, :bases, :phase, :argument, ...
|
|
113
145
|
@opts: Hash[Symbol, untyped]
|
|
114
146
|
|
|
115
|
-
def initialize: (
|
|
147
|
+
def initialize: (_FieldDefinition field_def, _NamedType type_def, _DirectiveNode? directive_node, ?Hash[Symbol, untyped] opts) -> void
|
|
116
148
|
|
|
117
149
|
# Install the field's resolver on `target_type_class` (a graphql-ruby type class).
|
|
118
|
-
def define_resolver: (
|
|
150
|
+
def define_resolver: (Class target_type_class) -> void
|
|
119
151
|
|
|
120
152
|
# `ctx`: the query's context, which @builder on an argument receives.
|
|
121
|
-
def apply_where_filters: (relation relation,
|
|
153
|
+
def apply_where_filters: (relation relation, _ArgumentSet? args, ?context? ctx) -> relation
|
|
122
154
|
def apply_arg_builders: (relation relation, arguments args_h, ?context? ctx) -> relation
|
|
123
155
|
def apply_field_builders: (relation relation, ?arguments args_h, ?context? ctx) -> relation
|
|
124
156
|
def constantize_model: (String? name) -> Class?
|
|
125
157
|
def apply_scopes: (relation relation) -> relation
|
|
126
158
|
|
|
127
159
|
# The literal value of an argument of this directive.
|
|
128
|
-
def directive_arg: (String name) ->
|
|
160
|
+
def directive_arg: (String name) -> literal
|
|
129
161
|
def resolver_method_name: () -> String
|
|
130
162
|
# The field's resolver so far, for a directive that wraps it.
|
|
131
|
-
def capture_inner: (
|
|
132
|
-
def install: (
|
|
163
|
+
def capture_inner: (Class target_type_class) -> _Resolver
|
|
164
|
+
def install: (Class target_type_class, _Resolver callable) -> void
|
|
133
165
|
# The model the directive acts on; raises DefinitionError when there is none.
|
|
134
166
|
def model_class: () -> Class
|
|
135
167
|
end
|
|
@@ -138,9 +170,9 @@ module Lighthouse
|
|
|
138
170
|
class BuilderApplier
|
|
139
171
|
DEFINITION: String
|
|
140
172
|
|
|
141
|
-
def self.apply: (relation relation,
|
|
142
|
-
def self.apply_directive: (relation relation,
|
|
143
|
-
def self.extract_directive_arg: (
|
|
173
|
+
def self.apply: (relation relation, _NamedNode? field_def_ast_node, arguments args, context? ctx, BaseDirectiveResolver? resolver_instance) -> relation
|
|
174
|
+
def self.apply_directive: (relation relation, _DirectiveNode directive_node, arguments args, context? ctx, BaseDirectiveResolver? resolver_instance) -> relation
|
|
175
|
+
def self.extract_directive_arg: (_DirectiveNode directive_node, String name) -> literal
|
|
144
176
|
end
|
|
145
177
|
end
|
|
146
178
|
|
|
@@ -152,19 +184,20 @@ module Lighthouse
|
|
|
152
184
|
include Contracts::ArgBuilder
|
|
153
185
|
|
|
154
186
|
# graphql-ruby's AST nodes for the argument and the directive on it.
|
|
155
|
-
@arg_node:
|
|
156
|
-
@directive_node:
|
|
187
|
+
@arg_node: _Named
|
|
188
|
+
@directive_node: _DirectiveNode
|
|
157
189
|
|
|
158
|
-
def initialize: (
|
|
190
|
+
def initialize: (_Named arg_node, _DirectiveNode directive_node) -> void
|
|
159
191
|
|
|
160
|
-
# Constrain the relation by the value the client gave the argument
|
|
192
|
+
# Constrain the relation by the value the client gave the argument
|
|
193
|
+
# (whatever its type allows, so untyped).
|
|
161
194
|
def handle_builder: (relation relation, untyped value) -> relation
|
|
162
195
|
|
|
163
196
|
private
|
|
164
197
|
|
|
165
198
|
# The directive's `key:`, else the argument's name in snake_case.
|
|
166
199
|
def column: () -> String
|
|
167
|
-
def arel_column: (relation relation) ->
|
|
200
|
+
def arel_column: (relation relation) -> _ArelNode
|
|
168
201
|
end
|
|
169
202
|
end
|
|
170
203
|
end
|
data/sig/lighthouse/events.rbs
CHANGED
|
@@ -6,19 +6,36 @@ module Lighthouse
|
|
|
6
6
|
# to some events (BuildSchemaString, RegisterDirectiveNamespaces,
|
|
7
7
|
# BuildExtensionsResponse), and is ignored by the rest.
|
|
8
8
|
interface _Listener
|
|
9
|
-
def call: (
|
|
9
|
+
def call: (Object event) -> untyped
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# Register a listener (a callable or a block) for an event class and its
|
|
13
|
-
# subclasses; answers the listener, for `forget`.
|
|
14
|
-
|
|
13
|
+
# subclasses; answers the listener, for `forget`. A block gets the event
|
|
14
|
+
# of the class it listens to: one of Lighthouse's, or of the app's own
|
|
15
|
+
# (what @event dispatches). What it answers is read for BuildSchemaString
|
|
16
|
+
# (SDL to add), RegisterDirectiveNamespaces (namespaces) and
|
|
17
|
+
# BuildExtensionsResponse (extensions), and ignored for the rest.
|
|
18
|
+
def self.listen: (singleton(StartRequest) event_class, ?_Listener? callable) ?{ (StartRequest event) -> void } -> _Listener
|
|
19
|
+
| (singleton(StartOperationOrOperations) event_class, ?_Listener? callable) ?{ (StartOperationOrOperations event) -> void } -> _Listener
|
|
20
|
+
| (singleton(BuildSchemaString) event_class, ?_Listener? callable) ?{ (BuildSchemaString event) -> String? } -> _Listener
|
|
21
|
+
| (singleton(RegisterDirectiveNamespaces) event_class, ?_Listener? callable) ?{ (RegisterDirectiveNamespaces event) -> (Module | String | Array[Module | String])? } -> _Listener
|
|
22
|
+
| (singleton(ManipulateAST) event_class, ?_Listener? callable) ?{ (ManipulateAST event) -> void } -> _Listener
|
|
23
|
+
| (singleton(StartExecution) event_class, ?_Listener? callable) ?{ (StartExecution event) -> void } -> _Listener
|
|
24
|
+
| (singleton(BuildExtensionsResponse) event_class, ?_Listener? callable) ?{ (BuildExtensionsResponse event) -> (ExtensionsResponse | Array[untyped])? } -> _Listener
|
|
25
|
+
| (singleton(ManipulateResult) event_class, ?_Listener? callable) ?{ (ManipulateResult event) -> void } -> _Listener
|
|
26
|
+
| (singleton(EndExecution) event_class, ?_Listener? callable) ?{ (EndExecution event) -> void } -> _Listener
|
|
27
|
+
| (singleton(EndOperationOrOperations) event_class, ?_Listener? callable) ?{ (EndOperationOrOperations event) -> void } -> _Listener
|
|
28
|
+
| (singleton(EndRequest) event_class, ?_Listener? callable) ?{ (EndRequest event) -> void } -> _Listener
|
|
29
|
+
| (singleton(ValidateSchema) event_class, ?_Listener? callable) ?{ (ValidateSchema event) -> void } -> _Listener
|
|
30
|
+
| (singleton(Event) event_class, ?_Listener? callable) ?{ (Event event) -> void } -> _Listener
|
|
31
|
+
| (Class event_class, ?_Listener? callable) ?{ (Object event) -> untyped } -> _Listener
|
|
15
32
|
|
|
16
33
|
def self.forget: (_Listener listener) -> nil
|
|
17
34
|
def self.reset!: () -> nil
|
|
18
35
|
|
|
19
36
|
# Call the listeners of the event's class and ancestors in registration
|
|
20
37
|
# order; answers their non-nil return values.
|
|
21
|
-
def self.dispatch: (
|
|
38
|
+
def self.dispatch: (Object event) -> Array[untyped]
|
|
22
39
|
|
|
23
40
|
# Whether dispatching an `event_class` event would reach a listener or an
|
|
24
41
|
# ActiveSupport::Notifications subscriber.
|
|
@@ -35,9 +52,9 @@ module Lighthouse
|
|
|
35
52
|
end
|
|
36
53
|
|
|
37
54
|
class StartRequest < Event
|
|
38
|
-
attr_reader request:
|
|
55
|
+
attr_reader request: _Request
|
|
39
56
|
|
|
40
|
-
def initialize: (
|
|
57
|
+
def initialize: (_Request request) -> void
|
|
41
58
|
end
|
|
42
59
|
|
|
43
60
|
class StartOperationOrOperations < Event
|
|
@@ -58,65 +75,73 @@ module Lighthouse
|
|
|
58
75
|
end
|
|
59
76
|
|
|
60
77
|
class ManipulateAST < Event
|
|
61
|
-
attr_accessor document_ast:
|
|
78
|
+
attr_accessor document_ast: _Document
|
|
62
79
|
|
|
63
|
-
def initialize: (
|
|
80
|
+
def initialize: (_Document document_ast) -> void
|
|
64
81
|
end
|
|
65
82
|
|
|
66
83
|
class StartExecution < Event
|
|
67
|
-
attr_reader schema:
|
|
68
|
-
|
|
84
|
+
attr_reader schema: _Schema
|
|
85
|
+
# The parsed document; nil when it does not parse.
|
|
86
|
+
attr_reader query: _Document?
|
|
69
87
|
attr_reader variables: Hash[String, untyped]?
|
|
70
88
|
attr_reader operation_name: String?
|
|
71
|
-
attr_reader context:
|
|
89
|
+
attr_reader context: _Context
|
|
90
|
+
# The GraphQL::Query, which the operation's EndExecution carries too.
|
|
91
|
+
attr_reader graphql_query: _Query?
|
|
72
92
|
|
|
73
|
-
def initialize: (
|
|
93
|
+
def initialize: (_Schema? schema, _Document? query, Hash[String, untyped]? variables, String? operation_name, _Context context, ?_Query? graphql_query) -> void
|
|
74
94
|
end
|
|
75
95
|
|
|
76
96
|
# A listener may answer an ExtensionsResponse, or an Array of them.
|
|
77
97
|
class BuildExtensionsResponse < Event
|
|
78
|
-
attr_reader result: Hash[String,
|
|
98
|
+
attr_reader result: Hash[String, json]
|
|
79
99
|
attr_reader query_complexity: Integer?
|
|
80
100
|
|
|
81
|
-
def initialize: (Hash[String,
|
|
101
|
+
def initialize: (Hash[String, json] result, Integer? query_complexity) -> void
|
|
82
102
|
end
|
|
83
103
|
|
|
84
104
|
class ManipulateResult < Event
|
|
85
|
-
attr_accessor result: Hash[String,
|
|
105
|
+
attr_accessor result: Hash[String, json]
|
|
86
106
|
|
|
87
|
-
def initialize: (Hash[String,
|
|
107
|
+
def initialize: (Hash[String, json] result) -> void
|
|
88
108
|
end
|
|
89
109
|
|
|
90
110
|
class EndExecution < Event
|
|
91
|
-
attr_reader result: Hash[String,
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
attr_reader result: Hash[String, json]
|
|
112
|
+
# The GraphQL::Query its StartExecution carried.
|
|
113
|
+
attr_reader graphql_query: _Query?
|
|
114
|
+
|
|
115
|
+
def initialize: (Hash[String, json] result, ?_Query? graphql_query) -> void
|
|
116
|
+
# The operation that ran; nil for an anonymous one.
|
|
117
|
+
def operation_name: () -> String?
|
|
118
|
+
def context: () -> _Context?
|
|
94
119
|
end
|
|
95
120
|
|
|
96
121
|
class EndOperationOrOperations < Event
|
|
97
|
-
attr_reader result_or_results:
|
|
122
|
+
attr_reader result_or_results: _Result | Array[_Result]
|
|
98
123
|
|
|
99
|
-
def initialize: (
|
|
124
|
+
def initialize: (_Result | Array[_Result] result_or_results) -> void
|
|
100
125
|
end
|
|
101
126
|
|
|
102
127
|
class EndRequest < Event
|
|
103
|
-
attr_reader response:
|
|
128
|
+
attr_reader response: _Response
|
|
104
129
|
|
|
105
|
-
def initialize: (
|
|
130
|
+
def initialize: (_Response response) -> void
|
|
106
131
|
end
|
|
107
132
|
|
|
108
133
|
class ValidateSchema < Event
|
|
109
|
-
attr_reader schema:
|
|
134
|
+
attr_reader schema: _Schema
|
|
110
135
|
|
|
111
|
-
def initialize: (
|
|
136
|
+
def initialize: (_Schema schema) -> void
|
|
112
137
|
end
|
|
113
138
|
|
|
114
139
|
# A key and content merged into the "extensions" of a result.
|
|
115
140
|
class ExtensionsResponse
|
|
116
141
|
attr_reader key: String | Symbol
|
|
117
|
-
attr_reader content:
|
|
142
|
+
attr_reader content: json
|
|
118
143
|
|
|
119
|
-
def initialize: (String | Symbol key,
|
|
144
|
+
def initialize: (String | Symbol key, json content) -> void
|
|
120
145
|
end
|
|
121
146
|
end
|
|
122
147
|
end
|
data/sig/lighthouse/graphql.rbs
CHANGED
|
@@ -6,7 +6,7 @@ module Lighthouse
|
|
|
6
6
|
Config: singleton(Lighthouse::Config)
|
|
7
7
|
|
|
8
8
|
# A GraphQL::Schema subclass.
|
|
9
|
-
type schema =
|
|
9
|
+
type schema = _Schema
|
|
10
10
|
|
|
11
11
|
module RbLightHouse
|
|
12
12
|
# The schema built from the SDL `schema_path` (default: Config.schema_path) and its imports.
|
|
@@ -16,7 +16,7 @@ module Lighthouse
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
module SchemaFactory
|
|
19
|
-
def self?.build_base_schema: (?schema_path: path?, ?sdl: String?, ?base_types: Hash[
|
|
19
|
+
def self?.build_base_schema: (?schema_path: path?, ?sdl: String?, ?base_types: Hash[Symbol, Module],
|
|
20
20
|
?schema_options: Hash[Symbol, untyped], **untyped extra_options) -> schema
|
|
21
21
|
def self?.load_sdl: (?path? schema_path) -> String
|
|
22
22
|
end
|
|
@@ -38,25 +38,25 @@ module Lighthouse
|
|
|
38
38
|
KEYWORDS: Hash[Class, String]
|
|
39
39
|
EXTENSIONS: Array[Class]
|
|
40
40
|
|
|
41
|
-
attr_reader types: Hash[String,
|
|
42
|
-
attr_reader type_extensions: Hash[String, Array[
|
|
43
|
-
attr_reader directives: Hash[String,
|
|
44
|
-
attr_reader schema_definitions: Array[
|
|
41
|
+
attr_reader types: Hash[String, _NamedNode]
|
|
42
|
+
attr_reader type_extensions: Hash[String, Array[_NamedNode]]
|
|
43
|
+
attr_reader directives: Hash[String, _NamedNode]
|
|
44
|
+
attr_reader schema_definitions: Array[_Node]
|
|
45
45
|
|
|
46
46
|
def self.from_source: (String sdl) -> DocumentAST
|
|
47
|
-
def self.from_document: (
|
|
47
|
+
def self.from_document: (_Document document) -> DocumentAST
|
|
48
48
|
|
|
49
49
|
def initialize: () -> void
|
|
50
|
-
def add: (
|
|
50
|
+
def add: (_Node definition) -> void
|
|
51
51
|
# Adds a type, or replaces the one of the same name.
|
|
52
|
-
def put_type: (
|
|
52
|
+
def put_type: (_NamedNode definition) -> self
|
|
53
53
|
def remove_type: (String name) -> self
|
|
54
54
|
def remove_directive: (String name) -> self
|
|
55
55
|
# Adds the type parsed from the SDL (or the block's), unless one of the name exists.
|
|
56
|
-
def define_type: (String name, ?String? sdl) ?{ () -> String } ->
|
|
56
|
+
def define_type: (String name, ?String? sdl) ?{ () -> String } -> _NamedNode
|
|
57
57
|
def type?: (String name) -> bool
|
|
58
58
|
def type_names: () -> Array[String]
|
|
59
|
-
def to_document: () ->
|
|
59
|
+
def to_document: () -> _Document
|
|
60
60
|
def to_sdl: () -> String
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -82,21 +82,26 @@ module Lighthouse
|
|
|
82
82
|
attr_reader code: String
|
|
83
83
|
|
|
84
84
|
def initialize: (String message, String code) -> void
|
|
85
|
-
def to_h: () -> Hash[String,
|
|
85
|
+
def to_h: () -> Hash[String, json]
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
# `extensions` as a request carries it: a Hash, a JSON String (GET) or
|
|
89
|
+
# ActionController::Parameters.
|
|
90
|
+
type extensions = Hash[String | Symbol, untyped] | String | _Parameters
|
|
91
|
+
|
|
88
92
|
# `extensions` as the request carries it: a Hash, a JSON String (GET) or
|
|
89
93
|
# ActionController::Parameters.
|
|
90
94
|
#
|
|
91
95
|
# `schema.execute` with the query the request names: its result, or a
|
|
92
96
|
# protocol error as a ready-to-render { "errors" => [...] } Hash.
|
|
93
|
-
def self?.execute: (schema schema, query: String?, ?extensions:
|
|
97
|
+
def self?.execute: (schema schema, query: String?, ?extensions: extensions?, ?variables: Hash[String, untyped]?,
|
|
98
|
+
?operation_name: String?, ?context: Hash[Symbol, untyped], **untyped options) -> _Result
|
|
94
99
|
# A batch: `schema.multiplex` with the query each operation (a Hash of
|
|
95
100
|
# query, extensions, variables, operation_name, context) names. One result
|
|
96
101
|
# per operation, in order; a protocol error is a ready-to-render Hash.
|
|
97
|
-
def self?.multiplex: (schema schema, Array[Hash[Symbol | String, untyped]] operations, **untyped options) -> Array[
|
|
102
|
+
def self?.multiplex: (schema schema, Array[Hash[Symbol | String, untyped]] operations, **untyped options) -> Array[_Result]
|
|
98
103
|
# The query text to run for a request's `query` and `extensions`.
|
|
99
|
-
def self?.resolve: (String? query,
|
|
104
|
+
def self?.resolve: (String? query, extensions? extensions) -> String?
|
|
100
105
|
def self?.enabled?: () -> bool
|
|
101
106
|
def self?.digest: (String query) -> String
|
|
102
107
|
# Store a query ahead of time (e.g. from a deploy task); returns its hash.
|
|
@@ -110,10 +115,10 @@ module Lighthouse
|
|
|
110
115
|
module Subscription
|
|
111
116
|
# May this client subscribe? Called with the subscription request only.
|
|
112
117
|
def authorize?: (**untyped args) -> boolish
|
|
113
|
-
# Should this subscriber receive the broadcast of `root
|
|
114
|
-
# arguments it subscribed with.
|
|
118
|
+
# Should this subscriber receive the broadcast of `root` (what the
|
|
119
|
+
# mutation returned, the app's)? `args` are the arguments it subscribed with.
|
|
115
120
|
def filter?: (untyped root, **untyped args) -> boolish
|
|
116
|
-
# The value an update resolves the field with.
|
|
121
|
+
# The value an update resolves the field with: the app's.
|
|
117
122
|
def resolve_payload: (untyped root, **untyped args) -> untyped
|
|
118
123
|
|
|
119
124
|
# The class methods the concern adds to its includer.
|
|
@@ -121,7 +126,7 @@ module Lighthouse
|
|
|
121
126
|
# :field (default): every subscriber shares the field's topic and filter?
|
|
122
127
|
# decides; :arguments: graphql-ruby's, subscribers match the trigger's arguments.
|
|
123
128
|
def topic_by: (?(:field | :arguments)? mode) -> (:field | :arguments)
|
|
124
|
-
def topic_for: (arguments:
|
|
129
|
+
def topic_for: (arguments: arguments, field: _FieldDefinition, scope: untyped) -> String
|
|
125
130
|
# What @broadcast triggers the subscription with, for the root a mutation returned.
|
|
126
131
|
def trigger_arguments: (untyped root, context context) -> Hash[Symbol | String, untyped]
|
|
127
132
|
def trigger_scope: (untyped root, context context) -> untyped
|
|
@@ -140,9 +145,9 @@ module Lighthouse
|
|
|
140
145
|
|
|
141
146
|
# For an executed query (a GraphQL::Query::Result or GraphQL::Query);
|
|
142
147
|
# nil when the schema does not use @cacheControl.
|
|
143
|
-
def self?.header: (
|
|
144
|
-
# Set the header on a Rails
|
|
145
|
-
def self?.apply: (
|
|
148
|
+
def self?.header: (_Result | _Query result) -> String?
|
|
149
|
+
# Set the header on a Rails response, and return it.
|
|
150
|
+
def self?.apply: (_ResponseHeaders response, _Result | _Query result) -> String?
|
|
146
151
|
end
|
|
147
152
|
|
|
148
153
|
# What fields cost in graphql-ruby's complexity analysis (@complexity, and
|
|
@@ -153,9 +158,9 @@ module Lighthouse
|
|
|
153
158
|
|
|
154
159
|
# Give the schema's fields their cost; `root_kinds` maps root type names to
|
|
155
160
|
# :queries / :mutations / :subscriptions.
|
|
156
|
-
def self?.apply: (
|
|
161
|
+
def self?.apply: (_Schema schema, ?Hash[String, Symbol] root_kinds) -> void
|
|
157
162
|
# A query's score, once scored for BuildExtensionsResponse; nil otherwise.
|
|
158
|
-
def self?.query_complexity: (
|
|
163
|
+
def self?.query_complexity: (_Query query) -> Integer?
|
|
159
164
|
end
|
|
160
165
|
|
|
161
166
|
# A concern for a GraphQL::Analysis::Analyzer that @complexity(resolver:)
|