Skip to content

Commit

Permalink
fix(query-graphql): adapt createFromPromise typings and add tests for…
Browse files Browse the repository at this point in the history
… passing additional query params
  • Loading branch information
psteinroe authored and doug-martin committed Sep 7, 2021
1 parent 07f9e7b commit d81e531
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ describe('CursorConnectionType', (): void => {
});
});

it('should pass additional query params to queryMany', async () => {
const queryMany = jest.fn();
const dtos = [createTestDTO(1), createTestDTO(2)];
queryMany.mockResolvedValueOnce([...dtos]);
await TestConnection.createFromPromise(queryMany, { search: 'searchString', paging: createPage({ first: 2 }) });
expect(queryMany).toHaveBeenCalledTimes(1);
expect(queryMany).toHaveBeenCalledWith({ search: 'searchString', paging: { limit: 3, offset: 0 } });
});

it('should create a connections response with an empty paging', async () => {
const queryMany = jest.fn();
const response = await TestConnection.createFromPromise(queryMany, { paging: {} });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ describe('OffsetConnectionType', (): void => {
});
});

it('should pass additional query params to queryMany', async () => {
const queryMany = jest.fn();
const dtos = [createTestDTO(1), createTestDTO(2)];
queryMany.mockResolvedValueOnce([...dtos]);
await TestConnection.createFromPromise(queryMany, {
search: 'searchString',
paging: createPage({ limit: 2 }),
});
expect(queryMany).toHaveBeenCalledTimes(1);
expect(queryMany).toHaveBeenCalledWith({ search: 'searchString', paging: { limit: 3, offset: 0 } });
});

it('should create a connections response with an empty paging', async () => {
const queryMany = jest.fn();
const response = await TestConnection.createFromPromise(queryMany, { paging: {} });
Expand Down
2 changes: 1 addition & 1 deletion packages/query-graphql/src/types/connection/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface StaticConnectionType<DTO, S extends PagingStrategies>
resolveType: ReturnTypeFuncValue;
createFromPromise(
queryMany: QueryMany<DTO>,
query: Query<DTO>,
query: Query<DTO> & Record<string, any>,
count?: Count<DTO>,
): Promise<InferConnectionTypeFromStrategy<DTO, S>>;
}

0 comments on commit d81e531

Please sign in to comment.