Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit c795453

Browse files
author
Dekel Barzilay
committed
Added new eagerOptions service option
1 parent 9f910ea commit c795453

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ Note that all this eager related options are optional.
143143
the service. Defaults to `'[]'`, meaning no eager queries allowed. See
144144
[`allowGraph`](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#allowgraph)
145145
documentation.
146+
147+
- **`eagerOptions`** - Options object to use with `$eager` and `$joinEager` query operators.
148+
See [`GraphOptions`](https://vincit.github.io/objection.js/api/types/#type-graphoptions)
149+
documentation.
150+
146151
- **`eagerFilters`** - option to impose compulsory eager filter. It takes an
147152
object or array of objects with the following properties:
148153
- `expression` - the relation expression that the filter will be applied.
@@ -214,7 +219,8 @@ Note that all this eager related options are optional.
214219
See [`allowGraph`](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#allowgraph)
215220
documentation.
216221

217-
- **`eagerOptions`** - Options object to use with `$eager` and `$joinEager` query operators.
222+
- **`eagerOptions`** - Options object to use with `$eager` and `$joinEager` query operators.
223+
merges on top of the `eagerOptions` service option.
218224
See [`GraphOptions`](https://vincit.github.io/objection.js/api/types/#type-graphoptions)
219225
documentation.
220226

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Service extends AdapterService {
9292
this.idSeparator = options.idSeparator || ',';
9393
this.jsonSchema = options.model.jsonSchema;
9494
this.allowedEager = options.allowedEager;
95+
this.eagerOptions = options.eagerOptions;
9596
this.eagerFilters = options.eagerFilters;
9697
this.allowedInsert = options.allowedInsert && RelationExpression.create(options.allowedInsert);
9798
this.insertGraphOptions = options.insertGraphOptions;
@@ -259,7 +260,7 @@ class Service extends AdapterService {
259260
createQuery (params = {}) {
260261
const { filters, query } = this.filterQuery(params);
261262
const q = this._createQuery(params).skipUndefined();
262-
const eagerOptions = params.eagerOptions || {};
263+
const eagerOptions = { ...this.eagerOptions, ...params.eagerOptions };
263264

264265
if (this.allowedEager) { q.allowGraph(this.allowedEager); }
265266

0 commit comments

Comments
 (0)