lighthouse-graphql 0.8.1 → 0.9.0

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +166 -1
  3. data/docs/authorization.md +5 -1
  4. data/docs/configuration.md +71 -3
  5. data/docs/custom-directives.md +22 -0
  6. data/docs/defer.md +352 -0
  7. data/docs/directives.md +106 -1
  8. data/docs/events.md +30 -1
  9. data/docs/filtering-and-ordering.md +488 -0
  10. data/docs/getting-started.md +1 -1
  11. data/docs/performance.md +9 -0
  12. data/docs/relay.md +27 -0
  13. data/docs/resolvers.md +14 -2
  14. data/docs/testing.md +99 -0
  15. data/lib/lighthouse/complexity.rb +4 -2
  16. data/lib/lighthouse/config.rb +28 -11
  17. data/lib/lighthouse/contracts/field_resolver.rb +32 -0
  18. data/lib/lighthouse/contracts/search_builder.rb +16 -0
  19. data/lib/lighthouse/controller.rb +94 -18
  20. data/lib/lighthouse/defer.rb +114 -0
  21. data/lib/lighthouse/directive_resolvers/aggregate_resolver.rb +1 -0
  22. data/lib/lighthouse/directive_resolvers/all_resolver.rb +30 -1
  23. data/lib/lighthouse/directive_resolvers/argument_binding.rb +1 -3
  24. data/lib/lighthouse/directive_resolvers/argument_transforms_resolver.rb +14 -4
  25. data/lib/lighthouse/directive_resolvers/association_resolvers.rb +1 -0
  26. data/lib/lighthouse/directive_resolvers/base.rb +99 -49
  27. data/lib/lighthouse/directive_resolvers/builder_applier.rb +24 -18
  28. data/lib/lighthouse/directive_resolvers/can_resolvers.rb +28 -2
  29. data/lib/lighthouse/directive_resolvers/count_resolver.rb +1 -0
  30. data/lib/lighthouse/directive_resolvers/field_resolver.rb +4 -0
  31. data/lib/lighthouse/directive_resolvers/find_resolver.rb +31 -16
  32. data/lib/lighthouse/directive_resolvers/first_resolver.rb +6 -3
  33. data/lib/lighthouse/directive_resolvers/global_id_resolver.rb +6 -0
  34. data/lib/lighthouse/directive_resolvers/global_id_types.rb +83 -0
  35. data/lib/lighthouse/directive_resolvers/model_mutation_resolver.rb +2 -0
  36. data/lib/lighthouse/directive_resolvers/paginate_resolver.rb +27 -4
  37. data/lib/lighthouse/directive_resolvers/throttle_resolver.rb +17 -6
  38. data/lib/lighthouse/directives/arguments/base.rb +14 -0
  39. data/lib/lighthouse/directives/arguments/filters.rb +6 -0
  40. data/lib/lighthouse/directives/arguments/more_filters.rb +3 -0
  41. data/lib/lighthouse/directives/arguments/search.rb +34 -0
  42. data/lib/lighthouse/directives/arguments/soft_deletes.rb +11 -0
  43. data/lib/lighthouse/directives/model_directive.rb +1 -1
  44. data/lib/lighthouse/directives/registry.rb +1 -1
  45. data/lib/lighthouse/events/execution_trace.rb +6 -1
  46. data/lib/lighthouse/events/lifecycle.rb +2 -1
  47. data/lib/lighthouse/events.rb +9 -0
  48. data/lib/lighthouse/field_resolver_stack.rb +22 -21
  49. data/lib/lighthouse/global_id.rb +28 -0
  50. data/lib/lighthouse/graphql/version.rb +1 -1
  51. data/lib/lighthouse/incremental/body.rb +76 -0
  52. data/lib/lighthouse/incremental/defer_directive.rb +34 -0
  53. data/lib/lighthouse/incremental/delivery.rb +94 -0
  54. data/lib/lighthouse/incremental/document.rb +242 -0
  55. data/lib/lighthouse/incremental/gone.rb +6 -0
  56. data/lib/lighthouse/incremental/legacy.rb +75 -0
  57. data/lib/lighthouse/incremental/multipart.rb +76 -0
  58. data/lib/lighthouse/incremental/plan.rb +249 -0
  59. data/lib/lighthouse/incremental/rules.rb +116 -0
  60. data/lib/lighthouse/incremental/run.rb +302 -0
  61. data/lib/lighthouse/incremental/serializer.rb +37 -0
  62. data/lib/lighthouse/incremental/state.rb +204 -0
  63. data/lib/lighthouse/incremental/stream_directive.rb +41 -0
  64. data/lib/lighthouse/incremental/stream_trace.rb +93 -0
  65. data/lib/lighthouse/incremental/tree.rb +68 -0
  66. data/lib/lighthouse/namespaces.rb +2 -0
  67. data/lib/lighthouse/nested_mutations/belongs_to_operations.rb +2 -2
  68. data/lib/lighthouse/operations.rb +6 -2
  69. data/lib/lighthouse/pagination.rb +61 -15
  70. data/lib/lighthouse/persisted_queries.rb +53 -8
  71. data/lib/lighthouse/rb_lighthouse.rb +35 -0
  72. data/lib/lighthouse/resolve_info.rb +7 -1
  73. data/lib/lighthouse/search/auto.rb +21 -0
  74. data/lib/lighthouse/search/enhancer.rb +127 -0
  75. data/lib/lighthouse/search/field_check.rb +171 -0
  76. data/lib/lighthouse/search/pg_search.rb +76 -0
  77. data/lib/lighthouse/search/query.rb +35 -0
  78. data/lib/lighthouse/search/result.rb +181 -0
  79. data/lib/lighthouse/search/searchkick.rb +292 -0
  80. data/lib/lighthouse/search/searchkick_index.rb +54 -0
  81. data/lib/lighthouse/search/searchkick_options.rb +74 -0
  82. data/lib/lighthouse/search.rb +78 -0
  83. data/lib/lighthouse/support/argument_walk.rb +81 -0
  84. data/lib/lighthouse/support/count.rb +16 -0
  85. data/lib/lighthouse/support/failures.rb +28 -0
  86. data/lib/lighthouse/support/memo.rb +72 -0
  87. data/lib/lighthouse/support/model_resolver.rb +24 -0
  88. data/lib/lighthouse/support/relations.rb +31 -0
  89. data/lib/lighthouse/support/soft_deletes.rb +42 -8
  90. data/lib/lighthouse/testing.rb +81 -0
  91. data/sig/lighthouse/controller.rbs +34 -1
  92. data/sig/lighthouse/directives.rbs +46 -5
  93. data/sig/lighthouse/events.rbs +7 -0
  94. data/sig/lighthouse/graphql.rbs +117 -0
  95. data/sig/lighthouse/search.rbs +132 -0
  96. data/sig/lighthouse.rbs +69 -1
  97. metadata +39 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9256c2a7c721e495cf5c3754da6b1f684a1d15822014435150c08612af4964e6
