-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from doug-martin/issue19
Issue19
- Loading branch information
Showing
17 changed files
with
402 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
examples/nest-graphql-typeorm/src/todo-item/dto/todo-item-input.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { IsString, MaxLength, IsBoolean } from 'class-validator'; | ||
import { Field, InputType } from 'type-graphql'; | ||
|
||
@InputType('TodoItemInput') | ||
export class TodoItemInputDTO { | ||
@IsString() | ||
@MaxLength(20) | ||
@Field() | ||
title!: string; | ||
|
||
@IsBoolean() | ||
@Field() | ||
completed!: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 40 additions & 1 deletion
41
packages/query-graphql/__tests__/types/delete-many-args.type.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,55 @@ | ||
import 'reflect-metadata'; | ||
import * as typeGraphql from 'type-graphql'; | ||
import { plainToClass } from 'class-transformer'; | ||
import { validateSync } from 'class-validator'; | ||
import { DeleteManyArgsType } from '../../src'; | ||
|
||
describe('DeleteManyArgsType', (): void => { | ||
const argsTypeSpy = jest.spyOn(typeGraphql, 'ArgsType'); | ||
const fieldSpy = jest.spyOn(typeGraphql, 'Field'); | ||
|
||
class FakeFilter {} | ||
it('should create an args type with an array field', () => { | ||
class FakeFilter {} | ||
DeleteManyArgsType(FakeFilter); | ||
expect(argsTypeSpy).toBeCalledWith(); | ||
expect(argsTypeSpy).toBeCalledTimes(1); | ||
expect(fieldSpy.mock.calls[0]![0]!()).toEqual(FakeFilter); | ||
}); | ||
|
||
describe('validation', () => { | ||
it('should validate the filter is defined', () => { | ||
const Type = DeleteManyArgsType(FakeFilter); | ||
const input = {}; | ||
const it = plainToClass(Type, input); | ||
const errors = validateSync(it); | ||
expect(errors).toEqual([ | ||
{ | ||
children: [], | ||
constraints: { | ||
isNotEmptyObject: 'input must be a non-empty object', | ||
}, | ||
property: 'input', | ||
target: input, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should validate the filter is not empty', () => { | ||
const Type = DeleteManyArgsType(FakeFilter); | ||
const input = { input: {} }; | ||
const it = plainToClass(Type, input); | ||
const errors = validateSync(it); | ||
expect(errors).toEqual([ | ||
{ | ||
children: [], | ||
constraints: { | ||
isNotEmptyObject: 'input must be a non-empty object', | ||
}, | ||
property: 'input', | ||
target: input, | ||
value: input.input, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.