Skip to content

Commit b6ee1d1

Browse files
authored
Revert "Make authorizer work for nested relations"
1 parent 5d716c3 commit b6ee1d1

File tree

13 files changed

+63
-431
lines changed

13 files changed

+63
-431
lines changed

examples/auth/e2e/fixtures.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DataSource } from 'typeorm'
22

33
import { executeTruncate } from '../../helpers'
4-
import { SubSubTaskEntity } from '../src/sub-sub-task/sub-sub-task.entity'
54
import { SubTaskEntity } from '../src/sub-task/sub-task.entity'
65
import { TagEntity } from '../src/tag/tag.entity'
76
import { TodoItemEntity } from '../src/todo-item/todo-item.entity'
@@ -16,7 +15,6 @@ export const refresh = async (dataSource: DataSource): Promise<void> => {
1615
const userRepo = dataSource.getRepository(UserEntity)
1716
const todoRepo = dataSource.getRepository(TodoItemEntity)
1817
const subTaskRepo = dataSource.getRepository(SubTaskEntity)
19-
const subSubTaskRepo = dataSource.getRepository(SubSubTaskEntity)
2018
const tagsRepo = dataSource.getRepository(TagEntity)
2119

2220
const users = await userRepo.save([
@@ -52,24 +50,15 @@ export const refresh = async (dataSource: DataSource): Promise<void> => {
5250
Promise.resolve([] as TodoItemEntity[])
5351
)
5452

55-
const subTasks: SubTaskEntity[] = await subTaskRepo.save(
56-
todoItems.flatMap(
57-
(todo) => [
53+
await subTaskRepo.save(
54+
todoItems.reduce(
55+
(subTasks, todo) => [
56+
...subTasks,
5857
{ completed: true, title: `${todo.title} - Sub Task 1`, todoItem: todo, ownerId: todo.ownerId },
5958
{ completed: false, title: `${todo.title} - Sub Task 2`, todoItem: todo, ownerId: todo.ownerId },
6059
{ completed: false, title: `${todo.title} - Sub Task 3`, todoItem: todo, ownerId: todo.ownerId }
6160
],
62-
[]
63-
)
64-
)
65-
66-
await subSubTaskRepo.save(
67-
subTasks.flatMap(
68-
(parent) => [
69-
{ subTask: parent, title: `${parent.title} - Sub Sub Task Public`, public: true },
70-
{ subTask: parent, title: `${parent.title} - Sub Sub Task Private`, public: false }
71-
],
72-
[]
61+
[] as Partial<SubTaskEntity>[]
7362
)
7463
)
7564
}

examples/auth/e2e/todo-item.resolver.spec.ts

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -426,61 +426,6 @@ describe('TodoItemResolver (auth - e2e)', () => {
426426
])
427427
}))
428428

429-
it(`should allow fetching subSubTasks, but only the ones that are allowed by the nested authorizers`, () =>
430-
request(app.getHttpServer())
431-
.post('/graphql')
432-
.auth(jwtToken, { type: 'bearer' })
433-
.send({
434-
operationName: null,
435-
variables: {},
436-
query: `{
437-
todoItems {
438-
edges {
439-
node {
440-
subTasks {
441-
edges {
442-
node {
443-
subSubTasks {
444-
title
445-
}
446-
}
447-
}
448-
}
449-
}
450-
}
451-
}
452-
}`
453-
})
454-
.expect(200)
455-
.then(({ body }) => {
456-
const {
457-
edges: [{ node: task }]
458-
}: {
459-
edges: Array<{
460-
node: {
461-
subTasks: {
462-
edges: Array<{
463-
node: {
464-
subSubTasks: Array<{
465-
title: string
466-
}>
467-
}
468-
}>
469-
}
470-
}
471-
}>
472-
} = body.data.todoItems
473-
const [subTask] = task.subTasks.edges.map((e) => e.node)
474-
475-
expect(subTask).toEqual({
476-
subSubTasks: [
477-
{
478-
title: 'Create Nest App - Sub Task 1 - Sub Sub Task Public'
479-
}
480-
]
481-
})
482-
}))
483-
484429
it(`should allow querying on tags`, () =>
485430
request(app.getHttpServer())
486431
.post('/graphql')
@@ -675,7 +620,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
675620
.send({
676621
operationName: null,
677622
variables: {},
678-
query: `{
623+
query: `{
679624
todoItemAggregate {
680625
${todoItemAggregateFields}
681626
}
@@ -702,7 +647,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
702647
.send({
703648
operationName: null,
704649
variables: {},
705-
query: `{
650+
query: `{
706651
todoItemAggregate {
707652
${todoItemAggregateFields}
708653
}
@@ -729,7 +674,7 @@ describe('TodoItemResolver (auth - e2e)', () => {
729674
.send({
730675
operationName: null,
731676
variables: {},
732-
query: `{
677+
query: `{
733678
todoItemAggregate(filter: { completed: { is: false } }) {
734679
${todoItemAggregateFields}
735680
}

0 commit comments

Comments
 (0)