4
- data.tar.gz: 8acfd179e8ede63d8d9f7addfb85e5472435078e9f389ca684d543203353ef88
3
+ metadata.gz: 8545d3d90944dac8ea9e55b6fc19064b1895b160e2c2bd9459264456eed12dc8
4
+ data.tar.gz: eb9631fdd402f4e699a0976ee6f8c5592b6a3231a7fc52d883c40ed7ea2b0a7a
5
5
  SHA512:
6
- metadata.gz: 066e474500d83f2c5d8809275819a96941fa4e303bb3d2984a8652a7e54f2bf08e0259ef40f7ddbf8105eb5dc40485588c1e760c368c7cd9205823e44fc1c50a
7
- data.tar.gz: 013fffcb17f486024bcb94f3ba347973326bbbaf1cfdfac3b2d7ba9be90a808e64c21d37d0eac5c74d4c552f8b5ed74b40c0689715a6041ae5d232de3560bee4
6
+ metadata.gz: b443a6a974eaf9fad8ceab3eb3037a8fc03fc7de0d1d4944c5ffd26205fafed5137a12a680823dad5b74f5f2094d217ab2d9002abac44de4981352631e193c82
7
+ data.tar.gz: 929747b79b50bdeca4da61a47eecbab7c09a41a95ec3eea3797fc7e8d2e93a5c509105f0edd35873a007988eb1971c79690c1a76a411bc1133d24c5620f0caee
data/CHANGELOG.md CHANGED
@@ -6,6 +6,169 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.9.0] - 2026-10-30
10
+
11
+ ### Added
12
+
13
+ - **`@search`**, PHP Lighthouse's directive, with its definition: on a `String` argument, a string
14
+ from the client (`""` too) runs the field's query through a full-text engine instead of the
15
+ database; `null` or nothing falls back to it. `within:` names the index (Searchkick) or the
16
+ `pg_search_scope`. Ruby has no Laravel Scout, so two gems back it behind one adapter seam
17
+ (`Lighthouse::Search`), neither a dependency of Lighthouse: **Searchkick** (Elasticsearch /
18
+ OpenSearch) answers with the records it found, in relevance order, for `@all`, `@paginate`
19
+ (all three types; the total comes with the page, one request, and `first: 0` can count, which Scout
20
+ cannot), `@first` (the best match), `@find` (the one match; more than one is an error, as in PHP
21
+ Lighthouse) and a resolver of your own. The total is always exact past the 10,000 matches the engines
22
+ stop counting at (`track_total_hits`, which an app's `body_options` may not set, so that no page
23
+ serves a record `@canQuery` did not check), a search reads within the index's result window
24
+ (`index.max_result_window`, read from the engine, the index `within:` names too; from the model's
25
+ options, whatever their keys, when it cannot be read): a page past it is an error the client reads,
26
+ and `@all` reads what the client asks for (`first`, an argument's `@limit`, else every match),
27
+ 10,000 records at most at once, even with `deep_paging`, with an error next to them when that
28
+ answers fewer than asked while more match. An index's mapping and settings are read at most once a
29
+ minute, one thread at a time (a failed read once in five seconds, reported to `Config.on_error`, its
30
+ cause named in the error it leads to; they need the `view_index_metadata` privilege). An `@builder`
31
+ may set only the Searchkick options that rank or shape the hits (`Searchkick::Options::BUILDER_OPTIONS`), never
32
+ `load:`, `index_name:`, `unscope:` or what pages and counts them; its `scope_results:` runs before
33
+ Lighthouse's. A search counts only what it can load: a Searchkick model with a default scope
34
+ (any, as declared, since what one selects may depend on the request) or a `search_results` scope
35
+ defines `search_where`, the engine's `where:` for the
36
+ same records (a tenant's, a published flag's), which every search ANDs in; and pages follow the
37
+ engine's positions, so a hit that does not load (a stale index) is neither shown twice nor skips
38
+ another, in `SIMPLE` and `CONNECTION` alike. **pg_search** (2.3 and 2.4) is a
39
+ scope on the relation, so `scopes:`, `@builder`, `@whereAuth`, the argument filters, `@orderBy`,
40
+ nested fields, batched nested `@paginate` and mass mutations all apply on top of it, the rank
41
+ first (before the model's default order too), then the orders that break its ties, then the
42
+ primary key, so equal matches keep one order on every field. A mass mutation (`@delete`, ...) counts a `@search` argument as a filter only when
43
+ the search runs, as PHP Lighthouse. The engine is detected per model, and for a model with both
44
+ gems a `within:` naming a pg_search scope picks pg_search; `Config.search` replaces the detection. `@eq`,
45
+ `@trashed` and `@builder` on an argument narrow a Searchkick search through the new
46
+ `Contracts::SearchBuilder` and `Lighthouse::Search::Query`, as Scout's `ScoutBuilderDirective`,
47
+ every condition holding (one column's conditions are ANDed, never overwritten); `@limit`, which
48
+ only cuts the result, is taken too.
49
+ `@trashed` filters on the soft-delete column the index holds, the one `Config.soft_deletes` filters
50
+ the database on (with paranoia's sentinel value; adapters may tell it with `column(model)` and
51
+ `kept_value(model)`; it is the one place to name it), and the records load through the database's
52
+ `@trashed` (`ONLY` / `WITH` past the default scope that hides them, paranoia's, discard's). The
53
+ column is Lighthouse's: a model whose default scope hides trashed records is filtered on it in the
54
+ engine when the client does not say, and its `search_where` leaves it out (naming it anywhere is an
55
+ error at the first search).
56
+ A model's `search_results` scope, when it has one, is what a search of it may return: Searchkick
57
+ loads the records it finds through it (`scope_results:`), and through each `@eq` on a column of the
58
+ model (a scalar, a list or a Range of them; not an engine operator), and through the model's default
59
+ scope when it loads `unscope: true`, so a record a stale index still holds, or holds as it was, is not
60
+ returned. An STI subclass searching its parent's index needs `inheritance: true` or `search_where`. Each field's
61
+ search is its own, nothing kept in the query's context. `@canQuery` on a searched field checks every record the search finds, as PHP
62
+ Lighthouse does (with Searchkick, 10,000 at most: a search that finds more a page could reach is an
63
+ error), and the hits it checked serve the field's page, handed to the field's resolver for that
64
+ resolution only (never through the query's context), so nothing the index gains in between is
65
+ answered unchecked; and `resolve_info.enhance_builder` answers a `Lighthouse::Search::Result` for a
66
+ Searchkick search, as PHP Lighthouse answers Scout's builder, so a field your own class resolves
67
+ can search through it; the relation it gets must select what the model's own does (`Post.all`,
68
+ or `Post`), any other is refused. Each resolver class declares whether it applies a search and
69
+ takes an engine's records (`applies_search?`, `takes_search_results?`; `Contracts::FieldResolver`
70
+ says no by default, so a directive of your own opts in). A filter of a searched field that raises
71
+ fails the field, reported to `Config.on_error`, rather than answer what it would have left out; so
72
+ does the engine, whenever a page asks it.
73
+ See [Full-text search](docs/filtering-and-ordering.md#full-text-search).
74
+ - **`@defer` (experimental)**, PHP Lighthouse's extension, on the specification draft's terms.
75
+ `use Lighthouse::GraphQL::Defer` in the schema class adds the directive as the draft has it
76
+ (graphql-spec PR #1110: on fragments, with `if` and `label`, answered as `pending` /
77
+ `incremental` / `completed` / `hasNext`), and `Lighthouse::GraphQL::Controller` streams the
78
+ response of an operation that defers as `multipart/mixed`, as PHP Lighthouse does once its
79
+ provider is registered: nothing else to set up, from the same action and routes (`GET` too), as a
80
+ body Rails streams in the request's thread (no `ActionController::Live`). It streams to any
81
+ client but one whose `Accept` header leaves `multipart/mixed` out (`application/json` alone),
82
+ which gets one ordinary response; GraphiQL's `application/json, multipart/mixed` streams. A
83
+ client that names Apollo's older format (`multipart/mixed;deferSpec=20220824`: Apollo Client 3,
84
+ Apollo Client 4's `Defer20220824Handler`) gets its payloads in that format (`path` and `label`,
85
+ no `pending` / `completed`). As PHP Lighthouse's, a response goes in
86
+ rounds, one payload each, and stops deferring past its limits, with their names and meaning:
87
+ `defer_max_nested_fields` and `defer_max_execution_ms` (0, the default, for none). PHP
88
+ Lighthouse's rules hold: no `@defer` on a root mutation field ("The @defer directive cannot be
89
+ used on a root mutation field.", inline or through a named fragment), `@skip` and `@include`
90
+ answer first, and a deferred field's errors come with it. The rules are checked for every query,
91
+ streamed or not, by a graphql-ruby analyzer, on the client's document, which is never rewritten:
92
+ listeners, `query_string` and tracing see it as sent. Unlike PHP Lighthouse's, `@defer` goes on
93
+ fragments, not fields (`... @defer { parent { name } }` for `parent @defer { name }`); the format
94
+ is the draft's, not Apollo's 2018 one; a round runs only the pending fragments, on the objects
95
+ already loaded (`GraphQL::Query::Partial`), not the whole query again, so a field resolves once, a
96
+ mutation runs once and the Dataloader batches across a round; a field also asked for outside the
97
+ fragment comes in the first payload, once, and the fragment still completes, as the draft has it
98
+ (PHP Lighthouse and Apollo do not defer it); the fields the same fragments select make one
99
+ grouped field set, as the draft's, so a fragment that fails fails only those it shares fields
100
+ with, and sends nothing (not even what it adds to a shared field); and a Non-Null field can be deferred. Needs
101
+ graphql-ruby 2.5.23. The first pass is the schema's `execute` (an app's own override too), as on
102
+ the JSON path. See [defer.md](docs/defer.md), which lists the differences.
103
+ - **`Lighthouse::GraphQL::Testing`**, PHP Lighthouse's `MakesGraphQLRequests`, for request specs and
104
+ integration tests: `graphql(query, variables)`, `post_graphql` (a batch too), `multipart_graphql`
105
+ (uploads), `introspect`, `introspect_type(name)`, `introspect_directive(name)`, and
106
+ `stream_graphql`, PHP Lighthouse's `streamGraphQL`, which answers the payloads of a streamed
107
+ response (`NotStreamed` for one that came whole). See [testing.md](docs/testing.md).
108
+ - **`@stream` (experimental)**, with `@defer` (PHP Lighthouse has none): `users @stream(initialCount: 2)
109
+ { name }` answers the first items at once and the rest in a later part (`items`, the draft's
110
+ format). A graphql-ruby trace module on the schema that uses the plugin cuts the list after its
111
+ resolver ran, once, on any of its fields; a field that is not streamed costs it next to nothing. The later items run
112
+ what the field's declarations select, together, so the Dataloader still batches. Items may carry
113
+ `@defer`. A `null` item where the list's items are non-null fails the stream. A negative
114
+ `initialCount` is a field error.
115
+
116
+ ### Changed
117
+
118
+ - **A filter that raises fails its field; it is never skipped.** An argument directive, a
119
+ `@builder` or `@whereAuth` that raised was reported to `Config.on_error` and dropped, and the
120
+ field answered without it, or without any filter: a `@builder` that enforces tenancy, a
121
+ `@whereAuth` whose user has no id, or a `@builder` class that does not exist let the client read
122
+ every row, and a mass `@delete` whose builder raised deleted every row. Now the error is
123
+ reported, then raised as it is, on every field (lists, pages, relationships, counts, mass
124
+ mutations, `enhance_builder`): the schema's `rescue_from` maps it as any resolver's error, in test
125
+ and production alike. A schema error found only as a query runs (a `@builder` whose class or
126
+ method cannot be found, a search a field's directives would narrow) is reported and answered as
127
+ a client error. Breaking for an app that relied on a failing filter being skipped.
128
+ - **`BaseDirectiveResolver#apply_arg_builders` is removed.** It applied the argument directives
129
+ without the field's search, so a directive of your own calling it answered unsearched rows: call
130
+ `apply_where_filters`.
131
+ - **`@search` is stricter than PHP Lighthouse where it drops a constraint silently.** With an engine
132
+ outside the database (Searchkick) PHP Lighthouse ignores the field's `scopes:`, `@builder`,
133
+ `@whereAuth` and `@orderBy(column:)` when it searches, so a search that skipped `@whereAuth`
134
+ returns records the user must not see. Here that field is a schema error at build, as are `@search`
135
+ on a model that is not searchable, a `within:` that is not a string, a `@search` nothing applies
136
+ (graphql-ruby's default reader, `@create`, ...), which PHP Lighthouse ignores, and, with
137
+ Searchkick, any field but `@all`, `@paginate` of the model's whole table and a resolver of your
138
+ own, an `@canQuery` with `scopes:`, and a value graphql-ruby fills in without the client (an
139
+ argument's default, the fields of a default object) whose directive the engine cannot apply (PHP
140
+ Lighthouse fails every search of such a field). A relational engine (pg_search) applies them all.
141
+ `enhance_builder` refuses, with Searchkick, a relation that selects other records than the
142
+ model's own (a narrowed one, `unscoped`, `with_deleted`, ...), whose conditions PHP Lighthouse
143
+ drops. A Searchkick model that declares a default scope (any, whatever it reads as a request
144
+ runs) or a `search_results` scope without `search_where`, whose totals PHP Lighthouse lets count
145
+ other tenants' matches, is a schema error too; a nested `@paginate` whose parent type is no model
146
+ is one, and a record that pages an association there a client error.
147
+
148
+ ### Fixed
149
+
150
+ - **`@find` keeps `@whereAuth` and the query's context.** Its filters ran without the context, so
151
+ `@whereAuth` never saw the user and an argument `@builder` got none, and a lookup by `id` alone was
152
+ batched past the field's own query directives: `post(id:) @find @whereAuth(relation: "author")`
153
+ answered another user's post. It now passes the context, and batches only a field with no query
154
+ directive of its own.
155
+ - **`@canQuery`, `@canFind` and `@canModel` tell their model when the schema is built.** A field
156
+ whose model cannot be told (a type that is no model, and no `model:`) built, and every query of it
157
+ raised an internal error; the schema now fails to build with that message.
158
+
159
+ ## [0.8.2] - 2026-10-30
160
+
161
+ ### Fixed
162
+
163
+ - **`@globalId(decode: ID)` checks the type of the id** (#6). It kept the id and dropped the
164
+ type, so another type's global id found the record with the same number:
165
+ `user(id: <a Post's id>)` answered user 1, and `@delete` / `@forceDelete` could act on a
166
+ record the client did not name. An argument that filters the field's model by its key
167
+ (`@whereKey`, `@eq`/`@in` on the primary key, or `id`), on the field or in an input it
168
+ takes, now fails with `"…" is not a valid global id for User.` given another type's id;
169
+ a subclass (STI) or a type whose `@model` is the field's model passes. The new
170
+ `@globalId(type: "User")` names the type anywhere else. PHP Lighthouse does not check.
171
+
9
172
  ## [0.8.1] - 2026-10-30
10
173
 
11
174
  ### Changed
@@ -853,7 +1016,9 @@ had been running inside a private monorepo as a path gem before being extracted.
853
1016
  - Config-driven extension seams: `Lighthouse.configure`, `resolver_namespaces`,
854
1017
  `on_error`, and `DirectiveRegistry.register` for app-defined directives.
855
1018
 
856
- [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.1...HEAD
1019
+ [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.9.0...HEAD
1020
+ [0.9.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.2...v0.9.0
1021
+ [0.8.2]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.1...v0.8.2
857
1022
  [0.8.1]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.0...v0.8.1
858
1023
  [0.8.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.3...v0.8.0
859
1024
  [0.7.3]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.2...v0.7.3
@@ -115,7 +115,11 @@ Plus, per directive:
115
115
  scopes applied to the lookup.
116
116
  - `@canModel(model: String)`.
117
117
  - `@canQuery(model: String, scopes: [String!])`. `scopes` narrow the records
118
- being authorized, not the field's result.
118
+ being authorized, not the field's result. On a field the client searches
119
+ ([`@search`](filtering-and-ordering.md#canquery-on-a-searched-field)), the records are
120
+ the ones the search finds, every one and not only the page, as in PHP Lighthouse;
121
+ with Searchkick, 10,000 at most (a search that finds more a page could reach is an
122
+ error), and `scopes` are a schema error, as the engine cannot apply them.
119
123
 
120
124
  The model defaults to the `model:` of another directive on the field (as in
121
125
  `@count(model: "Post") @canQuery`), then to the field's return type.
@@ -114,9 +114,13 @@ This is the seam that keeps the gem free of your app's namespace.
114
114
  ### `on_error`
115
115
 
116
116
  A callable `->(error, context) { ... }` invoked when a directive or resolver
117
- swallows an error (e.g. a malformed filter). The default **raises in test** (so
118
- failures surface in your suite) and logs otherwise. Point it at your error
119
- reporter in production:
117
+ reports an error. A filter that raises (an argument directive, a `@builder`,
118
+ `@whereAuth`) is one: the error comes here, then the field fails with it, raised as
119
+ it is, so your schema's `rescue_from` maps it as any resolver's error. A schema error
120
+ found only as a query runs (a `@builder` that does not exist) comes here, and the
121
+ client reads it. A query is never answered without a filter that failed. The default
122
+ **raises in test** (so failures surface in your suite) and logs otherwise. Point it at
123
+ your error reporter in production:
120
124
 
121
125
  ```ruby
122
126
  config.on_error = ->(error, _ctx) { Sentry.capture_exception(error) }
@@ -148,6 +152,26 @@ config.persisted_queries_manifest = Rails.root.join('persisted-queries.json') #
148
152
  config.persisted_queries_only = Rails.env.production? # run nothing else
149
153
  ```
150
154
 
155
+ ### `defer_max_nested_fields` and `defer_max_execution_ms`
156
+
157
+ The limits of [`@defer`](defer.md) (experimental), PHP
158
+ Lighthouse's `defer.max_nested_fields` and `defer.max_execution_ms`. `0`, the default, is no limit.
159
+
160
+ - `defer_max_nested_fields`: how many rounds of nested deferred fragments a response may take. The
161
+ last round allowed resolves the fragments it holds where they stand, so `1` delivers everything
162
+ deferred in one payload after the first.
163
+ - `defer_max_execution_ms`: once that many milliseconds have gone since the first pass started, the
164
+ next round is the last, and resolves everything left without deferring further.
165
+
166
+ Each takes an Integer of 0 or more, or a String of digits, as `ENV` holds it
167
+ (`config.defer_max_execution_ms = ENV.fetch('DEFER_MAX_MS', 0)`). Anything else raises
168
+ `ArgumentError` when the setting is assigned, at boot, rather than when a request runs.
169
+
170
+ ```ruby
171
+ config.defer_max_nested_fields = 3
172
+ config.defer_max_execution_ms = 2_000
173
+ ```
174
+
151
175
  ### `convert_empty_strings_to_null`
152
176
 
153
177
  Makes every field behave as if it carried
@@ -208,12 +232,56 @@ class SoftDeleteAdapter
208
232
  def without_trashed(relation) = relation.unscope(where: :archived_at).where(archived_at: nil)
209
233
  def restore(record) = record.unarchive
210
234
  def force_delete(record) = record.destroy
235
+
236
+ # Optional, for @trashed in a Searchkick search: the column that marks trashed records,
237
+ # and its value for the others (nil, or a sentinel as paranoia's).
238
+ def column(_model) = :archived_at
239
+ def kept_value(_model) = nil
211
240
  end
212
241
  config.soft_deletes = SoftDeleteAdapter.new
213
242
  ```
214
243
 
244
+ A Searchkick search filters `@trashed` on the same column, and value, as the database does: the
245
+ gems' and `Column`'s are known; an adapter of your own tells them with `column` and `kept_value`, or
246
+ the search falls back to `deleted_at`.
247
+
215
248
  See [Soft deletes & global scopes](directives.md#soft-deletes-global-scopes).
216
249
 
250
+ ### `search`
251
+
252
+ Which engine searches a model, for [`@search`](directives.md#search). By default each model is
253
+ inspected: Searchkick if it calls `searchkick`, then pg_search if it includes `PgSearch::Model`
254
+ (neither gem is a dependency of Lighthouse). Set it to use one adapter for every model, or one of your own:
255
+
256
+ ```ruby
257
+ config.search = Lighthouse::Search::PgSearch.new
258
+
259
+ # Searchkick for every model (@trashed filters on the column config.soft_deletes tells):
260
+ config.search = Lighthouse::Search::Searchkick.new
261
+
262
+ # Any object answering `searchable?(model, index)` and `relational?`, and `scope(relation, query)`
263
+ # (a relational one, in the database) or `page(query, offset:, limit:)` -> [records, total],
264
+ # one entry per hit, nil for one it could not load, and every match counted; with an optional `result_window(query)` (how many
265
+ # matches it pages through; 10,000 otherwise, nil when it cannot tell), `named?(model, index)` (does
266
+ # `within:` name something of its own) and `model_error(model)` (why a model cannot be searched as it is)
267
+ config.search = MySearch.new
268
+ ```
269
+
270
+ By default, a model that uses both gems is searched with Searchkick, unless `within:` names one of
271
+ its pg_search scopes. `Lighthouse::Search::Searchkick` always asks the engine for the exact total
272
+ (`track_total_hits`, which `body_options` may not set), loads the records it finds through the
273
+ model's `search_results` scope when it has one, through `@trashed`'s filter and the `@eq` ones on a
274
+ column of the model (so a stale index never answers a record that no longer matches), filters
275
+ `@trashed` on the column `soft_deletes` tells (and filters out trashed records when the model's
276
+ default scope hides them), ANDs in the model's `search_where` (which a model whose default scope or
277
+ `search_results` narrows its records must define, leaving the soft-delete column out), and reads the
278
+ result window from the index's settings on the engine, else from the model's `max_result_window:` /
279
+ `deep_paging:`. It reads an index's mapping and settings at most once a minute, one thread at a time (a
280
+ failed read, reported to `on_error`, once in five seconds; reading them needs the `view_index_metadata`
281
+ privilege): `Lighthouse::Search::Searchkick.new(index: Lighthouse::Search::Searchkick::Index.new)`. An
282
+ `@builder` may set only the search options in `Lighthouse::Search::Searchkick::Options::BUILDER_OPTIONS`.
283
+ The adapter protocol is experimental. See [Full-text search](filtering-and-ordering.md#full-text-search).
284
+
217
285
  ### `authenticated_user`, `policy_user`, `authorizer`
218
286
 
219
287
  The authentication and authorization seams behind `@guard` and the `@can*`
@@ -44,6 +44,28 @@ def self.definition = 'directive @upcase on FIELD_DEFINITION'
44
44
  If the definition refers to types of its own (an enum argument, say), return
45
45
  them from `def self.type_definitions = { 'Mode' => 'enum Mode { A B }' }`.
46
46
 
47
+ ### With `@search`
48
+
49
+ A `@search` on a field needs its resolver to apply it, which Lighthouse asks the
50
+ resolving directive's class when the schema is built. `Contracts::FieldResolver`
51
+ answers no by default, so a `@search` on a field your directive resolves is a schema
52
+ error until the class opts in:
53
+
54
+ ```ruby
55
+ # It runs the field's argument filters, a relational search (pg_search) among them:
56
+ # apply_where_filters, or resolve_info.enhance_builder.
57
+ def self.applies_search? = true
58
+
59
+ # It also takes the records Searchkick answers with, a Lighthouse::Search::Result
60
+ # (apply_where_filters(..., search: :model) on the model's own relation).
61
+ def self.takes_search_results?(type, field_def, directive, root_kind) = true
62
+ ```
63
+
64
+ An argument directive (`Arguments::Base`) says whether, as the SDL writes it, it
65
+ changes the field's query: `def self.changes_query?(directive_node) = false` lets a
66
+ Searchkick search take it (as `@limit` without `builder: true`, which cuts the
67
+ result after). See [Full-text search](filtering-and-ordering.md#full-text-search).
68
+
47
69
  Lighthouse injects that `definition` into the schema automatically, so apps never
48
70
  hand-declare your directive, and `bin/rails lighthouse:ide_helper` writes it out
49
71
  for the IDE (see [IDE support](getting-started.md#ide-support)).