-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detect array membership with '_contains'
- Loading branch information
Sam Jackson
committed
Feb 4, 2019
1 parent
d2a0b1b
commit e82efbc
Showing
6 changed files
with
76 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
/** | ||
* Parses GraphQL AST to get complex parameters to GraphQL queries. | ||
* @param objectFields Set of key-value pairs in GraphQL AST form. | ||
*/ | ||
export declare const parseObjectValue: (objectFields: any) => any; | ||
/** | ||
* Applies filters to a Firestore query. Basically chains a series of | ||
* calls to `firestore.collection#where`. | ||
* @param collectionQuery The query to be made against some collection. | ||
* @param where Set of filters formatted as `KEY_COMPARATOR: VALUE` pairs | ||
*/ | ||
export declare const setQueryFilters: (collectionQuery: any, where: any[]) => import("firebase").firestore.Query; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Parses GraphQL AST to get complex parameters to GraphQL queries. | ||
* @param objectFields Set of key-value pairs in GraphQL AST form. | ||
*/ | ||
exports.parseObjectValue = (objectFields) => { | ||
return objectFields.map((field) => { | ||
const { name, value } = field; | ||
if (value.kind === 'IntValue') | ||
value.value = parseInt(value.value); | ||
return { | ||
key: name.value, | ||
value: value.value | ||
}; | ||
}); | ||
}; | ||
/** | ||
* Applies filters to a Firestore query. Basically chains a series of | ||
* calls to `firestore.collection#where`. | ||
* @param collectionQuery The query to be made against some collection. | ||
* @param where Set of filters formatted as `KEY_COMPARATOR: VALUE` pairs | ||
*/ | ||
exports.setQueryFilters = (collectionQuery, where) => { | ||
where.forEach((filter) => { | ||
const key = filter['key']; | ||
const value = filter['value']; | ||
const splitKey = key.split('_'); | ||
const whereOp = splitKey[splitKey.length - 1]; | ||
const actualKey = key.slice(0, -1 * (whereOp.length + 1)); | ||
switch (whereOp) { | ||
case 'eq': | ||
collectionQuery = collectionQuery.where(actualKey, '==', value); | ||
break; | ||
case 'gt': | ||
collectionQuery = collectionQuery.where(actualKey, '>', value); | ||
break; | ||
case 'gte': | ||
collectionQuery = collectionQuery.where(actualKey, '>=', value); | ||
break; | ||
case 'lt': | ||
collectionQuery = collectionQuery.where(actualKey, '<', value); | ||
break; | ||
case 'lte': | ||
collectionQuery = collectionQuery.where(actualKey, '<=', value); | ||
break; | ||
default: | ||
collectionQuery = collectionQuery.where(key, '==', value); | ||
break; | ||
} | ||
}); | ||
return collectionQuery; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters