lighthouse-graphql 0.8.2 → 0.9.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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +168 -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 -0
  8. data/docs/events.md +30 -1
  9. data/docs/filtering-and-ordering.md +567 -0
  10. data/docs/getting-started.md +1 -1
  11. data/docs/performance.md +9 -0
  12. data/docs/resolvers.md +14 -2
  13. data/docs/testing.md +99 -0
  14. data/lib/lighthouse/complexity.rb +4 -2
  15. data/lib/lighthouse/config.rb +28 -11
  16. data/lib/lighthouse/contracts/field_resolver.rb +32 -0
  17. data/lib/lighthouse/contracts/search_builder.rb +16 -0
  18. data/lib/lighthouse/controller.rb +94 -18
  19. data/lib/lighthouse/defer.rb +114 -0
  20. data/lib/lighthouse/directive_resolvers/aggregate_resolver.rb +1 -0
  21. data/lib/lighthouse/directive_resolvers/all_resolver.rb +32 -3
  22. data/lib/lighthouse/directive_resolvers/argument_binding.rb +1 -3
  23. data/lib/lighthouse/directive_resolvers/association_resolvers.rb +1 -0
  24. data/lib/lighthouse/directive_resolvers/base.rb +116 -49
  25. data/lib/lighthouse/directive_resolvers/builder_applier.rb +24 -18
  26. data/lib/lighthouse/directive_resolvers/can_resolvers.rb +28 -2
  27. data/lib/lighthouse/directive_resolvers/count_resolver.rb +1 -0
  28. data/lib/lighthouse/directive_resolvers/field_resolver.rb +4 -0
  29. data/lib/lighthouse/directive_resolvers/find_resolver.rb +31 -16
  30. data/lib/lighthouse/directive_resolvers/first_resolver.rb +6 -3
  31. data/lib/lighthouse/directive_resolvers/global_id_types.rb +1 -2
  32. data/lib/lighthouse/directive_resolvers/model_mutation_resolver.rb +2 -0
  33. data/lib/lighthouse/directive_resolvers/paginate_resolver.rb +29 -4
  34. data/lib/lighthouse/directive_resolvers/throttle_resolver.rb +17 -6
  35. data/lib/lighthouse/directives/arguments/base.rb +14 -0
  36. data/lib/lighthouse/directives/arguments/filters.rb +6 -0
  37. data/lib/lighthouse/directives/arguments/more_filters.rb +3 -0
  38. data/lib/lighthouse/directives/arguments/search.rb +34 -0
  39. data/lib/lighthouse/directives/arguments/soft_deletes.rb +11 -0
  40. data/lib/lighthouse/directives/model_directive.rb +1 -1
  41. data/lib/lighthouse/directives/registry.rb +1 -1
  42. data/lib/lighthouse/events/execution_trace.rb +6 -1
  43. data/lib/lighthouse/events/lifecycle.rb +2 -1
  44. data/lib/lighthouse/events.rb +9 -0
  45. data/lib/lighthouse/field_resolver_stack.rb +22 -21
  46. data/lib/lighthouse/graphql/version.rb +1 -1
  47. data/lib/lighthouse/incremental/body.rb +76 -0
  48. data/lib/lighthouse/incremental/defer_directive.rb +34 -0
  49. data/lib/lighthouse/incremental/delivery.rb +94 -0
  50. data/lib/lighthouse/incremental/document.rb +242 -0
  51. data/lib/lighthouse/incremental/gone.rb +6 -0
  52. data/lib/lighthouse/incremental/legacy.rb +75 -0
  53. data/lib/lighthouse/incremental/multipart.rb +76 -0
  54. data/lib/lighthouse/incremental/plan.rb +249 -0
  55. data/lib/lighthouse/incremental/rules.rb +116 -0
  56. data/lib/lighthouse/incremental/run.rb +302 -0
  57. data/lib/lighthouse/incremental/serializer.rb +37 -0
  58. data/lib/lighthouse/incremental/state.rb +204 -0
  59. data/lib/lighthouse/incremental/stream_directive.rb +41 -0
  60. data/lib/lighthouse/incremental/stream_trace.rb +93 -0
  61. data/lib/lighthouse/incremental/tree.rb +68 -0
  62. data/lib/lighthouse/namespaces.rb +2 -0
  63. data/lib/lighthouse/nested_mutations/belongs_to_operations.rb +2 -2
  64. data/lib/lighthouse/operations.rb +6 -2
  65. data/lib/lighthouse/pagination.rb +61 -15
  66. data/lib/lighthouse/persisted_queries.rb +53 -8
  67. data/lib/lighthouse/rb_lighthouse.rb +35 -0
  68. data/lib/lighthouse/resolve_info.rb +7 -1
  69. data/lib/lighthouse/schema_generator.rb +2 -0
  70. data/lib/lighthouse/search/auto.rb +26 -0
  71. data/lib/lighthouse/search/enhancer.rb +151 -0
  72. data/lib/lighthouse/search/field_check.rb +173 -0
  73. data/lib/lighthouse/search/pg_search.rb +146 -0
  74. data/lib/lighthouse/search/query.rb +54 -0
  75. data/lib/lighthouse/search/result.rb +181 -0
  76. data/lib/lighthouse/search/searchkick.rb +335 -0
  77. data/lib/lighthouse/search/searchkick_index.rb +54 -0
  78. data/lib/lighthouse/search/searchkick_options.rb +74 -0
  79. data/lib/lighthouse/search/together_check.rb +137 -0
  80. data/lib/lighthouse/search.rb +101 -0
  81. data/lib/lighthouse/support/argument_walk.rb +81 -0
  82. data/lib/lighthouse/support/count.rb +16 -0
  83. data/lib/lighthouse/support/failures.rb +28 -0
  84. data/lib/lighthouse/support/memo.rb +72 -0
  85. data/lib/lighthouse/support/model_resolver.rb +24 -0
  86. data/lib/lighthouse/support/relations.rb +31 -0
  87. data/lib/lighthouse/support/soft_deletes.rb +42 -8
  88. data/lib/lighthouse/testing.rb +81 -0
  89. data/sig/lighthouse/controller.rbs +34 -1
  90. data/sig/lighthouse/directives.rbs +46 -5
  91. data/sig/lighthouse/events.rbs +7 -0
  92. data/sig/lighthouse/graphql.rbs +117 -0
  93. data/sig/lighthouse/search.rbs +153 -0
  94. data/sig/lighthouse.rbs +77 -1
  95. metadata +39 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2ab527dcb3edd5db81b2cbd6c9bbec9c3e57a563ef226ec45ed4f44aab44f40
4
- data.tar.gz: e3965b3baa2fc998bce3ecbfafeaf7de724d5715957f35384e63cdbb484df5dd
3
+ metadata.gz: 16b866dbbae1192cb051baae53de5a7938f9bb16c1f176a5112d8b1893cef78c
4
+ data.tar.gz: b0a9ed4c1fdfe4e6d22b7ebb5d07ff192ea661dbaaf7751cc726854edbbdb4b7
5
5
  SHA512:
6
- metadata.gz: 436960e077273eef766bcd648ba709d16eaf263e12bb76c5447c730353822c8e3d334bf214bc252bcc01af3a23234b81987ef29d8e103c5f1f85d6c28abf1ea6
7
- data.tar.gz: 8008508abc330c3fffb6725655bd445af480812b17d953db62fbb6f0aefa61700d63b46fc88171cfd74ad11536ee5e93bcfd598370453f0fd18ce012b14baff2
6
+ metadata.gz: 485c2dcd6ade1ff9f1c62be69544114784c18ebedf2e25609791d9113eccdf97ef6b41824fb7b6bf6d0fffa86a95d14aac6f43eab91c21109bf3ec592ffb8192
7
+ data.tar.gz: 14a7e8b8718f655c53e9c7594099ba9060b9b34c60eb23a08a258c36856fa459c4da5aaa38ec99c74f32248cc365131a06176928ace9aa46cfbf65cc0e8458ec
data/CHANGELOG.md CHANGED
@@ -6,6 +6,171 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.9.1] - 2026-10-30
10
+
11
+ ### Added
12
+
13
+ - **`@search` over several models**: a field of a union or an interface (`everything(search: String!
14
+ @search): [SearchResult!]! @paginate`) searches the models of its types together, one ranked list with an
15
+ exact total, each record answered as its model's type. Searchkick searches their indices in one request,
16
+ each model's `search_where` and hidden records holding in its own index only (`_index`), each model's hits
17
+ loading through its own scopes; pg_search searches its multisearch documents, each one counted only when
18
+ its model's relation selects its record. The schema is refused when the field is not a root `@all` or
19
+ `@paginate`, has no non-null `@search` argument, has a type that is no model's or models no one engine
20
+ searches together, or asks for what one model's search applies (`scopes:`, `@builder`, `@whereAuth`,
21
+ `@orderBy(column:)`, `@trashed`). An adapter of its own opts in with `searchable_together?` and
22
+ `together_error`. See [filtering-and-ordering.md](docs/filtering-and-ordering.md#searching-several-models-together).
23
+
24
+ ## [0.9.0] - 2026-10-30
25
+
26
+ ### Added
27
+
28
+ - **`@search`**, PHP Lighthouse's directive, with its definition: on a `String` argument, a string
29
+ from the client (`""` too) runs the field's query through a full-text engine instead of the
30
+ database; `null` or nothing falls back to it. `within:` names the index (Searchkick) or the
31
+ `pg_search_scope`. Ruby has no Laravel Scout, so two gems back it behind one adapter seam
32
+ (`Lighthouse::Search`), neither a dependency of Lighthouse: **Searchkick** (Elasticsearch /
33
+ OpenSearch) answers with the records it found, in relevance order, for `@all`, `@paginate`
34
+ (all three types; the total comes with the page, one request, and `first: 0` can count, which Scout
35
+ cannot), `@first` (the best match), `@find` (the one match; more than one is an error, as in PHP
36
+ Lighthouse) and a resolver of your own. The total is always exact past the 10,000 matches the engines
37
+ stop counting at (`track_total_hits`, which an app's `body_options` may not set, so that no page
38
+ serves a record `@canQuery` did not check), a search reads within the index's result window
39
+ (`index.max_result_window`, read from the engine, the index `within:` names too; from the model's
40
+ options, whatever their keys, when it cannot be read): a page past it is an error the client reads,
41
+ and `@all` reads what the client asks for (`first`, an argument's `@limit`, else every match),
42
+ 10,000 records at most at once, even with `deep_paging`, with an error next to them when that
43
+ answers fewer than asked while more match. An index's mapping and settings are read at most once a
44
+ minute, one thread at a time (a failed read once in five seconds, reported to `Config.on_error`, its
45
+ cause named in the error it leads to; they need the `view_index_metadata` privilege). An `@builder`
46
+ may set only the Searchkick options that rank or shape the hits (`Searchkick::Options::BUILDER_OPTIONS`), never
47
+ `load:`, `index_name:`, `unscope:` or what pages and counts them; its `scope_results:` runs before
48
+ Lighthouse's. A search counts only what it can load: a Searchkick model with a default scope
49
+ (any, as declared, since what one selects may depend on the request) or a `search_results` scope
50
+ defines `search_where`, the engine's `where:` for the
51
+ same records (a tenant's, a published flag's), which every search ANDs in; and pages follow the
52
+ engine's positions, so a hit that does not load (a stale index) is neither shown twice nor skips
53
+ another, in `SIMPLE` and `CONNECTION` alike. **pg_search** (2.3 and 2.4) is a
54
+ scope on the relation, so `scopes:`, `@builder`, `@whereAuth`, the argument filters, `@orderBy`,
55
+ nested fields, batched nested `@paginate` and mass mutations all apply on top of it, the rank
56
+ first (before the model's default order too), then the orders that break its ties, then the
57
+ primary key, so equal matches keep one order on every field. A mass mutation (`@delete`, ...) counts a `@search` argument as a filter only when
58
+ the search runs, as PHP Lighthouse. The engine is detected per model, and for a model with both
59
+ gems a `within:` naming a pg_search scope picks pg_search; `Config.search` replaces the detection. `@eq`,
60
+ `@trashed` and `@builder` on an argument narrow a Searchkick search through the new
61
+ `Contracts::SearchBuilder` and `Lighthouse::Search::Query`, as Scout's `ScoutBuilderDirective`,
62
+ every condition holding (one column's conditions are ANDed, never overwritten); `@limit`, which
63
+ only cuts the result, is taken too.
64
+ `@trashed` filters on the soft-delete column the index holds, the one `Config.soft_deletes` filters
65
+ the database on (with paranoia's sentinel value; adapters may tell it with `column(model)` and
66
+ `kept_value(model)`; it is the one place to name it), and the records load through the database's
67
+ `@trashed` (`ONLY` / `WITH` past the default scope that hides them, paranoia's, discard's). The
68
+ column is Lighthouse's: a model whose default scope hides trashed records is filtered on it in the
69
+ engine when the client does not say, and its `search_where` leaves it out (naming it anywhere is an
70
+ error at the first search).
71
+ A model's `search_results` scope, when it has one, is what a search of it may return: Searchkick
72
+ loads the records it finds through it (`scope_results:`), and through each `@eq` on a column of the
73
+ model (a scalar, a list or a Range of them; not an engine operator), and through the model's default
74
+ scope when it loads `unscope: true`, so a record a stale index still holds, or holds as it was, is not
75
+ returned. An STI subclass searching its parent's index needs `inheritance: true` or `search_where`. Each field's
76
+ search is its own, nothing kept in the query's context. `@canQuery` on a searched field checks every record the search finds, as PHP
77
+ Lighthouse does (with Searchkick, 10,000 at most: a search that finds more a page could reach is an
78
+ error), and the hits it checked serve the field's page, handed to the field's resolver for that
79
+ resolution only (never through the query's context), so nothing the index gains in between is
80
+ answered unchecked; and `resolve_info.enhance_builder` answers a `Lighthouse::Search::Result` for a
81
+ Searchkick search, as PHP Lighthouse answers Scout's builder, so a field your own class resolves
82
+ can search through it; the relation it gets must select what the model's own does (`Post.all`,
83
+ or `Post`), any other is refused. Each resolver class declares whether it applies a search and
84
+ takes an engine's records (`applies_search?`, `takes_search_results?`; `Contracts::FieldResolver`
85
+ says no by default, so a directive of your own opts in). A filter of a searched field that raises
86
+ fails the field, reported to `Config.on_error`, rather than answer what it would have left out; so
87
+ does the engine, whenever a page asks it.
88
+ See [Full-text search](docs/filtering-and-ordering.md#full-text-search).
89
+ - **`@defer` (experimental)**, PHP Lighthouse's extension, on the specification draft's terms.
90
+ `use Lighthouse::GraphQL::Defer` in the schema class adds the directive as the draft has it
91
+ (graphql-spec PR #1110: on fragments, with `if` and `label`, answered as `pending` /
92
+ `incremental` / `completed` / `hasNext`), and `Lighthouse::GraphQL::Controller` streams the
93
+ response of an operation that defers as `multipart/mixed`, as PHP Lighthouse does once its
94
+ provider is registered: nothing else to set up, from the same action and routes (`GET` too), as a
95
+ body Rails streams in the request's thread (no `ActionController::Live`). It streams to any
96
+ client but one whose `Accept` header leaves `multipart/mixed` out (`application/json` alone),
97
+ which gets one ordinary response; GraphiQL's `application/json, multipart/mixed` streams. A
98
+ client that names Apollo's older format (`multipart/mixed;deferSpec=20220824`: Apollo Client 3,
99
+ Apollo Client 4's `Defer20220824Handler`) gets its payloads in that format (`path` and `label`,
100
+ no `pending` / `completed`). As PHP Lighthouse's, a response goes in
101
+ rounds, one payload each, and stops deferring past its limits, with their names and meaning:
102
+ `defer_max_nested_fields` and `defer_max_execution_ms` (0, the default, for none). PHP
103
+ Lighthouse's rules hold: no `@defer` on a root mutation field ("The @defer directive cannot be
104
+ used on a root mutation field.", inline or through a named fragment), `@skip` and `@include`
105
+ answer first, and a deferred field's errors come with it. The rules are checked for every query,
106
+ streamed or not, by a graphql-ruby analyzer, on the client's document, which is never rewritten:
107
+ listeners, `query_string` and tracing see it as sent. Unlike PHP Lighthouse's, `@defer` goes on
108
+ fragments, not fields (`... @defer { parent { name } }` for `parent @defer { name }`); the format
109
+ is the draft's, not Apollo's 2018 one; a round runs only the pending fragments, on the objects
110
+ already loaded (`GraphQL::Query::Partial`), not the whole query again, so a field resolves once, a
111
+ mutation runs once and the Dataloader batches across a round; a field also asked for outside the
112
+ fragment comes in the first payload, once, and the fragment still completes, as the draft has it
113
+ (PHP Lighthouse and Apollo do not defer it); the fields the same fragments select make one
114
+ grouped field set, as the draft's, so a fragment that fails fails only those it shares fields
115
+ with, and sends nothing (not even what it adds to a shared field); and a Non-Null field can be deferred. Needs
116
+ graphql-ruby 2.5.23. The first pass is the schema's `execute` (an app's own override too), as on
117
+ the JSON path. See [defer.md](docs/defer.md), which lists the differences.
118
+ - **`Lighthouse::GraphQL::Testing`**, PHP Lighthouse's `MakesGraphQLRequests`, for request specs and
119
+ integration tests: `graphql(query, variables)`, `post_graphql` (a batch too), `multipart_graphql`
120
+ (uploads), `introspect`, `introspect_type(name)`, `introspect_directive(name)`, and
121
+ `stream_graphql`, PHP Lighthouse's `streamGraphQL`, which answers the payloads of a streamed
122
+ response (`NotStreamed` for one that came whole). See [testing.md](docs/testing.md).
123
+ - **`@stream` (experimental)**, with `@defer` (PHP Lighthouse has none): `users @stream(initialCount: 2)
124
+ { name }` answers the first items at once and the rest in a later part (`items`, the draft's
125
+ format). A graphql-ruby trace module on the schema that uses the plugin cuts the list after its
126
+ resolver ran, once, on any of its fields; a field that is not streamed costs it next to nothing. The later items run
127
+ what the field's declarations select, together, so the Dataloader still batches. Items may carry
128
+ `@defer`. A `null` item where the list's items are non-null fails the stream. A negative
129
+ `initialCount` is a field error.
130
+
131
+ ### Changed
132
+
133
+ - **A filter that raises fails its field; it is never skipped.** An argument directive, a
134
+ `@builder` or `@whereAuth` that raised was reported to `Config.on_error` and dropped, and the
135
+ field answered without it, or without any filter: a `@builder` that enforces tenancy, a
136
+ `@whereAuth` whose user has no id, or a `@builder` class that does not exist let the client read
137
+ every row, and a mass `@delete` whose builder raised deleted every row. Now the error is
138
+ reported, then raised as it is, on every field (lists, pages, relationships, counts, mass
139
+ mutations, `enhance_builder`): the schema's `rescue_from` maps it as any resolver's error, in test
140
+ and production alike. A schema error found only as a query runs (a `@builder` whose class or
141
+ method cannot be found, a search a field's directives would narrow) is reported and answered as
142
+ a client error. Breaking for an app that relied on a failing filter being skipped.
143
+ - **`BaseDirectiveResolver#apply_arg_builders` is removed.** It applied the argument directives
144
+ without the field's search, so a directive of your own calling it answered unsearched rows: call
145
+ `apply_where_filters`.
146
+ - **`@search` is stricter than PHP Lighthouse where it drops a constraint silently.** With an engine
147
+ outside the database (Searchkick) PHP Lighthouse ignores the field's `scopes:`, `@builder`,
148
+ `@whereAuth` and `@orderBy(column:)` when it searches, so a search that skipped `@whereAuth`
149
+ returns records the user must not see. Here that field is a schema error at build, as are `@search`
150
+ on a model that is not searchable, a `within:` that is not a string, a `@search` nothing applies
151
+ (graphql-ruby's default reader, `@create`, ...), which PHP Lighthouse ignores, and, with
152
+ Searchkick, any field but `@all`, `@paginate` of the model's whole table and a resolver of your
153
+ own, an `@canQuery` with `scopes:`, and a value graphql-ruby fills in without the client (an
154
+ argument's default, the fields of a default object) whose directive the engine cannot apply (PHP
155
+ Lighthouse fails every search of such a field). A relational engine (pg_search) applies them all.
156
+ `enhance_builder` refuses, with Searchkick, a relation that selects other records than the
157
+ model's own (a narrowed one, `unscoped`, `with_deleted`, ...), whose conditions PHP Lighthouse
158
+ drops. A Searchkick model that declares a default scope (any, whatever it reads as a request
159
+ runs) or a `search_results` scope without `search_where`, whose totals PHP Lighthouse lets count
160
+ other tenants' matches, is a schema error too; a nested `@paginate` whose parent type is no model
161
+ is one, and a record that pages an association there a client error.
162
+
163
+ ### Fixed
164
+
165
+ - **`@find` keeps `@whereAuth` and the query's context.** Its filters ran without the context, so
166
+ `@whereAuth` never saw the user and an argument `@builder` got none, and a lookup by `id` alone was
167
+ batched past the field's own query directives: `post(id:) @find @whereAuth(relation: "author")`
168
+ answered another user's post. It now passes the context, and batches only a field with no query
169
+ directive of its own.
170
+ - **`@canQuery`, `@canFind` and `@canModel` tell their model when the schema is built.** A field
171
+ whose model cannot be told (a type that is no model, and no `model:`) built, and every query of it
172
+ raised an internal error; the schema now fails to build with that message.
173
+
9
174
  ## [0.8.2] - 2026-10-30
10
175
 
11
176
  ### Fixed
@@ -866,7 +1031,9 @@ had been running inside a private monorepo as a path gem before being extracted.
866
1031
  - Config-driven extension seams: `Lighthouse.configure`, `resolver_namespaces`,
867
1032
  `on_error`, and `DirectiveRegistry.register` for app-defined directives.
868
1033
 
869
- [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.2...HEAD
1034
+ [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.9.1...HEAD
1035
+ [0.9.1]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.9.0...v0.9.1
1036
+ [0.9.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.2...v0.9.0
870
1037
  [0.8.2]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.1...v0.8.2
871
1038
  [0.8.1]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.8.0...v0.8.1
872
1039
  [0.8.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.3...v0.8.0
@@ -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)).