From 9f910eaa25921a8ffe172ff3097f13b50249f1c8 Mon Sep 17 00:00:00 2001 From: Dekel Barzilay Date: Fri, 28 Feb 2020 16:49:51 +0200 Subject: [PATCH] Added new `eagerOptions` params operator --- README.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- src/index.js | 7 ++++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bf12522..096ed29 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,10 @@ Note that all this eager related options are optional. - **`mergeAllowEager`** - Will merge the given expression to the existing expression from the `allowEager` service option. See [`allowGraph`](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#allowgraph) documentation. + +- **`eagerOptions`** - Options object to use with `$eager` and `$joinEager` query operators. + See [`GraphOptions`](https://vincit.github.io/objection.js/api/types/#type-graphoptions) + documentation. ### Composite primary keys diff --git a/package-lock.json b/package-lock.json index c72c5e8..b9126e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "feathers-objection", - "version": "5.0.0", + "version": "5.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1aaf9bd..93520f8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "feathers-objection", "description": "A service plugin for ObjectionJS an ORM based on KnexJS", - "version": "5.0.0", + "version": "5.0.1", "homepage": "https://github.com/feathersjs-ecosystem/feathers-objection", "keywords": [ "feathers", diff --git a/src/index.js b/src/index.js index e7d2bd8..93a5537 100644 --- a/src/index.js +++ b/src/index.js @@ -259,6 +259,7 @@ class Service extends AdapterService { createQuery (params = {}) { const { filters, query } = this.filterQuery(params); const q = this._createQuery(params).skipUndefined(); + const eagerOptions = params.eagerOptions || {}; if (this.allowedEager) { q.allowGraph(this.allowedEager); } @@ -271,13 +272,13 @@ class Service extends AdapterService { // $eager for Objection eager queries if (query && query.$eager) { - q.withGraphFetched(query.$eager); + q.withGraphFetched(query.$eager, eagerOptions); delete query.$eager; } if (query && query.$joinEager) { - q.withGraphJoined(query.$joinEager); + q.withGraphJoined(query.$joinEager, eagerOptions); delete query.$joinEager; } @@ -291,7 +292,7 @@ class Service extends AdapterService { } if (query && query.$mergeEager) { - q[query.$joinEager ? 'withGraphJoined' : 'withGraphFetched'](query.$mergeEager); + q[query.$joinEager ? 'withGraphJoined' : 'withGraphFetched'](query.$mergeEager, eagerOptions); delete query.$mergeEager; }