Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(query): queries with a collection & subcollection but an empty doc fail silently #269

Open
puppybits opened this issue Feb 25, 2020 · 0 comments
Labels

Comments

@puppybits
Copy link
Contributor

What is the current behavior?
If a query string has a collection and subcollection but not a docId it's an invalid query. No error is getting thrown.

What is the expected behavior?
In the queryStrToObj function, if there is a collection and subcollection, there must always be a doc. I assume an error would be thrown just like in the getQueryConfig function below it.

throw new Error(
'Invalid Path Definition: Only Strings and Objects are accepted.',
);

Which version of redux-firestore are you using? What about other dependencies?
v0.12.0

Which environments/browsers are affected by this issue? Did this work in previous versions or setups?
all

Minimal demo to reproduce issue (using codesandbox or similar)

let docId = ''
getQueryConfigs(`/test/${docId}/col/subId`); // returns object with missing doc param {collection:'test', subcollection:[{collection:'col', doc:'subId'}]'
// or
useFirestoreConnect({collection:`/test/${docId}/col/subId`})

I would assume there to be a check in the queryStrToObj and a corresponding unit test to validate.

export function queryStrToObj(queryPathStr, parsedPath) {
const pathArr = parsedPath || trim(queryPathStr, ['/']).split('/');
const [collection, doc, ...subcollections] = pathArr;
const queryObj = {};
if (collection) queryObj.collection = collection;
if (doc) queryObj.doc = doc;
if (subcollections.length) {
queryObj.subcollections = [queryStrToObj('', subcollections)];
}
return queryObj;
}

A check could be something like:

if (collection && subcollection && doc === nil) {
   throw new Error(
    'Invalid Path Definition: Parent document path is empty.',
  )
}
@prescottprue prescottprue changed the title Queries with a collection & subcollection but an empty doc fail silently bug(query): queries with a collection & subcollection but an empty doc fail silently Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants