Skip to content

Commit

Permalink
Merge pull request #10 from TriPSs/improvements
Browse files Browse the repository at this point in the history
feat(query-graphql): Added `disableFilter` and `disableSort`
  • Loading branch information
TriPSs authored May 31, 2022
2 parents 9ac1a05 + 41190a1 commit 7079531
Show file tree
Hide file tree
Showing 171 changed files with 3,942 additions and 4,731 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"singleQuote": true,
"printWidth": 120,
"printWidth": 130,
"trailingComma": "none"
}
45 changes: 45 additions & 0 deletions documentation/docs/graphql/relations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,51 @@ To disable the `read` `queries` you can set the `disableRead` option to `true`.
</TabItem>
</Tabs>

#### Disable `filter` or `sorting` in relations

To disable the `filter` or `sorting` of relations you can set the `disableFilter` or/and `disableSort` option to `true`.

<Tabs
defaultValue="relation"
groupId="relation-type"
values={[
{ label: 'Relation', value: 'relation', },
{ label: 'CursorConnection', value: 'cursor-connection', },
{ label: 'OffsetConnection', value: 'offset-connection', },
{ label: 'UnPagedRelation', value: 'unpaged-relation', },
]
}>
<TabItem value="relation">

This is not available in `relation` as it will only fetch one record.

</TabItem>
<TabItem value="cursor-connection">

```ts
// disable reading the connection
@CursorConnection('subTasks', () => SubTaskDTO, { disableFilter: true, disableSort: true })
```

</TabItem>
<TabItem value="offset-connection">

```ts
// disable reading the relation
@OffsetConnection('subTaskConnection', () => SubTaskDTO, { disableFilter: true, disableSort: true })
```

</TabItem>
<TabItem value="unpaged-relation">

```ts
// disable reading the relation
@UnPagedRelation('subTaskConnection', () => SubTaskDTO, { disableFilter: true, disableSort: true })
```

</TabItem>
</Tabs>

### Disable Updates

To disable the `update` `mutations` you can set the `disableUpdate` option to `true`.
Expand Down
8 changes: 2 additions & 6 deletions examples/auth/e2e/sub-task.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,7 @@ describe('SubTaskResolver (auth - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -913,9 +911,7 @@ describe('SubTaskResolver (auth - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down
6 changes: 2 additions & 4 deletions examples/auth/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,7 @@ describe('TagResolver (auth - e2e)', () => {
})
.expect(200)
.then(({ body }) => {
const { edges, pageInfo, totalCount }: CursorConnectionType<TodoItemDTO> =
body.data.addTodoItemsToTag.todoItems;
const { edges, pageInfo, totalCount }: CursorConnectionType<TodoItemDTO> = body.data.addTodoItemsToTag.todoItems;
expect(body.data.addTodoItemsToTag.id).toBe('1');
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
Expand Down Expand Up @@ -1178,8 +1177,7 @@ describe('TagResolver (auth - e2e)', () => {
})
.expect(200)
.then(({ body }) => {
const { edges, pageInfo, totalCount }: CursorConnectionType<TodoItemDTO> =
body.data.removeTodoItemsFromTag.todoItems;
const { edges, pageInfo, totalCount }: CursorConnectionType<TodoItemDTO> = body.data.removeTodoItemsFromTag.todoItems;
expect(body.data.removeTodoItemsFromTag.id).toBe('1');
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjE=',
Expand Down
11 changes: 3 additions & 8 deletions examples/auth/e2e/todo-item.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -1439,9 +1437,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down Expand Up @@ -1615,8 +1611,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
})
.expect(200)
.then(({ body }) => {
const { edges, pageInfo, totalCount }: CursorConnectionType<SubTaskDTO> =
body.data.addSubTasksToTodoItem.subTasks;
const { edges, pageInfo, totalCount }: CursorConnectionType<SubTaskDTO> = body.data.addSubTasksToTodoItem.subTasks;
expect(body.data.addSubTasksToTodoItem.id).toBe('1');
expect(pageInfo).toEqual({
endCursor: 'YXJyYXljb25uZWN0aW9uOjU=',
Expand Down
5 changes: 1 addition & 4 deletions examples/auth/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { UserDTO } from '../user/user.dto';

@Injectable()
export class AuthService {
constructor(
@InjectQueryService(UserEntity) private usersService: QueryService<UserEntity>,
private jwtService: JwtService
) {}
constructor(@InjectQueryService(UserEntity) private usersService: QueryService<UserEntity>, private jwtService: JwtService) {}

async validateUser(username: string, pass: string): Promise<AuthenticatedUser | null> {
const [user] = await this.usersService.query({ filter: { username: { eq: username } }, paging: { limit: 1 } });
Expand Down
7 changes: 1 addition & 6 deletions examples/auth/src/sub-task/dto/subtask-input.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Field, InputType, ID } from '@nestjs/graphql';
import { IsOptional, IsString, IsBoolean, IsNotEmpty } from 'class-validator';
import {
BeforeCreateMany,
BeforeCreateOne,
CreateManyInputType,
CreateOneInputType
} from '@ptc-org/nestjs-query-graphql';
import { BeforeCreateMany, BeforeCreateOne, CreateManyInputType, CreateOneInputType } from '@ptc-org/nestjs-query-graphql';
import { UserContext } from '../../auth/auth.interfaces';

@InputType('SubTaskInput')
Expand Down
7 changes: 1 addition & 6 deletions examples/auth/src/sub-task/dto/subtask-update.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Field, InputType } from '@nestjs/graphql';
import { IsOptional, IsBoolean, IsString, IsNotEmpty } from 'class-validator';
import {
BeforeUpdateMany,
BeforeUpdateOne,
UpdateManyInputType,
UpdateOneInputType
} from '@ptc-org/nestjs-query-graphql';
import { BeforeUpdateMany, BeforeUpdateOne, UpdateManyInputType, UpdateOneInputType } from '@ptc-org/nestjs-query-graphql';
import { SubTaskDTO } from './sub-task.dto';
import { UserContext } from '../../auth/auth.interfaces';

Expand Down
10 changes: 1 addition & 9 deletions examples/auth/src/tag/tag.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ObjectType,
ManyToMany
} from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ObjectType, ManyToMany } from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity({ name: 'tag' })
Expand Down
7 changes: 1 addition & 6 deletions examples/auth/src/todo-item/dto/todo-item-input.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { IsString, MaxLength, IsBoolean } from 'class-validator';
import { Field, InputType } from '@nestjs/graphql';
import {
BeforeCreateMany,
BeforeCreateOne,
CreateManyInputType,
CreateOneInputType
} from '@ptc-org/nestjs-query-graphql';
import { BeforeCreateMany, BeforeCreateOne, CreateManyInputType, CreateOneInputType } from '@ptc-org/nestjs-query-graphql';
import { UserContext } from '../../auth/auth.interfaces';

@InputType('TodoItemInput')
Expand Down
7 changes: 1 addition & 6 deletions examples/auth/src/todo-item/dto/todo-item-update.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Field, InputType } from '@nestjs/graphql';
import { IsBoolean, IsNumber, IsOptional, IsString, MaxLength } from 'class-validator';
import {
BeforeUpdateMany,
BeforeUpdateOne,
UpdateManyInputType,
UpdateOneInputType
} from '@ptc-org/nestjs-query-graphql';
import { BeforeUpdateMany, BeforeUpdateOne, UpdateManyInputType, UpdateOneInputType } from '@ptc-org/nestjs-query-graphql';
import { TodoItemDTO } from './todo-item.dto';
import { UserContext } from '../../auth/auth.interfaces';

Expand Down
10 changes: 1 addition & 9 deletions examples/auth/src/user/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
OneToMany,
JoinTable
} from 'typeorm';
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn, OneToMany, JoinTable } from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity({ name: 'user' })
Expand Down
8 changes: 2 additions & 6 deletions examples/basic/e2e/sub-task.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ describe('SubTaskResolver (basic - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -615,9 +613,7 @@ describe('SubTaskResolver (basic - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down
8 changes: 2 additions & 6 deletions examples/basic/e2e/todo-item.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@ describe('TodoItemResolver (basic - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -661,9 +659,7 @@ describe('TodoItemResolver (basic - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down
10 changes: 1 addition & 9 deletions examples/basic/src/tag/tag.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ObjectType,
ManyToMany
} from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ObjectType, ManyToMany } from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity({ name: 'tag' })
Expand Down
8 changes: 2 additions & 6 deletions examples/complexity/e2e/sub-task.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ describe('SubTaskResolver (complexity - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneSubTaskInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -651,9 +649,7 @@ describe('SubTaskResolver (complexity - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneSubTaskInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down
8 changes: 2 additions & 6 deletions examples/complexity/e2e/todo-item.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ describe('TodoItemResolver (complexity - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneTodoItemInput.id" of required type "ID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -640,9 +638,7 @@ describe('TodoItemResolver (complexity - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneTodoItemInput.id" of required type "ID!" was not provided.');
}));
});

Expand Down
10 changes: 1 addition & 9 deletions examples/complexity/src/tag/tag.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ObjectType,
ManyToMany
} from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ObjectType, ManyToMany } from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity({ name: 'tag' })
Expand Down
8 changes: 2 additions & 6 deletions examples/custom-id/e2e/sub-task.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,7 @@ describe('SubTaskResolver (custom-id - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneSubTaskInput.id" of required type "CustomID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneSubTaskInput.id" of required type "CustomID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -657,9 +655,7 @@ describe('SubTaskResolver (custom-id - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneSubTaskInput.id" of required type "CustomID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneSubTaskInput.id" of required type "CustomID!" was not provided.');
}));
});

Expand Down
8 changes: 2 additions & 6 deletions examples/custom-id/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ describe('TagResolver (custom-id - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "UpdateOneTagInput.id" of required type "CustomID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "UpdateOneTagInput.id" of required type "CustomID!" was not provided.');
}));

it('should validate an update', () =>
Expand Down Expand Up @@ -529,9 +527,7 @@ describe('TagResolver (custom-id - e2e)', () => {
.expect(400)
.then(({ body }) => {
expect(body.errors).toHaveLength(1);
expect(body.errors[0].message).toBe(
'Field "DeleteOneTagInput.id" of required type "CustomID!" was not provided.'
);
expect(body.errors[0].message).toBe('Field "DeleteOneTagInput.id" of required type "CustomID!" was not provided.');
}));
});

Expand Down
Loading

0 comments on commit 7079531

Please sign in to comment.