lighthouse-graphql 0.8.0 → 0.8.2

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.
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaz Innovation
@@ -133,6 +133,7 @@ files:
133
133
  - lib/lighthouse/directive_resolvers/find_resolver.rb
134
134
  - lib/lighthouse/directive_resolvers/first_resolver.rb
135
135
  - lib/lighthouse/directive_resolvers/global_id_resolver.rb
136
+ - lib/lighthouse/directive_resolvers/global_id_types.rb
136
137
  - lib/lighthouse/directive_resolvers/guard_resolver.rb
137
138
  - lib/lighthouse/directive_resolvers/lazy_load_resolver.rb
138
139
  - lib/lighthouse/directive_resolvers/limit_resolver.rb