Skip to content

Commit

Permalink
fix: dataloader limit bug (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOlias authored Apr 5, 2024
1 parent c65c5dd commit c55fdd1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-bottles-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug where GraphQL queries that include a many -> `p.one()` path with a limit greater than 50 would fail with the error: "Cannot return null for non-nullable field".
1 change: 1 addition & 0 deletions packages/core/src/server/graphql/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function buildLoaderCache({ store }: { store: IndexingStore }) {
tableName,
where: { id: { in: ids } },
checkpoint,
limit: ids.length,
});

return ids.map((id) => rows.items.find((row) => row.id === id));
Expand Down
48 changes: 48 additions & 0 deletions packages/core/src/server/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,54 @@ test("uses dataloader to resolve a plural -> p.one() path", async (context) => {
await cleanup();
});

test("dataloader on a plural -> p.one() path handles a limit greater than 50", async (context) => {
const {
service,
gql,
createTestEntity,
createEntityWithBigIntId,
indexingStore,
cleanup,
} = await setup({ context });
service.setIsHealthy(true);

const findUniqueSpy = vi.spyOn(indexingStore, "findUnique");
const findManySpy = vi.spyOn(indexingStore, "findMany");

await Promise.all(
range(0, 100).map(async (n) => {
await createTestEntity({ id: n });
await createEntityWithBigIntId({
id: BigInt(n),
testEntityId: String(n),
});
}),
);

const response = await gql(`
entityWithBigIntIds(limit: 75) {
items {
id
testEntity {
id
}
}
}
`);

expect(response.status).toBe(200);
const body = (await response.json()) as any;
expect(body.errors).toBe(undefined);
const { entityWithBigIntIds } = body.data;
expect(entityWithBigIntIds.items).toHaveLength(75);

expect(findUniqueSpy).toHaveBeenCalledTimes(0);
expect(findManySpy).toHaveBeenCalledTimes(2);

await service.kill();
await cleanup();
});

test.skip.fails(
"uses dataloader to resolve a plural -> p.many() path",
async (context) => {
Expand Down

0 comments on commit c55fdd1

Please sign in to comment.