Skip to content

Commit 3b35ad3

Browse files
committed
fix(graphql): filter on collections not working
Without this patch filtering doesn't work on collections. The following query returns all collections instead of the one that's filtered for: { collections(where: { name: { eq: "test"}}) { data { name id hypercerts { hypercert_id } } } } The same holds true for ids.
1 parent b7c9587 commit 3b35ad3

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

src/graphql/schemas/resolvers/baseTypes.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { GetOrdersArgs } from "../args/orderArgs.js";
1414
import { GetSalesArgs } from "../args/salesArgs.js";
1515
import { GetSignatureRequestArgs } from "../args/signatureRequestArgs.js";
1616
import { GetUserArgs } from "../args/userArgs.js";
17+
import { GetCollectionsArgs } from "../args/collectionArgs.js";
1718

1819
export function DataResponse<TItem extends object>(
1920
TItemClass: ClassType<TItem>,
@@ -405,6 +406,35 @@ export function createBaseResolver<T extends ClassType>(
405406
);
406407
}
407408
}
409+
410+
getCollections(args: GetCollectionsArgs, single: boolean = false) {
411+
console.debug(
412+
`[${entityFieldName}Resolver::getCollections] Fetching collections`,
413+
);
414+
415+
try {
416+
const queries = this.supabaseDataService.getCollections(args);
417+
if (single) {
418+
return queries.data.executeTakeFirst();
419+
}
420+
421+
return this.supabaseDataService.db
422+
.transaction()
423+
.execute(async (transaction) => {
424+
const dataRes = await transaction.executeQuery(queries.data);
425+
const countRes = await transaction.executeQuery(queries.count);
426+
return {
427+
data: dataRes.rows,
428+
count: countRes.rows[0].count,
429+
};
430+
});
431+
} catch (e) {
432+
const error = e as Error;
433+
throw new Error(
434+
`[${entityFieldName}Resolver::getCollections] Error fetching collections: ${error.message}`,
435+
);
436+
}
437+
}
408438
}
409439

410440
return BaseResolver;

src/graphql/schemas/resolvers/collectionResolver.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ class CollectionResolver extends CollectionBaseResolver {
2525
@Query(() => GetCollectionsResponse)
2626
async collections(@Args() args: GetCollectionsArgs) {
2727
try {
28-
const res = await this.supabaseDataService.getCollections(args);
29-
30-
return {
31-
data: res.data,
32-
count: res.count,
33-
};
28+
return this.getCollections(args);
3429
} catch (e) {
3530
console.error("[CollectionResolver::collections] Error:", e);
3631
throw new Error(`Error fetching collections: ${(e as Error).message}`);

src/services/SupabaseDataService.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -431,24 +431,9 @@ export class SupabaseDataService extends BaseSupabaseService<KyselyDataDatabase>
431431
.execute();
432432
}
433433

434-
async getCollections(args: GetCollectionsArgs) {
435-
let query = this.db
436-
.selectFrom("collections")
437-
.select([
438-
"collections.id",
439-
"collections.name",
440-
"collections.description",
441-
"collections.chain_ids",
442-
"collections.hidden",
443-
"collections.created_at",
444-
]);
445-
446-
if (args.sort?.by) {
447-
query = this.applySorting(query, args.sort.by);
448-
}
449-
434+
getCollections(args: GetCollectionsArgs) {
450435
return {
451-
data: await query.execute(),
436+
data: this.handleGetData("collections", args),
452437
count: this.handleGetCount("collections", args),
453438
};
454439
}

0 commit comments

Comments
 (0)