From b93699c0258cadfdd6639b64479f1738b5c301b4 Mon Sep 17 00:00:00 2001 From: Patryk Fryda Date: Fri, 27 Jan 2023 15:05:31 +0100 Subject: [PATCH] fix(firestore): support not equals null query --- packages/firestore/e2e/Query/where.e2e.js | 4 ++++ packages/firestore/lib/FirestoreQuery.js | 6 +++++- packages/firestore/lib/FirestoreQueryModifiers.js | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/firestore/e2e/Query/where.e2e.js b/packages/firestore/e2e/Query/where.e2e.js index 8656eca845..0a62c85b04 100644 --- a/packages/firestore/e2e/Query/where.e2e.js +++ b/packages/firestore/e2e/Query/where.e2e.js @@ -88,6 +88,10 @@ describe('firestore().collection().where()', function () { firebase.firestore().collection(COLLECTION).where('foo.bar', '==', null); }); + it('allows null to be used with not equal operator', function () { + firebase.firestore().collection(COLLECTION).where('foo.bar', '!=', null); + }); + it('throws if multiple inequalities on different paths is provided', function () { try { firebase.firestore().collection(COLLECTION).where('foo.bar', '>', 123).where('bar', '>', 123); diff --git a/packages/firestore/lib/FirestoreQuery.js b/packages/firestore/lib/FirestoreQuery.js index 4eadb3a08d..b7c9ce2f45 100644 --- a/packages/firestore/lib/FirestoreQuery.js +++ b/packages/firestore/lib/FirestoreQuery.js @@ -437,7 +437,11 @@ export default class FirestoreQuery { ); } - if (isNull(value) && !this._modifiers.isEqualOperator(opStr)) { + if ( + isNull(value) && + !this._modifiers.isEqualOperator(opStr) && + !this._modifiers.isNotEqualOperator(opStr) + ) { throw new Error( "firebase.firestore().collection().where(_, _, *) 'value' is invalid. You can only perform equals comparisons on null", ); diff --git a/packages/firestore/lib/FirestoreQueryModifiers.js b/packages/firestore/lib/FirestoreQueryModifiers.js index 4014ea4bbe..0488a7737d 100644 --- a/packages/firestore/lib/FirestoreQueryModifiers.js +++ b/packages/firestore/lib/FirestoreQueryModifiers.js @@ -198,6 +198,10 @@ export default class FirestoreQueryModifiers { return OPERATORS[operator] === 'EQUAL'; } + isNotEqualOperator(operator) { + return OPERATORS[operator] === 'NOT_EQUAL'; + } + isInOperator(operator) { return ( OPERATORS[operator] === 'IN' ||