Skip to content

Commit 99298ff

Browse files
authoredFeb 21, 2025
Merge pull request #2177 from cardstack/investigate-link-id
Allow to search null field on search resources / improve parse query on null handling
2 parents 1f454f8 + 79fa53e commit 99298ff

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed
 

‎packages/host/app/components/prerendered-card-search.gts

+8-5
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ export default class PrerenderedCardSearch extends Component<Signature> {
133133
realmURL: string,
134134
): Promise<PrerenderedCard[]> {
135135
let json = (await this.cardService.fetchJSON(
136-
`${realmURL}_search-prerendered?${stringify({
137-
...query,
138-
prerenderedHtmlFormat: format,
139-
cardUrls,
140-
})}`,
136+
`${realmURL}_search-prerendered?${stringify(
137+
{
138+
...query,
139+
prerenderedHtmlFormat: format,
140+
cardUrls,
141+
},
142+
{ strictNullHandling: true },
143+
)}`,
141144
)) as unknown as PrerenderedCardCollectionDocument;
142145
if (!isPrerenderedCardCollectionDocument(json)) {
143146
throw new Error(

‎packages/host/app/resources/search.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ export class Search extends Resource<Args> {
168168
await Promise.all(
169169
this.realmsToSearch.map(async (realm) => {
170170
let json = await this.cardService.fetchJSON(
171-
`${realm}_search?${stringify(query)}`,
171+
`${realm}_search?${stringify(query, {
172+
strictNullHandling: true,
173+
})}`,
172174
);
173175
if (!isCardCollectionDocument(json)) {
174176
throw new Error(

‎packages/host/tests/integration/realm-indexing-and-querying-test.gts

+16
Original file line numberDiff line numberDiff line change
@@ -4391,6 +4391,22 @@ posts/ignore-me.json
43914391
);
43924392
});
43934393

4394+
test(`can use 'eq' to find empty linksTo field`, async function (assert) {
4395+
let { data: matching } = await queryEngine.search({
4396+
filter: {
4397+
on: {
4398+
module: `${testModuleRealm}friend`,
4399+
name: 'Friend',
4400+
},
4401+
every: [{ eq: { firstName: 'Mango' } }, { eq: { friend: null } }],
4402+
},
4403+
});
4404+
assert.deepEqual(
4405+
matching.map((m) => m.id),
4406+
[`${testRealmURL}friend2`],
4407+
);
4408+
});
4409+
43944410
test(`can search for cards by using a computed field`, async function (assert) {
43954411
let { data: matching } = await queryEngine.search({
43964412
filter: {

‎packages/runtime-common/query.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function isAnyFilter(filter: Filter): filter is AnyFilter {
110110
}
111111

112112
export function buildQueryString(query: Query): string {
113-
return `?${qs.stringify(query)}`;
113+
return `?${qs.stringify(query, { strictNullHandling: true })}`;
114114
}
115115

116116
export function assertQuery(
@@ -431,5 +431,9 @@ export function assertKey(key: string, pointer: string[]) {
431431
}
432432

433433
export const parseQuery = (queryString: string) => {
434-
return qs.parse(queryString, { depth: 10, strictDepth: true });
434+
return qs.parse(queryString, {
435+
depth: 10,
436+
strictDepth: true,
437+
strictNullHandling: true,
438+
});
435439
};

0 commit comments

Comments
 (0)