lighthouse-graphql 0.8.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f307869fd0902be910da0c9edad56620a3339962ccb77e388b7b11aad1565fde
4
- data.tar.gz: 3e9164c49b69dcf6626b6985266fd33a65c90a76cf065e44efe7cee5bc250b0f
3
+ metadata.gz: 9256c2a7c721e495cf5c3754da6b1f684a1d15822014435150c08612af4964e6
4
+ data.tar.gz: 8acfd179e8ede63d8d9f7addfb85e5472435078e9f389ca684d543203353ef88
5
5
  SHA512:
6
- metadata.gz: ac2430336cfdc489d2d032d038ad3227d45cfd92101f66c4eff3c5a83b1325058d1e65fd16430fecf2a0b358849427e9be31a1b3ba2b309c787873cf20bf41bc
7
- data.tar.gz: 8c9c10c5650b02845daa40cc74ad76909e8ea7622221d19d204a2b77fd3cec08b9686339c8b2606e067a06f4ba56a4d13111b42b155e0d8d0e5c5ed4831d6558
6
+ metadata.gz: 066e474500d83f2c5d8809275819a96941fa4e303bb3d2984a8652a7e54f2bf08e0259ef40f7ddbf8105eb5dc40485588c1e760c368c7cd9205823e44fc1c50a
7
+ data.tar.gz: 013fffcb17f486024bcb94f3ba347973326bbbaf1cfdfac3b2d7ba9be90a808e64c21d37d0eac5c74d4c552f8b5ed74b40c0689715a6041ae5d232de3560bee4
data/CHANGELOG.md CHANGED
@@ -6,6 +6,35 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.8.1] - 2026-10-30
10
+
11
+ ### Changed
12
+
13
+ - **The RBS signatures are typed.** What Lighthouse takes from graphql-ruby, Active Record
14
+ and Rails, which ship no RBS, was `untyped`; it is now declared as interfaces of the methods
15
+ Lighthouse uses (`_Schema`, `_Result`, `_Context`, `_Query`, `_Relation`, `_DirectiveNode`,
16
+ `_Request`, ...), so Steep checks code that calls Lighthouse and `rake rbs:test` checks the
17
+ suite's real values against them. Results are `Hash[String, json]`, directive arguments
18
+ `literal`, `Events.listen` has an overload per event class, with the block's event and
19
+ answer typed. `untyped` is left for the app's own values (a user, a client's argument
20
+ value): 169 became 76. Typing found `BuilderApplier.apply` called without a context, which
21
+ the signature now allows.
22
+
23
+ ### Removed
24
+
25
+ - `Config.directive_map`, a setting nothing read.
26
+
27
+ ### Added
28
+
29
+ - **`Unauthenticated.` and `This action is unauthorized.` carry an `extensions.code`** (#5):
30
+ `UNAUTHENTICATED` from `@guard` and `@auth` (the new `Lighthouse::AuthenticationError`), and
31
+ `FORBIDDEN` from the `@can*` directives (`Lighthouse::AuthorizationError`), as Apollo names
32
+ them, so a client can react without matching the message. PHP Lighthouse's have no code.
33
+ - **`EndExecution` says which operation ended** (#4): `operation_name`, `context`, and the
34
+ `GraphQL::Query` as `graphql_query`, which `StartExecution` carries too. In a batch every
35
+ `StartExecution` comes before any `EndExecution`, so a listener could not tell the results
36
+ apart.
37
+
9
38
  ## [0.8.0] - 2026-10-29
10
39
 
11
40
  ### Added
@@ -824,7 +853,8 @@ had been running inside a private monorepo as a path gem before being extracted.
824
853
  - Config-driven extension seams: `Lighthouse.configure`, `resolver_namespaces`,
825
854
  `on_error`, and `DirectiveRegistry.register` for app-defined directives.
826
855
 
827
- [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.0...HEAD
856
+ [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.1...HEAD
857
+ [0.8.1]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.0...v0.8.1
828
858
  [0.8.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.3...v0.8.0
829
859
  [0.7.3]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.2...v0.7.3
830
860
  [0.7.2]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.1...v0.7.2
@@ -33,8 +33,9 @@ three-argument authorizer keeps working for checks without them.
33
33
 
34
34
  ## `@guard` — require authentication
35
35
 
36
- Raises `Unauthenticated.` when there is no user. It runs before everything else
37
- on the field.
36
+ Raises `Unauthenticated.` when there is no user, with `extensions.code`
37
+ `UNAUTHENTICATED`, Apollo's code, so a client can send the user to sign in without
38
+ matching the message. It runs before everything else on the field.
38
39
 
39
40
  ```graphql
40
41
  type Query {
@@ -134,6 +135,16 @@ post(id: ID!): Post @canFind(ability: "show", find: "id", action: EXCEPTION_NOT_
134
135
  `action` applies to the directive's own checks only. Errors from the resolver
135
136
  itself are untouched.
136
137
 
138
+ `This action is unauthorized.` carries `extensions.code` `FORBIDDEN`, as Apollo
139
+ names it (`@guard`'s `Unauthenticated.` carries `UNAUTHENTICATED`):
140
+
141
+ ```json
142
+ { "message": "This action is unauthorized.", "path": ["post"], "extensions": { "code": "FORBIDDEN" } }
143
+ ```
144
+
145
+ PHP Lighthouse's errors have no code. Raise `Lighthouse::AuthenticationError` and
146
+ `Lighthouse::AuthorizationError` from your own resolvers to answer the same.
147
+
137
148
  ### Who may use an argument
138
149
 
139
150
  Some arguments are for some users only: `trashed` for admins, a filter on drafts
data/docs/events.md CHANGED
@@ -51,10 +51,10 @@ created at (UTC).
51
51
  | --- | --- | --- |
52
52
  | `StartRequest` | The controller action begins | `request`, `moment` |
53
53
  | `StartOperationOrOperations` | The operation(s) were read, before they run | `operation_or_operations` |
54
- | `StartExecution` | A query is about to run (once per operation of a batch) | `schema`, `query`, `variables`, `operation_name`, `context`, `moment` |
54
+ | `StartExecution` | A query is about to run (once per operation of a batch) | `schema`, `query`, `variables`, `operation_name`, `context`, `graphql_query`, `moment` |
55
55
  | `BuildExtensionsResponse` | A query ran | `result`, `query_complexity` |
56
56
  | `ManipulateResult` | Before the result is returned | `result` (+ writer) |
57
- | `EndExecution` | The result is final | `result`, `moment` |
57
+ | `EndExecution` | The result is final | `result`, `operation_name`, `context`, `graphql_query`, `moment` |
58
58
  | `EndOperationOrOperations` | The operation(s) ran | `result_or_results` |
59
59
  | `EndRequest` | The response is rendered | `response`, `moment` |
60
60
 
@@ -95,7 +95,21 @@ it builds, so they fire however the query was started: the controller,
95
95
  With no listener, and no `ActiveSupport::Notifications` subscriber, they cost
96
96
  one lookup per request.
97
97
 
98
- `StartExecution#query` is the parsed `GraphQL::Language::Nodes::Document`.
98
+ `StartExecution#query` is the parsed `GraphQL::Language::Nodes::Document`, and
99
+ `operation_name` the one the client gave. Both events carry the `GraphQL::Query` as
100
+ `graphql_query`, and `EndExecution` its `operation_name` (the operation that ran,
101
+ `nil` for an anonymous one) and `context`. In a batch, graphql-ruby runs the
102
+ operations together, so every `StartExecution` comes before any `EndExecution`:
103
+ read what you need from `EndExecution`, or pair the two by `graphql_query`, not by
104
+ order. PHP Lighthouse's `EndExecution` has the result only, as it runs a batch's
105
+ operations one after the other.
106
+
107
+ ```ruby
108
+ Lighthouse::Events.listen(Lighthouse::Events::EndExecution) do |event|
109
+ errors = event.result['errors']
110
+ Rails.logger.warn("GraphQL #{event.operation_name || 'an anonymous operation'} answered with errors") if errors.present?
111
+ end
112
+ ```
99
113
 
100
114
  **`BuildExtensionsResponse`**: return an `ExtensionsResponse` (or an Array of
101
115
  them) to add to the result's `extensions`:
@@ -26,7 +26,7 @@ module Lighthouse
26
26
  SETTINGS = %i[
27
27
  schema_path ide_helper resolver_namespaces namespaces transactional_mutations pagination_default_count pagination_max_count
28
28
  schema_cache schema_cache_path watch_sdl persisted_queries persisted_queries_store persisted_queries_ttl
29
- persisted_queries_manifest persisted_queries_only on_error directive_map authenticated_user policy_user authorizer
29
+ persisted_queries_manifest persisted_queries_only on_error authenticated_user policy_user authorizer
30
30
  feature_checker feature_actor
31
31
  convert_empty_strings_to_null
32
32
  soft_deletes
@@ -78,8 +78,6 @@ module Lighthouse
78
78
  File.exist?(::Rails.root.join('graphql.config.yml'))
79
79
  end
80
80
 
81
- def directive_map = @directive_map ||= {}
82
-
83
81
  # Namespaces tried (in order) when resolving a class name from a directive
84
82
  # argument, e.g. `@field(resolver: "ContactPerson")` or `@all(model: "X")`.
85
83
  # Keeping this in config means the library holds no app-specific namespace
@@ -18,7 +18,7 @@ class Lighthouse::GraphQL::DirectiveResolvers::AuthDirectiveResolver < Lighthous
18
18
 
19
19
  install(target_type_class, lambda do |obj, arguments, ctx|
20
20
  user = ctx && (ctx[:current_user] || ctx['current_user'])
21
- raise(::GraphQL::ExecutionError, 'Unauthenticated.') unless user
21
+ raise Lighthouse::AuthenticationError unless user
22
22
 
23
23
  inner.call(obj, arguments, ctx)
24
24
  end)
@@ -3,8 +3,9 @@
3
3
  require_relative 'base'
4
4
 
5
5
  # @guard — require an authenticated user before the field resolves.
6
- # Wraps the field's resolver; raises "Unauthenticated." when no user is
7
- # present (per Config.authenticated_user). Mirrors PHP Lighthouse's @guard.
6
+ # Wraps the field's resolver; raises "Unauthenticated." (AuthenticationError,
7
+ # extensions.code UNAUTHENTICATED) when no user is present (per
8
+ # Config.authenticated_user). Mirrors PHP Lighthouse's @guard.
8
9
  class Lighthouse::GraphQL::DirectiveResolvers::GuardDirectiveResolver < Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver
9
10
  def self.directive_name = 'guard'
10
11
 
@@ -24,7 +25,7 @@ class Lighthouse::GraphQL::DirectiveResolvers::GuardDirectiveResolver < Lighthou
24
25
  inner = Lighthouse::GraphQL::DirectiveResolvers::Resolution.capture(target_type_class, method_name, @field_def, field_name)
25
26
 
26
27
  wrapper = lambda do |obj, arguments, ctx|
27
- raise(::GraphQL::ExecutionError, 'Unauthenticated.') unless Lighthouse::Support::Authorization.authenticated?(ctx)
28
+ raise Lighthouse::AuthenticationError unless Lighthouse::Support::Authorization.authenticated?(ctx)
28
29
 
29
30
  inner.call(obj, arguments, ctx)
30
31
  end
@@ -6,10 +6,24 @@ module Lighthouse
6
6
  # missing @validator class. A server bug, so not a client-facing error.
7
7
  class DefinitionError < StandardError; end
8
8
 
9
- # Raised by the @can* family when the policy denies the ability.
9
+ # Raised by @guard and @auth when no user is signed in. PHP Lighthouse's
10
+ # message; `extensions.code` is Apollo's UNAUTHENTICATED, so a client can
11
+ # tell it apart without matching the text (send the user to sign in).
12
+ class AuthenticationError < ::GraphQL::ExecutionError
13
+ CODE = 'UNAUTHENTICATED'
14
+
15
+ def initialize(message = 'Unauthenticated.', extensions: {}, **options)
16
+ super(message, extensions: { 'code' => CODE }.merge(extensions), **options)
17
+ end
18
+ end
19
+
20
+ # Raised by the @can* family when the policy denies the ability, with
21
+ # Apollo's FORBIDDEN as `extensions.code`.
10
22
  class AuthorizationError < ::GraphQL::ExecutionError
11
- def initialize(message = 'This action is unauthorized.', **options)
12
- super
23
+ CODE = 'FORBIDDEN'
24
+
25
+ def initialize(message = 'This action is unauthorized.', extensions: {}, **options)
26
+ super(message, extensions: { 'code' => CODE }.merge(extensions), **options)
13
27
  end
14
28
  end
15
29
 
@@ -23,7 +23,7 @@ module Lighthouse::Events::ExecutionTrace
23
23
  class << self
24
24
  def start(schema, query)
25
25
  Lighthouse::Events.dispatch(
26
- Lighthouse::Events::StartExecution.new(schema, query.document, query.provided_variables, query.operation_name, query.context)
26
+ Lighthouse::Events::StartExecution.new(schema, query.document, query.provided_variables, query.operation_name, query.context, query)
27
27
  )
28
28
  end
29
29
 
@@ -38,7 +38,7 @@ module Lighthouse::Events::ExecutionTrace
38
38
  manipulate = Lighthouse::Events::ManipulateResult.new(result)
39
39
  Lighthouse::Events.dispatch(manipulate)
40
40
  result.replace(manipulate.result) unless manipulate.result.equal?(result)
41
- Lighthouse::Events.dispatch(Lighthouse::Events::EndExecution.new(result))
41
+ Lighthouse::Events.dispatch(Lighthouse::Events::EndExecution.new(result, query))
42
42
  end
43
43
 
44
44
  def merge_extensions(result, responses)
@@ -55,17 +55,23 @@ module Lighthouse::Events
55
55
  end
56
56
 
57
57
  # A query is about to run. `query` is its parsed GraphQL::Language::Nodes::Document
58
- # (nil if it does not parse). Fires once per operation of a multiplex.
58
+ # (nil if it does not parse), `operation_name` the one the client gave.
59
+ # Fires once per operation of a multiplex: in a batch, every StartExecution
60
+ # comes before any EndExecution, as graphql-ruby runs the operations
61
+ # together. `graphql_query` (the GraphQL::Query) is the one the operation's
62
+ # EndExecution carries too, to pair them.
59
63
  class StartExecution < Event
60
- attr_reader :schema, :query, :variables, :operation_name, :context
64
+ attr_reader :schema, :query, :variables, :operation_name, :context, :graphql_query
61
65
 
62
- def initialize(schema, query, variables, operation_name, context)
66
+ # PHP Lighthouse's five, positional as there, then the query.
67
+ def initialize(schema, query, variables, operation_name, context, graphql_query = nil) # rubocop:disable Metrics/ParameterLists
63
68
  super()
64
69
  @schema = schema
65
70
  @query = query
66
71
  @variables = variables
67
72
  @operation_name = operation_name
68
73
  @context = context
74
+ @graphql_query = graphql_query
69
75
  end
70
76
  end
71
77
 
@@ -95,14 +101,22 @@ module Lighthouse::Events
95
101
  end
96
102
  end
97
103
 
98
- # A query ran and its result is final.
104
+ # A query ran and its result is final. `graphql_query` is the GraphQL::Query
105
+ # its StartExecution carried; `operation_name` the operation that ran (nil
106
+ # for an anonymous one), and `context` its context. PHP Lighthouse's carries
107
+ # the result only, where a batch runs its operations one after the other.
99
108
  class EndExecution < Event
100
- attr_reader :result
109
+ attr_reader :result, :graphql_query
101
110
 
102
- def initialize(result)
111
+ def initialize(result, graphql_query = nil)
103
112
  super()
104
113
  @result = result
114
+ @graphql_query = graphql_query
105
115
  end
116
+
117
+ def operation_name = graphql_query&.selected_operation_name
118
+
119
+ def context = graphql_query&.context
106
120
  end
107
121
 
108
122
  # The operation(s) ran: the result, or for a batch an Array of results.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lighthouse
4
4
  module GraphQL
5
- VERSION = '0.8.0'
5
+ VERSION = '0.8.1'
6
6
  end
7
7
  end
@@ -6,13 +6,14 @@ module Lighthouse
6
6
  module ClassMethods
7
7
  # The schema the operations run on: a schema class, its name (constantized
8
8
  # per request) or a block (evaluated in the controller, per request).
9
- def lighthouse_schema: (?(Class | String | Symbol)? schema) ?{ () -> untyped } -> untyped
9
+ def lighthouse_schema: (?(_Schema | String | Symbol)? schema) ?{ () -> _Schema } -> (_Schema | String | Symbol | Proc)?
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  # The operation's result, or nil when a @throttle performed the response.
15
- def lighthouse_execute: (String? query, ?variables: untyped, ?operation_name: String?, ?extensions: Hash[untyped, untyped]?, ?context: Hash[Symbol, untyped]) -> Hash[String, untyped]?
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]?
16
17
 
17
18
  # Dispatch StartRequest, yield, dispatch EndRequest; only the outermost call does.
18
19
  def lighthouse_request: [T] () { () -> T } -> T
@@ -24,10 +25,10 @@ module Lighthouse
24
25
  def lighthouse_context: () -> Hash[Symbol, untyped]
25
26
 
26
27
  # The schema class `lighthouse_schema` names.
27
- def graphql_schema: () -> untyped
28
+ def graphql_schema: () -> _Schema
28
29
 
29
30
  # The `variables` parameter as a Hash: from a JSON String, a Hash or parameters.
30
- def graphql_variables: (untyped param) -> Hash[String, untyped]
31
+ def graphql_variables: ((Hash[String | Symbol, untyped] | String | _Parameters)? param) -> Hash[String | Symbol, untyped]
31
32
  end
32
33
 
33
34
  module Controller
@@ -35,7 +36,7 @@ module Lighthouse
35
36
 
36
37
  # The action: dispatches StartRequest, runs the operation (or a batch),
37
38
  # sets Cache-Control, renders JSON, dispatches EndRequest.
38
- def execute: () -> untyped
39
+ def execute: () -> void
39
40
  end
40
41
  end
41
42
  end
@@ -95,13 +95,16 @@ module Lighthouse
95
95
  FORMATS: Array[String]
96
96
  FILENAMES: Hash[String, String]
97
97
 
98
- def self?.print: (untyped schema, ?format: String | Symbol) -> String
99
- def self?.app_schema: (?String? name) -> untyped
100
- def self?.output: () -> Hash[Symbol, untyped]?
101
- def self?.output_content: (?Hash[Symbol, untyped]? setting) -> String
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
102
105
  # Writes unless the file holds `content` already; true when it wrote.
103
106
  def self?.write: (path path, String content) -> bool
104
- def self?.stale?: (?Hash[Symbol, untyped]? setting) -> bool
107
+ def self?.stale?: (?output? setting) -> bool
105
108
  end
106
109
 
107
110
  # Development's report on the schema, on boot and every reload: logged
@@ -110,8 +113,8 @@ module Lighthouse
110
113
  LIST_LIMIT: Integer
111
114
 
112
115
  # The report's [level, text] lines; nil when there is nothing to do.
113
- def self?.refresh: (?logger: untyped) -> Array[[Symbol, String]]?
114
- def self?.report: (Hash[Symbol, untyped]? output) -> Array[[Symbol, String]]
116
+ def self?.refresh: (?logger: _Logger?) -> Array[[Symbol, String]]?
117
+ def self?.report: (SchemaPrinter::output? output) -> Array[[Symbol, String]]
115
118
  end
116
119
  end
117
120
 
@@ -133,30 +136,32 @@ module Lighthouse
133
136
  # The base of the built-in field directives, and of a custom one:
134
137
  # subclass it and implement `define_resolver`.
135
138
  class BaseDirectiveResolver
136
- # graphql-ruby's field and type definitions, and the directive's AST node.
137
- @field_def: untyped
138
- @type_def: untyped
139
- @directive_node: untyped
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, ...
140
145
  @opts: Hash[Symbol, untyped]
141
146
 
142
- def initialize: (untyped field_def, untyped type_def, untyped directive_node, ?Hash[Symbol, untyped] opts) -> void
147
+ def initialize: (_FieldDefinition field_def, _NamedType type_def, _DirectiveNode? directive_node, ?Hash[Symbol, untyped] opts) -> void
143
148
 
144
149
  # Install the field's resolver on `target_type_class` (a graphql-ruby type class).
145
- def define_resolver: (untyped target_type_class) -> untyped
150
+ def define_resolver: (Class target_type_class) -> void
146
151
 
147
152
  # `ctx`: the query's context, which @builder on an argument receives.
148
- def apply_where_filters: (relation relation, untyped args, ?context? ctx) -> relation
153
+ def apply_where_filters: (relation relation, _ArgumentSet? args, ?context? ctx) -> relation
149
154
  def apply_arg_builders: (relation relation, arguments args_h, ?context? ctx) -> relation
150
155
  def apply_field_builders: (relation relation, ?arguments args_h, ?context? ctx) -> relation
151
156
  def constantize_model: (String? name) -> Class?
152
157
  def apply_scopes: (relation relation) -> relation
153
158
 
154
159
  # The literal value of an argument of this directive.
155
- def directive_arg: (String name) -> untyped
160
+ def directive_arg: (String name) -> literal
156
161
  def resolver_method_name: () -> String
157
162
  # The field's resolver so far, for a directive that wraps it.
158
- def capture_inner: (untyped target_type_class) -> untyped
159
- def install: (untyped target_type_class, untyped callable) -> untyped
163
+ def capture_inner: (Class target_type_class) -> _Resolver
164
+ def install: (Class target_type_class, _Resolver callable) -> void
160
165
  # The model the directive acts on; raises DefinitionError when there is none.
161
166
  def model_class: () -> Class
162
167
  end
@@ -165,9 +170,9 @@ module Lighthouse
165
170
  class BuilderApplier
166
171
  DEFINITION: String
167
172
 
168
- def self.apply: (relation relation, untyped field_def_ast_node, arguments args, context ctx, untyped resolver_instance) -> relation
169
- def self.apply_directive: (relation relation, untyped directive_node, arguments args, context ctx, untyped resolver_instance) -> relation
170
- def self.extract_directive_arg: (untyped directive_node, String name) -> untyped
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
171
176
  end
172
177
  end
173
178
 
@@ -179,19 +184,20 @@ module Lighthouse
179
184
  include Contracts::ArgBuilder
180
185
 
181
186
  # graphql-ruby's AST nodes for the argument and the directive on it.
182
- @arg_node: untyped
183
- @directive_node: untyped
187
+ @arg_node: _Named
188
+ @directive_node: _DirectiveNode
184
189
 
185
- def initialize: (untyped arg_node, untyped directive_node) -> void
190
+ def initialize: (_Named arg_node, _DirectiveNode directive_node) -> void
186
191
 
187
- # 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).
188
194
  def handle_builder: (relation relation, untyped value) -> relation
189
195
 
190
196
  private
191
197
 
192
198
  # The directive's `key:`, else the argument's name in snake_case.
193
199
  def column: () -> String
194
- def arel_column: (relation relation) -> untyped
200
+ def arel_column: (relation relation) -> _ArelNode
195
201
  end
196
202
  end
197
203
  end
@@ -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: (untyped event) -> untyped
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
- def self.listen: (Class event_class, ?_Listener? callable) ?{ (untyped event) -> untyped } -> _Listener
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: (untyped event) -> Array[untyped]
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: untyped
55
+ attr_reader request: _Request
39
56
 
40
- def initialize: (untyped request) -> void
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: untyped
78
+ attr_accessor document_ast: _Document
62
79
 
63
- def initialize: (untyped document_ast) -> void
80
+ def initialize: (_Document document_ast) -> void
64
81
  end
65
82
 
66
83
  class StartExecution < Event
67
- attr_reader schema: untyped
68
- attr_reader query: untyped
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: untyped
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: (untyped schema, untyped query, Hash[String, untyped]? variables, String? operation_name, untyped context) -> void
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, untyped]
98
+ attr_reader result: Hash[String, json]
79
99
  attr_reader query_complexity: Integer?
80
100
 
81
- def initialize: (Hash[String, untyped] result, Integer? query_complexity) -> void
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, untyped]
105
+ attr_accessor result: Hash[String, json]
86
106
 
87
- def initialize: (Hash[String, untyped] result) -> void
107
+ def initialize: (Hash[String, json] result) -> void
88
108
  end
89
109
 
90
110
  class EndExecution < Event
91
- attr_reader result: Hash[String, untyped]
92
-
93
- def initialize: (Hash[String, untyped] result) -> void
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: untyped
122
+ attr_reader result_or_results: _Result | Array[_Result]
98
123
 
99
- def initialize: (untyped result_or_results) -> void
124
+ def initialize: (_Result | Array[_Result] result_or_results) -> void
100
125
  end
101
126
 
102
127
  class EndRequest < Event
103
- attr_reader response: untyped
128
+ attr_reader response: _Response
104
129
 
105
- def initialize: (untyped response) -> void
130
+ def initialize: (_Response response) -> void
106
131
  end
107
132
 
108
133
  class ValidateSchema < Event
109
- attr_reader schema: untyped
134
+ attr_reader schema: _Schema
110
135
 
111
- def initialize: (untyped schema) -> void
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: untyped
142
+ attr_reader content: json
118
143
 
119
- def initialize: (String | Symbol key, untyped content) -> void
144
+ def initialize: (String | Symbol key, json content) -> void
120
145
  end
121
146
  end
122
147
  end
@@ -6,7 +6,7 @@ module Lighthouse
6
6
  Config: singleton(Lighthouse::Config)
7
7
 
8
8
  # A GraphQL::Schema subclass.
9
- type schema = untyped
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[untyped, untyped],
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, untyped]
42
- attr_reader type_extensions: Hash[String, Array[untyped]]
43
- attr_reader directives: Hash[String, untyped]
44
- attr_reader schema_definitions: Array[untyped]
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: (untyped document) -> DocumentAST
47
+ def self.from_document: (_Document document) -> DocumentAST
48
48
 
49
49
  def initialize: () -> void
50
- def add: (untyped definition) -> untyped
50
+ def add: (_Node definition) -> void
51
51
  # Adds a type, or replaces the one of the same name.
52
- def put_type: (untyped definition) -> self
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 } -> untyped
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: () -> untyped
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, untyped]
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: untyped, **untyped options) -> untyped
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[untyped]
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, untyped extensions) -> String?
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`? `args` are the
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: untyped, field: untyped, scope: untyped) -> String
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: (untyped result) -> String?
144
- # Set the header on a Rails (or Rack) response, and return it.
145
- def self?.apply: (untyped response, untyped result) -> String?
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: (untyped schema, ?Hash[String, Symbol] root_kinds) -> untyped
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: (untyped query) -> Integer?
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:)
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 and Active Record ship no RBS every app has, so the values that
6
- # come from them are aliases of untyped, named for what they hold.
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
- # An ActiveRecord::Relation, or anything with its query interface.
9
- type relation = untyped
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
- # The request's GraphQL::Query::Context.
15
- type context = untyped
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: (Hash[Symbol, untyped] values) -> Hash[Symbol | String, untyped]
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, untyped id) -> String
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, untyped record, String | Symbol ability, ?Array[untyped] args) -> boolish
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: (untyped record) -> boolish
76
- def force_delete: (untyped record) -> boolish
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
 
@@ -102,8 +272,8 @@ module Lighthouse
102
272
  def self.ide_helper=: (bool? enabled) -> bool?
103
273
 
104
274
  # The file development keeps the client schema in: a path, or { path:, schema: }; nil: none.
105
- def self.schema_output: () -> (path | Hash[Symbol, untyped])?
106
- def self.schema_output=: ((path | Hash[Symbol, untyped])? output) -> (path | Hash[Symbol, untyped])?
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 })?
107
277
 
108
278
  # Log the schema's build on boot and every reload; nil: in a development server.
109
279
  def self.schema_log: () -> bool
@@ -117,8 +287,6 @@ module Lighthouse
117
287
  def self.resolver_namespaces: () -> Array[String]
118
288
  def self.resolver_namespaces=: (Array[String] namespaces) -> Array[String]
119
289
 
120
- def self.directive_map: () -> Hash[untyped, untyped]
121
-
122
290
  # An ActiveSupport::Cache::Store; Rails.cache by default.
123
291
 
124
292
  def self.transactional_mutations: () -> bool
@@ -138,13 +306,13 @@ module Lighthouse
138
306
 
139
307
  def self.persisted_queries: () -> bool
140
308
  def self.persisted_queries=: (bool? enabled) -> bool?
141
- def self.persisted_queries_store: () -> untyped
142
- def self.persisted_queries_store=: (untyped store) -> untyped
309
+ def self.persisted_queries_store: () -> _CacheStore
310
+ def self.persisted_queries_store=: (_CacheStore? store) -> _CacheStore?
143
311
  def self.persisted_queries_ttl: () -> Numeric?
144
312
  def self.persisted_queries_ttl=: (Numeric? seconds) -> Numeric?
145
313
  # A JSON file, a Hash of operations, or a callable answering either.
146
- def self.persisted_queries_manifest: () -> (path | Hash[untyped, untyped] | ^() -> (path | Hash[untyped, untyped])?)?
147
- def self.persisted_queries_manifest=: ((path | Hash[untyped, untyped] | ^() -> (path | Hash[untyped, untyped])?)? manifest) -> untyped
314
+ def self.persisted_queries_manifest: () -> manifest_source?
315
+ def self.persisted_queries_manifest=: (manifest_source? manifest) -> manifest_source?
148
316
  def self.persisted_queries_only: () -> bool
149
317
  def self.persisted_queries_only=: (bool? enabled) -> bool?
150
318
 
@@ -201,9 +369,19 @@ module Lighthouse
201
369
  end
202
370
 
203
371
  # A GraphQL::ExecutionError (declared from StandardError, which it descends
204
- # 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).
205
374
  class AuthorizationError < StandardError
206
- def initialize: (?String message, **untyped options) -> void
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
207
385
  end
208
386
 
209
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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaz Innovation