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.
@@ -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:)