Skip to content

Commit

Permalink
Allow arguments for _count fields
Browse files Browse the repository at this point in the history
  • Loading branch information
f8k8 committed Mar 8, 2024
1 parent 8f6ecbb commit 2f43742
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/generator/src/Generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ export class Generators {
.filter((field) => !this.options?.excludeInputFields?.includes(field.name))
.forEach((field) => {
fileContent.push(
`${field.name}: ${field.outputType.isList ? `[${field.outputType.type}!]` : field.outputType.type}${
`${field.name}${
type.name.endsWith('CountOutputType') && field.args.length ? `(${this.getSDLArgs(field.args)})` : ''
}: ${field.outputType.isList ? `[${field.outputType.type}!]` : field.outputType.type}${
!field.isNullable ? '!' : ''
}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ export default gql\`
}
type UserCountOutputType {
posts: Int!
posts(where: PostWhereInput): Int!
}
type UserCountAggregateOutputType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ type AggregatePost {
}
type UserCountOutputType {
posts: Int!
posts(where: PostWhereInput): Int!
}
type UserCountAggregateOutputType {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ export class PrismaSelect<
if (this.isAggregate) {
selectObject[fieldName] = true;
} else {
selectObject.select[fieldName] = true;
if (fields.name === '_count' && Object.keys(fieldsByTypeName[key].args).length) {
selectObject.select[fieldName] = fieldsByTypeName[key].args;
} else {
selectObject.select[fieldName] = true;
}
}
} else {
if (this.isAggregate) {
Expand Down

0 comments on commit 2f43742

Please sign in to comment.