-
Notifications
You must be signed in to change notification settings - Fork 7
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
qs.parse returns invalid key with brackets when using nested array query #1751
Conversation
filter.every.every((value: any, index: number) => | ||
assertFilter(value, pointer.concat(`[${index}]`)), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.every
is problematic because it expects to return a boolean. So, not all assertions are being run thru
@@ -348,9 +348,10 @@ function assertEqFilter( | |||
if (typeof filter.eq !== 'object' || filter.eq == null) { | |||
throw new Error(`${pointer.join('/') || '/'}: eq must be an object`); | |||
} | |||
Object.entries(filter.eq).every(([key, value]) => | |||
assertJSONValue(value, pointer.concat(key)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointer.concat
doesn't even mutate the pointer. I would prefer to handle in another PR
060aaa6
to
2611f1a
Compare
b6e0fe1
to
ee8d70d
Compare
@@ -414,4 +414,70 @@ module(`Integration | prerendered-card-search`, function (hooks) { | |||
.dom('.card-container:nth-child(1)') | |||
.containsText('Cardy Stackington Jr. III'); | |||
}); | |||
|
|||
test<TestContextWithSSE>(`can parse objects in nested array`, async function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to come up with a better name here
I noticed in the qs docs, this comment:
Is this actually the problem, do these items reside 5+ levels deep? if they were higher up in the composition hierarchy would they be parsed correctly? If so, there is a |
Yes it is! I recall looking into this and thought 5 was sufficient depth. The depth that works is 6! I think this solves my issue, any ideas what should be the default depth? |
Let’s do a |
|
packages/runtime-common/query.ts
Outdated
} | ||
|
||
export const parseQuery = (queryString: string) => { | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's be a little more precise why we are ignoring. I usually do:
// @ts-expect-error no types available for XXX
this way when types do become available our lint will let us know that the following line doesn't need to be ignored anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Just fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been merged DefinitelyTyped/DefinitelyTyped#71087 and deployed on @6.9.17 of qs. No need for ts-expect-error
anymore
EDIT TLDR:
This PR fixes a limitation of the depth that qs.parse is parsing. There is a default of depthLimit = 5 hence, our nested queries would parse key names with brackets outside. This PR configures, depthLimit = 10 and sets strictDepth = true ( a new feature shipped in qs) which errors out if qs.parse recurses too deep.
=====Below Description here is historical=====
Problem
When making complicated queries where any array nests within every array,
qs.parse
incorrectly parses the string st a key has brackets wrapped around it.Fixing this problem unlocks the ability to nest
every
andany
queries which is useful for complex querying in applications that will be used by ecosystem team.Here is the test you can see a3ea344
The cardsQuery after returned from
qs.parse
will look like thisThe issue errors out because
pathSegments
doesn't know how to handle bracketsboxel/packages/runtime-common/index-query-engine.ts
Line 914 in a398617
SOLUTION
I decided to post-parse the
qs.parse
object even before going into the realm-index.query-engine. Placing my fix inrealm.ts
was intentional because I thought that the issue was withinqs.parse
, although, its possibly easier if using one-linerremoveOuterBracket
just occured nearpathSegments
insiderealm.ts
(open to opinions here) since the recursion is already made.I have also attempted to use qs.parse configuration but was unsuccesful bcos I don't think it works out-of-the-box
allowDots
configuration but it totally breaks the query structure query-engine is expecting since it converts keys to nested objects.qs.parse
only allows decoding of one-level deep and I didn't think it was worthwhile to expose myself to a recursiveqs.parse