Skip to content

Commit

Permalink
fix(graphql): Fix paging to properly check next/previous page
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed May 2, 2020
1 parent eae6287 commit 13c7bd9
Show file tree
Hide file tree
Showing 22 changed files with 349 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .run/jest.config.js.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<node-options value="" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<jest-options value="--runInBand" />
<jest-options value="--runInBand --coverage" />
<envs />
<scope-kind value="ALL" />
<method v="2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('Federated - SubTaskResolver (e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
2 changes: 1 addition & 1 deletion examples/federation/tag-graphql/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('Federated - TagResolver (e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('Federated - TodoItemResolver (e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('SubTaskResolver (sequelize - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-sequelize/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('TagResolver (sequelize - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('TodoItemResolver (sequelize - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('SoftDelete - TodoItemResolver (e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('SubTaskResolver (typeorm - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-typeorm/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('TagResolver (typeorm - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('TodoItemResolver (typeorm - e2e)', () => {
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
hasNextPage: true,
hasPreviousPage: false,
hasPreviousPage: true,
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
});
expect(edges).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'reflect-metadata';
import * as nestGraphql from '@nestjs/graphql';
import { instance, mock, when, objectContaining } from 'ts-mockito';
import { CanActivate, ExecutionContext } from '@nestjs/common';
import { QueryService, Query } from '@nestjs-query/core';
import { QueryService } from '@nestjs-query/core';
import { ReturnTypeFuncValue, QueryOptions, ArgsOptions } from '@nestjs/graphql';
import * as decorators from '../../src/decorators';
import { ConnectionType, QueryArgsType, ReadResolver } from '../../src';
Expand Down Expand Up @@ -122,10 +122,11 @@ describe('ReadResolver', () => {

it('should call the service query with the provided input', async () => {
const mockService = mock<QueryService<TestResolverDTO>>();
const input: Query<TestResolverDTO> = {
const input: QueryArgsType<TestResolverDTO> = {
filter: {
stringField: { eq: 'foo' },
},
paging: { first: 1 },
};
const output: TestResolverDTO[] = [
{
Expand All @@ -134,7 +135,7 @@ describe('ReadResolver', () => {
},
];
const resolver = new TestResolver(instance(mockService));
when(mockService.query(objectContaining(input))).thenResolve(output);
when(mockService.query(objectContaining({ ...input, paging: { limit: 2, offset: 0 } }))).thenResolve(output);
const result = await resolver.queryMany(input);
return expect(result).toEqual({
edges: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'reflect-metadata';
import { Query, QueryService } from '@nestjs-query/core';
import { QueryService } from '@nestjs-query/core';
import * as nestGraphql from '@nestjs/graphql';
import { mock, instance, when, objectContaining, deepEqual } from 'ts-mockito';
import { CanActivate, ExecutionContext } from '@nestjs/common';
import { ReturnTypeFuncValue, ResolveFieldOptions } from '@nestjs/graphql';
import { ReadRelationsResolver } from '../../../src/resolvers/relations';
import * as decorators from '../../../src/decorators';
import { QueryArgsType } from '../../../src/types';
import * as types from '../../../src/types';

const { ID, ObjectType } = nestGraphql;
Expand Down Expand Up @@ -249,8 +250,9 @@ describe('ReadRelationsResolver', () => {
id: 'id-1',
stringField: 'foo',
};
const query: Query<RelationDTO> = {
const query: QueryArgsType<RelationDTO> = {
filter: { id: { eq: 'id-2' } },
paging: { first: 1 },
};
const output: RelationDTO[] = [
{
Expand All @@ -260,9 +262,14 @@ describe('ReadRelationsResolver', () => {
];
const R = ReadRelationsResolver(ReadRelationDTO, { many: { relation: { DTO: RelationDTO } } });
const resolver = new R(instance(mockService));
when(mockService.queryRelations(RelationDTO, 'relations', deepEqual([dto]), objectContaining(query))).thenResolve(
new Map([[dto, output]]),
);
when(
mockService.queryRelations(
RelationDTO,
'relations',
deepEqual([dto]),
objectContaining({ ...query, paging: { limit: 2, offset: 0 } }),
),
).thenResolve(new Map([[dto, output]]));
// @ts-ignore
const result = await resolver.queryRelations(dto, query, {});
return expect(result).toEqual({
Expand Down Expand Up @@ -290,8 +297,9 @@ describe('ReadRelationsResolver', () => {
id: 'id-1',
stringField: 'foo',
};
const query: Query<RelationDTO> = {
const query: QueryArgsType<RelationDTO> = {
filter: { id: { eq: 'id-2' } },
paging: { first: 1 },
};
const output: RelationDTO[] = [
{
Expand All @@ -303,9 +311,14 @@ describe('ReadRelationsResolver', () => {
many: { relation: { DTO: RelationDTO, relationName: 'other' } },
});
const resolver = new R(instance(mockService));
when(mockService.queryRelations(RelationDTO, 'other', deepEqual([dto]), objectContaining(query))).thenResolve(
new Map([[dto, output]]),
);
when(
mockService.queryRelations(
RelationDTO,
'other',
deepEqual([dto]),
objectContaining({ ...query, paging: { limit: 2, offset: 0 } }),
),
).thenResolve(new Map([[dto, output]]));
// @ts-ignore
const result = await resolver.queryRelations(dto, query, {});
return expect(result).toEqual({
Expand Down
Loading

0 comments on commit 13c7bd9

Please sign in to comment.