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
data/sig/lighthouse.rbs
CHANGED
|
@@ -2,17 +2,180 @@
|
|
|
2
2
|
# the classes a schema names (builders, validators), the configuration, the
|
|
3
3
|
# directive extension points and the entrypoints. Internals are left out.
|
|
4
4
|
#
|
|
5
|
-
# graphql-ruby
|
|
6
|
-
#
|
|
5
|
+
# graphql-ruby, Active Record and Rails ship no RBS every app has, so what
|
|
6
|
+
# Lighthouse takes from them is declared here as interfaces of the methods it
|
|
7
|
+
# uses: GraphQL::Schema is a _Schema, GraphQL::Query::Context a _Context, an
|
|
8
|
+
# ActiveRecord::Relation a _Relation. Any object answering those methods
|
|
9
|
+
# conforms, the gem depends on no one else's signatures, and `rake rbs:test`
|
|
10
|
+
# checks the real values against them. What stays `untyped` is the app's own
|
|
11
|
+
# (a user, a record a resolver returns, a client's argument value).
|
|
7
12
|
module Lighthouse
|
|
8
|
-
#
|
|
9
|
-
|
|
13
|
+
# --- graphql-ruby ----------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
# A GraphQL::Schema subclass (the class itself), as Lighthouse builds it.
|
|
16
|
+
interface _Schema
|
|
17
|
+
def execute: (?String? query, **untyped options) -> _Result
|
|
18
|
+
def multiplex: (Array[Hash[Symbol, untyped]] queries, **untyped options) -> Array[_Result]
|
|
19
|
+
def validate: (String | _Document query, **untyped options) -> Array[_Error]
|
|
20
|
+
def to_definition: () -> String
|
|
21
|
+
def types: () -> Hash[String, _NamedType]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A GraphQL::Query::Result, or a ready-to-render Hash ({ "errors" => [...] }).
|
|
25
|
+
interface _Result
|
|
26
|
+
def to_h: () -> Hash[String, json]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A GraphQL::StaticValidation::Error, or any error graphql-ruby reports.
|
|
30
|
+
interface _Error
|
|
31
|
+
def message: () -> String
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# A GraphQL::Query: one operation of a request.
|
|
35
|
+
interface _Query
|
|
36
|
+
def selected_operation_name: () -> String?
|
|
37
|
+
def context: () -> _Context
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The request's GraphQL::Query::Context, or a Hash standing in for one.
|
|
41
|
+
interface _Context
|
|
42
|
+
def []: (Symbol | String key) -> untyped
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# A graphql-ruby type: an object, interface, input, enum, scalar or union class.
|
|
46
|
+
interface _NamedType
|
|
47
|
+
def graphql_name: (?String? name) -> String
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# A GraphQL::Schema::Field or GraphQL::Schema::Argument, as built from the SDL.
|
|
51
|
+
interface _SchemaMember
|
|
52
|
+
def graphql_name: () -> String
|
|
53
|
+
def ast_node: () -> _Node?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# A GraphQL::Schema::Field: a member with arguments.
|
|
57
|
+
interface _FieldDefinition
|
|
58
|
+
include _SchemaMember
|
|
59
|
+
def arguments: () -> Hash[String, _SchemaMember]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# What resolves a field: graphql-ruby's resolver signature, (object, arguments,
|
|
63
|
+
# context). The object and the value are the app's.
|
|
64
|
+
interface _Resolver
|
|
65
|
+
def call: (untyped object, untyped arguments, context? context) -> untyped
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# A field's arguments as graphql-ruby hands them over (GraphQL::Execution::
|
|
69
|
+
# Interpreter::Arguments), or a Hash.
|
|
70
|
+
interface _ArgumentSet
|
|
71
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# A GraphQL::Language::Nodes node: a document, a definition, a directive, ...
|
|
75
|
+
interface _Node
|
|
76
|
+
def to_query_string: () -> String
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Anything with a name: an AST node, a directive's argument.
|
|
80
|
+
interface _Named
|
|
81
|
+
def name: () -> String
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# A node with a name: a type or directive definition, a field, a directive.
|
|
85
|
+
interface _NamedNode
|
|
86
|
+
include _Node
|
|
87
|
+
include _Named
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# A parsed GraphQL::Language::Nodes::Document.
|
|
91
|
+
interface _Document
|
|
92
|
+
include _Node
|
|
93
|
+
def definitions: () -> Array[_Node]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# A directive as the SDL applies it (`@paginate(defaultCount: 10)`): its
|
|
97
|
+
# name and its arguments (each a name and a value).
|
|
98
|
+
interface _DirectiveNode
|
|
99
|
+
include _Named
|
|
100
|
+
def arguments: () -> Array[_Named]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# --- Active Record ---------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
# An ActiveRecord::Relation, or a model class (which answers the same).
|
|
106
|
+
interface _Relation
|
|
107
|
+
def where: (*untyped conditions) -> _Relation
|
|
108
|
+
def order: (*untyped orders) -> _Relation
|
|
109
|
+
def limit: (Integer? count) -> _Relation
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
type relation = _Relation
|
|
113
|
+
|
|
114
|
+
# An Arel attribute or SQL literal, which predicates build on.
|
|
115
|
+
interface _ArelNode
|
|
116
|
+
def eq: (untyped other) -> _ArelNode
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# A model instance.
|
|
120
|
+
interface _Record
|
|
121
|
+
def id: () -> (Integer | String | Array[Integer | String])?
|
|
122
|
+
def persisted?: () -> bool
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# --- Rails -----------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
# An ActionDispatch::Request.
|
|
128
|
+
interface _Request
|
|
129
|
+
def path: () -> String
|
|
130
|
+
def headers: () -> untyped
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# What has response headers: an ActionDispatch::Response.
|
|
134
|
+
interface _ResponseHeaders
|
|
135
|
+
def headers: () -> Hash[String, untyped]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# An ActionDispatch::Response.
|
|
139
|
+
interface _Response
|
|
140
|
+
include _ResponseHeaders
|
|
141
|
+
def status: () -> Integer
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# ActionController::Parameters, read whole.
|
|
145
|
+
interface _Parameters
|
|
146
|
+
def to_unsafe_h: () -> Hash[String, untyped]
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# An ActiveSupport::Cache::Store, Rails.cache by default.
|
|
150
|
+
interface _CacheStore
|
|
151
|
+
def read: (String key, **untyped options) -> untyped
|
|
152
|
+
def write: (String key, untyped value, **untyped options) -> boolish
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# A Logger, Rails.logger by default.
|
|
156
|
+
interface _Logger
|
|
157
|
+
def info: (?String? message) -> void
|
|
158
|
+
def warn: (?String? message) -> void
|
|
159
|
+
def error: (?String? message) -> void
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# --- Values ----------------------------------------------------------------
|
|
10
163
|
|
|
11
164
|
# A field's arguments, with snake_case Symbol keys as graphql-ruby passes them.
|
|
165
|
+
# A value is whatever the client sent for the argument's type.
|
|
12
166
|
type arguments = Hash[Symbol, untyped]
|
|
13
167
|
|
|
14
|
-
|
|
15
|
-
|
|
168
|
+
type context = _Context
|
|
169
|
+
|
|
170
|
+
# A literal a directive is written with in the SDL: `@paginate(defaultCount: 10)`,
|
|
171
|
+
# `@can(ability: "x", args: [1, "a"])`. Enum values are Strings.
|
|
172
|
+
type literal = String | Integer | Float | bool | nil | Array[literal] | Hash[String, literal]
|
|
173
|
+
|
|
174
|
+
# What a response's extensions, or a JSON document, may hold.
|
|
175
|
+
type json = String | Integer | Float | bool | nil | Array[json] | Hash[String | Symbol, json]
|
|
176
|
+
|
|
177
|
+
# A @validator's errors: messages by key, nested for input objects.
|
|
178
|
+
type validation_errors = Hash[Symbol | String, Array[String] | validation_errors]
|
|
16
179
|
|
|
17
180
|
# A path on disk: a String or a Pathname.
|
|
18
181
|
type path = String | _ToPath
|
|
@@ -31,7 +194,7 @@ module Lighthouse
|
|
|
31
194
|
# arguments (snake_case Symbol keys) and answers the errors by key,
|
|
32
195
|
# { title: ["is missing"] }, nested for input objects; empty when valid.
|
|
33
196
|
interface _Validator
|
|
34
|
-
def call: (
|
|
197
|
+
def call: (arguments values) -> validation_errors
|
|
35
198
|
end
|
|
36
199
|
|
|
37
200
|
# Config.on_error: called with an error a directive or resolver swallowed.
|
|
@@ -41,11 +204,12 @@ module Lighthouse
|
|
|
41
204
|
|
|
42
205
|
# Config.global_id: encodes and decodes Relay global ids (@globalId, @node).
|
|
43
206
|
interface _GlobalId
|
|
44
|
-
def encode: (String type,
|
|
207
|
+
def encode: (String type, String | Integer id) -> String
|
|
45
208
|
def decode: (String global_id) -> Array[String]
|
|
46
209
|
end
|
|
47
210
|
|
|
48
|
-
# Config.authenticated_user and Config.policy_user: the user of a request
|
|
211
|
+
# Config.authenticated_user and Config.policy_user: the user of a request,
|
|
212
|
+
# an object of the app's own (nil for a guest).
|
|
49
213
|
interface _UserReader
|
|
50
214
|
def call: (context? context) -> untyped
|
|
51
215
|
end
|
|
@@ -54,7 +218,7 @@ module Lighthouse
|
|
|
54
218
|
# instance, or a model class for @canModel)? `args` are the @can* `args:`,
|
|
55
219
|
# after the field's arguments with `injectArgs: true`.
|
|
56
220
|
interface _Authorizer
|
|
57
|
-
def call: (untyped user,
|
|
221
|
+
def call: (untyped user, _Record | Class record, String | Symbol ability, ?Array[untyped] args) -> boolish
|
|
58
222
|
end
|
|
59
223
|
|
|
60
224
|
# Config.feature_checker: is the feature `name` (as written in @feature) on
|
|
@@ -72,8 +236,8 @@ module Lighthouse
|
|
|
72
236
|
def only_trashed: (relation relation) -> relation
|
|
73
237
|
def with_trashed: (relation relation) -> relation
|
|
74
238
|
def without_trashed: (relation relation) -> relation
|
|
75
|
-
def restore: (
|
|
76
|
-
def force_delete: (
|
|
239
|
+
def restore: (_Record record) -> boolish
|
|
240
|
+
def force_delete: (_Record record) -> boolish
|
|
77
241
|
end
|
|
78
242
|
|
|
79
243
|
# What DirectiveRegistry#register_manipulator takes: it transforms the SDL
|
|
@@ -84,11 +248,17 @@ module Lighthouse
|
|
|
84
248
|
|
|
85
249
|
def self.configure: () ?{ (singleton(Config) config) -> void } -> void
|
|
86
250
|
|
|
251
|
+
# Trusted operations: { sha256 => query }, or Apollo's manifest
|
|
252
|
+
# ({ "operations" => [{ "id" => sha256, "body" => query }] }).
|
|
253
|
+
type manifest = Hash[String | Symbol, String | Array[Hash[String | Symbol, String]] | Integer]
|
|
254
|
+
type manifest_source = path | manifest | ^() -> (path | manifest)?
|
|
255
|
+
|
|
87
256
|
module Config
|
|
88
257
|
DEFAULT_NAMESPACES: Hash[Symbol, Array[String]]
|
|
89
258
|
SETTINGS: Array[Symbol]
|
|
90
259
|
|
|
91
260
|
def self.configure: () ?{ (singleton(Config) config) -> void } -> void
|
|
261
|
+
# A setting by name: its value, of the setting's type.
|
|
92
262
|
def self.[]: (Symbol | String key) -> untyped
|
|
93
263
|
def self.reset!: () -> void
|
|
94
264
|
|
|
@@ -101,6 +271,14 @@ module Lighthouse
|
|
|
101
271
|
def self.ide_helper: () -> bool?
|
|
102
272
|
def self.ide_helper=: (bool? enabled) -> bool?
|
|
103
273
|
|
|
274
|
+
# The file development keeps the client schema in: a path, or { path:, schema: }; nil: none.
|
|
275
|
+
def self.schema_output: () -> (path | { path: path, ?schema: String })?
|
|
276
|
+
def self.schema_output=: ((path | { path: path, ?schema: String })? output) -> (path | { path: path, ?schema: String })?
|
|
277
|
+
|
|
278
|
+
# Log the schema's build on boot and every reload; nil: in a development server.
|
|
279
|
+
def self.schema_log: () -> bool
|
|
280
|
+
def self.schema_log=: (bool? enabled) -> bool?
|
|
281
|
+
|
|
104
282
|
# { queries:, mutations:, subscriptions:, builders:, validators:, events: } => [namespace, ...].
|
|
105
283
|
# Assigning a partial hash overrides only the kinds it names.
|
|
106
284
|
def self.namespaces: () -> Hash[Symbol, Array[String]]
|
|
@@ -109,8 +287,6 @@ module Lighthouse
|
|
|
109
287
|
def self.resolver_namespaces: () -> Array[String]
|
|
110
288
|
def self.resolver_namespaces=: (Array[String] namespaces) -> Array[String]
|
|
111
289
|
|
|
112
|
-
def self.directive_map: () -> Hash[untyped, untyped]
|
|
113
|
-
|
|
114
290
|
# An ActiveSupport::Cache::Store; Rails.cache by default.
|
|
115
291
|
|
|
116
292
|
def self.transactional_mutations: () -> bool
|
|
@@ -130,12 +306,13 @@ module Lighthouse
|
|
|
130
306
|
|
|
131
307
|
def self.persisted_queries: () -> bool
|
|
132
308
|
def self.persisted_queries=: (bool? enabled) -> bool?
|
|
133
|
-
def self.persisted_queries_store: () ->
|
|
134
|
-
def self.persisted_queries_store=: (
|
|
309
|
+
def self.persisted_queries_store: () -> _CacheStore
|
|
310
|
+
def self.persisted_queries_store=: (_CacheStore? store) -> _CacheStore?
|
|
135
311
|
def self.persisted_queries_ttl: () -> Numeric?
|
|
136
312
|
def self.persisted_queries_ttl=: (Numeric? seconds) -> Numeric?
|
|
137
|
-
|
|
138
|
-
def self.persisted_queries_manifest
|
|
313
|
+
# A JSON file, a Hash of operations, or a callable answering either.
|
|
314
|
+
def self.persisted_queries_manifest: () -> manifest_source?
|
|
315
|
+
def self.persisted_queries_manifest=: (manifest_source? manifest) -> manifest_source?
|
|
139
316
|
def self.persisted_queries_only: () -> bool
|
|
140
317
|
def self.persisted_queries_only=: (bool? enabled) -> bool?
|
|
141
318
|
|
|
@@ -192,9 +369,19 @@ module Lighthouse
|
|
|
192
369
|
end
|
|
193
370
|
|
|
194
371
|
# A GraphQL::ExecutionError (declared from StandardError, which it descends
|
|
195
|
-
# from, as graphql-ruby ships no RBS): the @can* family denied the ability
|
|
372
|
+
# from, as graphql-ruby ships no RBS): the @can* family denied the ability
|
|
373
|
+
# (extensions.code FORBIDDEN).
|
|
196
374
|
class AuthorizationError < StandardError
|
|
197
|
-
|
|
375
|
+
CODE: String
|
|
376
|
+
|
|
377
|
+
def initialize: (?String message, ?extensions: Hash[String, json], ?ast_node: _Node?, ?ast_nodes: Array[_Node]?, ?options: Hash[String, json]?) -> void
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# A GraphQL::ExecutionError: @guard or @auth found no signed-in user (extensions.code UNAUTHENTICATED).
|
|
381
|
+
class AuthenticationError < StandardError
|
|
382
|
+
CODE: String
|
|
383
|
+
|
|
384
|
+
def initialize: (?String message, ?extensions: Hash[String, json], ?ast_node: _Node?, ?ast_nodes: Array[_Node]?, ?options: Hash[String, json]?) -> void
|
|
198
385
|
end
|
|
199
386
|
|
|
200
387
|
# A GraphQL::ExecutionError: invalid arguments, keyed by argument path
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lighthouse-graphql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vaz Innovation
|
|
@@ -118,6 +118,7 @@ files:
|
|
|
118
118
|
- lib/lighthouse/directive_resolvers/argument_transforms_resolver.rb
|
|
119
119
|
- lib/lighthouse/directive_resolvers/association_resolvers.rb
|
|
120
120
|
- lib/lighthouse/directive_resolvers/async_resolver.rb
|
|
121
|
+
- lib/lighthouse/directive_resolvers/attachment_resolver.rb
|
|
121
122
|
- lib/lighthouse/directive_resolvers/auth_resolver.rb
|
|
122
123
|
- lib/lighthouse/directive_resolvers/base.rb
|
|
123
124
|
- lib/lighthouse/directive_resolvers/broadcast_resolver.rb
|
|
@@ -190,10 +191,12 @@ files:
|
|
|
190
191
|
- lib/lighthouse/nested_mutations/many_to_many_operations.rb
|
|
191
192
|
- lib/lighthouse/nested_mutations/partitioner.rb
|
|
192
193
|
- lib/lighthouse/node_registry.rb
|
|
194
|
+
- lib/lighthouse/operations.rb
|
|
193
195
|
- lib/lighthouse/order_by/types.rb
|
|
194
196
|
- lib/lighthouse/pagination.rb
|
|
195
197
|
- lib/lighthouse/persisted_queries.rb
|
|
196
198
|
- lib/lighthouse/persisted_queries/batch.rb
|
|
199
|
+
- lib/lighthouse/persisted_queries/manifest.rb
|
|
197
200
|
- lib/lighthouse/railtie.rb
|
|
198
201
|
- lib/lighthouse/rb_lighthouse.rb
|
|
199
202
|
- lib/lighthouse/reference_resolver.rb
|
|
@@ -208,7 +211,10 @@ files:
|
|
|
208
211
|
- lib/lighthouse/schema_factory.rb
|
|
209
212
|
- lib/lighthouse/schema_generator.rb
|
|
210
213
|
- lib/lighthouse/schema_implementation.rb
|
|
214
|
+
- lib/lighthouse/schema_printer.rb
|
|
215
|
+
- lib/lighthouse/schema_report.rb
|
|
211
216
|
- lib/lighthouse/schema_stitcher.rb
|
|
217
|
+
- lib/lighthouse/server_directives.rb
|
|
212
218
|
- lib/lighthouse/subscription.rb
|
|
213
219
|
- lib/lighthouse/support/arguments.rb
|
|
214
220
|
- lib/lighthouse/support/authorization.rb
|