Skip to content

Commit b666949

Browse files
committed
fix: remove query filtering
This is intented to fix the issue uncovered in #482. It also adds `$populateParams` to the `paramsForServer` by default, which means it now supports feathers-graph-populate out of the box, now.
1 parent fa63313 commit b666949

9 files changed

+14
-18
lines changed

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const defaultOptions = {
293293
replaceItems: false,
294294
skipRequestIfExists: false,
295295

296-
paramsForServer: [],
296+
paramsForServer: ['$populateParams'],
297297
whitelist: [],
298298

299299
handleEvents: {
@@ -316,7 +316,7 @@ const defaultOptions = {
316316
- `preferUpdate {Boolean}` - **Default:** `false` - If `true`, calling `model.save()` will do an `update` instead of a `patch`.
317317
- `replaceItems {Boolean}` - **Default:** `false` - If `true`, updates & patches replace the record in the store. Default is false, which merges in changes.
318318
- `skipRequestIfExists {Boolean}` - **Default:** `false` - For get action, if `true` the record already exists in store, skip the remote request.
319-
- `paramsForServer {Array}` - **Default:** `[]` - Custom query operators that are ignored in the find getter, but will pass through to the server.
319+
- `paramsForServer {Array}` - **Default:** `['$populateParams']` - Custom query operators that are ignored in the find getter, but will pass through to the server. It is preconfigured to work with the `$populateParams` custom operator from [feathers-graph-populate](https://feathers-graph-populate.netlify.app/).
320320
- `whitelist {Array}` - **Default:** `[]` - Custom query operators that will be allowed in the find getter.
321321
- `enableEvents {Boolean}` - **Default:** `true` - If `false` socket event listeners will be turned off. See the services
322322
- `handleEvents {Object}`: For this to work `enableEvents` must be `true`

docs/service-plugin.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const servicePlugin = makeServicePlugin({
3737
replaceItems: false,
3838
skipRequestIfExists: false,
3939

40-
paramsForServer: [],
40+
paramsForServer: ['$populateParams'],
4141
whitelist: [],
4242

4343
enableEvents: true,
@@ -75,7 +75,7 @@ The following options can also be configured in [Global Configuration](getting-s
7575
- `preferUpdate {Boolean}` - **Default:** `globalConfig: false` - If `true`, calling `model.save()` will do an `update` instead of a `patch`.
7676
- `replaceItems {Boolean}` - **Default:** `globalConfig: false` - If `true`, updates & patches replace the record in the store. Default is false, which merges in changes.
7777
- `skipRequestIfExists {Boolean}` - **Default:** `globalConfig: false` - For get action, if `true` the record already exists in store, skip the remote request.
78-
- `paramsForServer {Array}` - Custom query operators that are ignored in the find getter, but will pass through to the server.
78+
- `paramsForServer {Array}` - **Default:** `['$populateParams']` - Custom query operators that are ignored in the find getter, but will pass through to the server. It is preconfigured to work with the `$populateParams` custom operator from [feathers-graph-populate](https://feathers-graph-populate.netlify.app/).
7979
- `whitelist {Array}` - Custom query operators that will be allowed in the find getter.
8080
- `enableEvents {Boolean}` - **Default:** `globalConfig: true` - If `false` socket event listeners will be turned off
8181
- `handleEvents {Object}`: For this to work `enableEvents` must be `true`
@@ -141,7 +141,7 @@ Each service comes loaded with the following default state:
141141
mostRecent: any
142142
},
143143

144-
paramsForServer: [],
144+
paramsForServer: ['$populateParams'],
145145
whitelist: [],
146146

147147
isFindPending: false,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const defaults: FeathersVuexOptions = {
4444
debug: false, // Set to true to enable logging messages.
4545
keepCopiesInStore: false, // Set to true to store cloned copies in the store instead of on the Model.
4646
nameStyle: 'short', // Determines the source of the module name. 'short', 'path', or 'explicit'
47-
paramsForServer: [], // Custom query operators that are ignored in the find getter, but will pass through to the server.
47+
paramsForServer: ['$populateParams'], // Custom query operators that are ignored in the find getter, but will pass through to the server. $populateParams is for https://feathers-graph-populate.netlify.app/
4848
preferUpdate: false, // When true, calling model.save() will do an update instead of a patch.
4949
replaceItems: false, // Instad of merging in changes in the store, replace the entire record.
5050
serverAlias: 'api',

src/service-module/service-module.getters.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ export default function makeServiceGetters() {
3232

3333
const { paramsForServer, whitelist, keyedById } = state
3434
const q = _omit(params.query || {}, paramsForServer)
35-
const customOperators = Object.keys(q).filter(
36-
k => k[0] === '$' && !defaultOps.includes(k)
37-
)
38-
const cleanQuery = _omit(q, customOperators)
3935

40-
const { query, filters } = filterQuery(cleanQuery, {
36+
const { query, filters } = filterQuery(q, {
4137
operators: additionalOperators.concat(whitelist)
4238
})
4339
let values = _.values(keyedById)

src/service-module/service-module.state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface ServiceStateExclusiveDefaults {
3434
defaultSkip: number
3535
default?: PaginationState
3636
}
37+
paramsForServer: string[]
3738
modelName?: string
3839
}
3940

@@ -109,6 +110,7 @@ export default function makeDefaultState(options: MakeServicePluginOptions) {
109110
defaultLimit: null,
110111
defaultSkip: null
111112
},
113+
paramsForServer: ['$populateParams'],
112114

113115
isFindPending: false,
114116
isGetPending: false,

test/service-module/make-service-plugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('makeServicePlugin', function() {
8181
defaultLimit: null,
8282
defaultSkip: null
8383
},
84-
paramsForServer: [],
84+
paramsForServer: ['$populateParams'],
8585
preferUpdate: false,
8686
replaceItems: false,
8787
serverAlias: 'default',

test/service-module/module.getters.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Service Module - Getters', function () {
177177

178178
it('find with custom operator', function () {
179179
const { state } = this
180-
const params = { query: { test: false, $populateQuery: 'test' } }
180+
const params = { query: { test: false, $populateParams: 'test' } }
181181
const results = find(state)(params)
182182

183183
assert(results.data.length === 1, 'the length was correct')
@@ -203,13 +203,11 @@ describe('Service Module - Getters', function () {
203203
it('find with non-whitelisted custom operator fails', function () {
204204
const { state } = this
205205
const params = { query: { $client: 'test' } }
206-
let results
207206
try {
208-
results = find(state)(params)
207+
find(state)(params)
209208
} catch (error) {
210209
assert(error)
211210
}
212-
assert(!results[0])
213211
})
214212

215213
it('find with whitelisted custom operators', function () {

test/service-module/service-module.reinitialization.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Service Module - Reinitialization', function() {
8282
defaultLimit: null,
8383
defaultSkip: null
8484
},
85-
paramsForServer: [],
85+
paramsForServer: ['$populateParams'],
8686
preferUpdate: false,
8787
replaceItems: false,
8888
serverAlias,

test/service-module/service-module.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ describe('Service Module', function() {
662662
defaultLimit: null,
663663
defaultSkip: null
664664
},
665-
paramsForServer: [],
665+
paramsForServer: ['$populateParams'],
666666
whitelist: []
667667
}
668668

0 commit comments

Comments
 (0)