Skip to content

Commit

Permalink
feat(graphql,#958,#1160): Enable authorizers on subscriptions
Browse files Browse the repository at this point in the history
* feat: authorizer applied to pub sub

* feat(query-graphql): authorizer for websocket in resolvers

* updating spaces to improve code review

* feat: authorizer for create many

* feat: authorizer applied to update subscriptions

* feat: authorizer applied to delete subscriptions

* fix: adding missing decorator to make authorizer applied to update and delete subscriptions working

* feat: Enable authorizers on subscriptions

* feat: Enable authorizers on subscriptions

* example: Add authorized subscription example

* fix: lock apollo versions until nestjs/graphql updates

Co-authored-by: Armando Soriano <asoriano.dev@gmail.com>
  • Loading branch information
doug-martin and asorian0 committed Jul 27, 2021
1 parent f40cac6 commit d2f857f
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 117 deletions.
14 changes: 13 additions & 1 deletion examples/auth/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ import { typeormOrmConfig } from '../../helpers';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';

interface HeadersContainer {
headers?: Record<string, string>;
}
interface ContextArgs {
req?: HeadersContainer;
connection?: { context: HeadersContainer };
}

@Module({
imports: [
TypeOrmModule.forRoot(typeormOrmConfig('auth')),
GraphQLModule.forRoot({
autoSchemaFile: 'schema.gql',
context: ({ req }: { req: { headers: Record<string, string> } }) => ({ req }),
installSubscriptionHandlers: true,
subscriptions: {
onConnect: (connectionParams: unknown) => ({ headers: connectionParams }),
},
context: ({ req, connection }: ContextArgs) => ({ req: { ...req, ...connection?.context } }),
}),
AuthModule,
UserModule,
Expand Down
1 change: 1 addition & 0 deletions examples/auth/src/sub-task/sub-task.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { JwtAuthGuard } from '../auth/jwt-auth.guard';
CreateDTOClass: CreateSubTaskDTO,
UpdateDTOClass: SubTaskUpdateDTO,
enableAggregate: true,
enableSubscriptions: true,
guards: [JwtAuthGuard],
},
],
Expand Down
1 change: 1 addition & 0 deletions examples/auth/src/tag/tag.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { JwtAuthGuard } from '../auth/jwt-auth.guard';
CreateDTOClass: TagInputDTO,
UpdateDTOClass: TagInputDTO,
enableAggregate: true,
enableSubscriptions: true,
guards: [JwtAuthGuard],
},
],
Expand Down
1 change: 1 addition & 0 deletions examples/auth/src/todo-item/todo-item.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { JwtAuthGuard } from '../auth/jwt-auth.guard';
CreateDTOClass: TodoItemInputDTO,
UpdateDTOClass: TodoItemUpdateDTO,
enableAggregate: true,
enableSubscriptions: true,
guards: [JwtAuthGuard],
},
],
Expand Down
2 changes: 2 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@nestjs/sequelize": "8.0.0",
"@nestjs/typeorm": "8.0.1",
"@typegoose/typegoose": "8.0.0-beta.7",
"apollo-server-core": "2.25.2",
"apollo-server-types": "0.9.0",
"apollo-server-express": "2.25.2",
"apollo-server-plugin-base": "0.13.0",
"class-validator": "0.13.1",
Expand Down
213 changes: 136 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d2f857f

Please sign in to comment.