Skip to content

Commit

Permalink
Update the aggregate resolver return type
Browse files Browse the repository at this point in the history
  • Loading branch information
f8k8 authored and AhmedElywa committed Mar 12, 2024
1 parent 87d2bd8 commit 39ea091
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions packages/generator/src/sdl/GenerateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class GenerateTypes {
`import * as Client from '@prisma/client'`,
`import { Context } from './context'`,
`import { GraphQLResolveInfo } from 'graphql';`,
`import { GetAggregateResult } from '@prisma/client/runtime/library';`,
`type Resolver<T extends {}, A extends {}, R extends any> = (parent: T,args: A, context: Context, info: GraphQLResolveInfo) => Promise<R>;`,
`type NoExpand<T> = T extends unknown ? T : never;`,
`type AtLeast<O extends object, K extends string> = NoExpand<
Expand Down Expand Up @@ -48,13 +49,17 @@ export class GenerateTypes {
case 'scalar':
return `${this.scalar[options.type as string]}${options.isList ? '[]' : ''}`;
default: {
const type = options.type.toString().startsWith('Aggregate')
? `Prisma.Get${options.type.toString().replace('Aggregate', '')}AggregateType<${options.type}Args>`
: options.type.toString() === 'AffectedRowsOutput'
? 'Prisma.BatchPayload'
: !this.isModel(options.type.toString()) && !input
? `Prisma.${options.type}`
: options.type;
if (options.type.toString().startsWith('Aggregate')) {
return `GetAggregateResult<Client.Prisma.$${options.type.toString().replace('Aggregate', '')}Payload, ${
options.type
}Args>`;
}
const type =
options.type.toString() === 'AffectedRowsOutput'
? 'Prisma.BatchPayload'
: !this.isModel(options.type.toString()) && !input
? `Prisma.${options.type}`
: options.type;
return `${!input ? 'Client.' : ''}${type}${options.isList ? '[]' : ''}`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Context } from './context'
import { GraphQLResolveInfo } from 'graphql'
import { GetAggregateResult } from '@prisma/client/runtime/library'
type Resolver<T extends {}, A extends {}, R extends any> = (
parent: T,
args: A,
Expand Down Expand Up @@ -82,7 +84,7 @@ export type Query = { [key: string]: Resolver<any, any, any> } & {
aggregateUser?: Resolver<
{},
AggregateUserArgs,
Client.Prisma.GetUserAggregateType<AggregateUserArgs>
GetAggregateResult<Client.Prisma.$UserPayload, AggregateUserArgs>
>
groupByUser?: Resolver<
{},
Expand All @@ -106,7 +108,7 @@ export type Query = { [key: string]: Resolver<any, any, any> } & {
aggregatePost?: Resolver<
{},
AggregatePostArgs,
Client.Prisma.GetPostAggregateType<AggregatePostArgs>
GetAggregateResult<Client.Prisma.$PostPayload, AggregatePostArgs>
>
groupByPost?: Resolver<
{},
Expand Down

0 comments on commit 39ea091

Please sign in to comment.