-
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.
fix(graphql,hooks,#957): Fix HookInterceptor not working with custom …
…resolvers
- Loading branch information
1 parent
d99d2b4
commit c947b3a
Showing
6 changed files
with
104 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1168,6 +1168,58 @@ describe('TodoItemResolver (hooks - e2e)', () => { | |
})); | ||
}); | ||
|
||
describe('markAllAsCompleted', () => { | ||
it('should call the beforeUpdateMany hook when marking all items as completed', async () => { | ||
const queryService = app.get<QueryService<TodoItemEntity>>(getQueryServiceToken(TodoItemEntity)); | ||
const todoItems = await queryService.createMany([ | ||
{ title: 'To Be Marked As Completed - 1', completed: false }, | ||
{ title: 'To Be Marked As Completed - 2', completed: false }, | ||
]); | ||
expect(todoItems).toHaveLength(2); | ||
const ids = todoItems.map((ti) => ti.id); | ||
return request(app.getHttpServer()) | ||
.post('/graphql') | ||
.set({ | ||
[AUTH_HEADER_NAME]: config.auth.header, | ||
[USER_HEADER_NAME]: 'e2e', | ||
}) | ||
.send({ | ||
operationName: null, | ||
variables: {}, | ||
query: `mutation { | ||
markTodoItemsAsCompleted( | ||
input: { | ||
filter: {id: { in: [${ids.join(',')}]} }, | ||
update: { } | ||
} | ||
) { | ||
updatedCount | ||
} | ||
}`, | ||
}) | ||
.expect(200, { | ||
data: { | ||
markTodoItemsAsCompleted: { | ||
updatedCount: 2, | ||
}, | ||
}, | ||
}) | ||
.then(async () => { | ||
const updatedTodoItems = await queryService.query({ filter: { id: { in: ids } } }); | ||
expect( | ||
updatedTodoItems.map((ti) => ({ | ||
title: ti.title, | ||
completed: ti.completed, | ||
updatedBy: ti.updatedBy, | ||
})), | ||
).toEqual([ | ||
{ title: 'To Be Marked As Completed - 1', completed: true, updatedBy: '[email protected]' }, | ||
{ title: 'To Be Marked As Completed - 2', completed: true, updatedBy: '[email protected]' }, | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { MutationArgsType, UpdateManyInputType } from '@nestjs-query/query-graphql'; | ||
import { ArgsType, InputType } from '@nestjs/graphql'; | ||
import { ArgsType, InputType, OmitType } from '@nestjs/graphql'; | ||
import { TodoItemDTO } from './dto/todo-item.dto'; | ||
import { TodoItemUpdateDTO } from './dto/todo-item-update.dto'; | ||
|
||
@InputType() | ||
class UpdateManyTodoItemsInput extends UpdateManyInputType(TodoItemDTO, TodoItemUpdateDTO) {} | ||
class MarkTodoItemAsCompleted extends OmitType(TodoItemUpdateDTO, ['completed']) {} | ||
|
||
@InputType() | ||
class MarkTodoItemsAsCompletedInput extends UpdateManyInputType(TodoItemDTO, MarkTodoItemAsCompleted) {} | ||
|
||
@ArgsType() | ||
export class UpdateManyTodoItemsArgs extends MutationArgsType(UpdateManyTodoItemsInput) {} | ||
export class MarkTodoItemsAsCompletedArgs extends MutationArgsType(MarkTodoItemsAsCompletedInput) {} |
40 changes: 15 additions & 25 deletions
40
packages/query-graphql/src/interceptors/hook.interceptor.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