Skip to content

Commit 17cc0f6

Browse files
committed
fix(auth): use NonNullable resolver fn types
1 parent a00ed2f commit 17cc0f6

File tree

1 file changed

+47
-50
lines changed
  • packages/auth/src/graphql/resolvers

1 file changed

+47
-50
lines changed

packages/auth/src/graphql/resolvers/grant.ts

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { Pagination } from '../../shared/baseModel'
1111
import { getPageInfo } from '../../shared/pagination'
1212
import { Access } from '../../access/model'
1313

14-
export const getGrants: QueryResolvers<ApolloContext>['grants'] = async (
15-
_,
16-
args,
17-
ctx
18-
): Promise<ResolversTypes['GrantsConnection']> => {
14+
export const getGrants: NonNullable<
15+
QueryResolvers<ApolloContext>['grants']
16+
> = async (_, args, ctx): Promise<ResolversTypes['GrantsConnection']> => {
1917
const grantService = await ctx.container.use('grantService')
2018
const { filter, sortOrder, ...pagination } = args
2119
const grants = await grantService.getPage(pagination, filter, sortOrder)
@@ -34,11 +32,9 @@ export const getGrants: QueryResolvers<ApolloContext>['grants'] = async (
3432
}
3533
}
3634

37-
export const getGrantById: QueryResolvers<ApolloContext>['grant'] = async (
38-
_,
39-
args,
40-
ctx
41-
): Promise<ResolversTypes['Grant']> => {
35+
export const getGrantById: NonNullable<
36+
QueryResolvers<ApolloContext>['grant']
37+
> = async (_, args, ctx): Promise<ResolversTypes['Grant']> => {
4238
const grantService = await ctx.container.use('grantService')
4339
const grant = await grantService.getByIdWithAccess(args.id)
4440

@@ -49,53 +45,54 @@ export const getGrantById: QueryResolvers<ApolloContext>['grant'] = async (
4945
return grantToGraphql(grant)
5046
}
5147

52-
export const revokeGrant: MutationResolvers<ApolloContext>['revokeGrant'] =
53-
async (
54-
_,
55-
args,
56-
ctx
57-
): Promise<ResolversTypes['RevokeGrantMutationResponse']> => {
58-
try {
59-
const { grantId } = args.input
60-
if (!grantId) {
61-
return {
62-
code: '401',
63-
success: false,
64-
message: 'Grant Id is not provided'
65-
}
66-
}
67-
68-
const grantService = await ctx.container.use('grantService')
69-
const revoked = await grantService.revokeGrant(grantId)
70-
if (!revoked) {
71-
return {
72-
code: '404',
73-
success: false,
74-
message: 'Revoke grant was not successful'
75-
}
76-
}
77-
48+
export const revokeGrant: NonNullable<
49+
MutationResolvers<ApolloContext>['revokeGrant']
50+
> = async (
51+
_,
52+
args,
53+
ctx
54+
): Promise<ResolversTypes['RevokeGrantMutationResponse']> => {
55+
try {
56+
const { grantId } = args.input
57+
if (!grantId) {
7858
return {
79-
code: '200',
80-
success: true,
81-
message: 'Grant revoked'
59+
code: '401',
60+
success: false,
61+
message: 'Grant Id is not provided'
8262
}
83-
} catch (err) {
84-
ctx.logger.error(
85-
{
86-
options: args.input.grantId,
87-
err
88-
},
89-
'error revoking grant'
90-
)
63+
}
9164

65+
const grantService = await ctx.container.use('grantService')
66+
const revoked = await grantService.revokeGrant(grantId)
67+
if (!revoked) {
9268
return {
93-
code: '500',
94-
message: 'Error trying to revoke grant',
95-
success: false
69+
code: '404',
70+
success: false,
71+
message: 'Revoke grant was not successful'
9672
}
9773
}
74+
75+
return {
76+
code: '200',
77+
success: true,
78+
message: 'Grant revoked'
79+
}
80+
} catch (err) {
81+
ctx.logger.error(
82+
{
83+
options: args.input.grantId,
84+
err
85+
},
86+
'error revoking grant'
87+
)
88+
89+
return {
90+
code: '500',
91+
message: 'Error trying to revoke grant',
92+
success: false
93+
}
9894
}
95+
}
9996

10097
export const grantToGraphql = (grant: Grant): SchemaGrant => ({
10198
id: grant.id,

0 commit comments

Comments
 (0)