groupBy doesn't accept it's own GroupByArgs type as an argument
See original GitHub issueBug description
After generating the client, the groupBy method of the client’s object throw an error when using a parameter typed GroupByArgs i.e.
userGroup: UserGroupByArgs = {
by: ["name"]
}
prismaClient.user.groupBy(userGroup);
will throw an error
src/users/users.resolver.ts:37:5 - error TS2615: Type of property 'AND' circularly references itself in mapped type '{ [K in keyof { AND?: UserScalarWhereWithAggregatesInput[]; OR?: UserScalarWhereWithAggregatesInput[]; NOT?: UserScalarWhereWithAggregatesInput[]; id?: IntWithAggregatesFilter; name?: StringWithAggregatesFilter; profile?: JsonWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingField...'.
37 this.prismaService.user.groupBy(group);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/users/users.resolver.ts:37:5 - error TS2615: Type of property 'NOT' circularly references itself in mapped type '{ [K in keyof { AND?: UserScalarWhereWithAggregatesInput[]; OR?: UserScalarWhereWithAggregatesInput[]; NOT?: UserScalarWhereWithAggregatesInput[]; id?: IntWithAggregatesFilter; name?: StringWithAggregatesFilter; profile?: JsonWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingField...'.
37 this.prismaService.user.groupBy(group);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/users/users.resolver.ts:37:5 - error TS2615: Type of property 'OR' circularly references itself in mapped type '{ [K in keyof { AND?: UserScalarWhereWithAggregatesInput[]; OR?: UserScalarWhereWithAggregatesInput[]; NOT?: UserScalarWhereWithAggregatesInput[]; id?: IntWithAggregatesFilter; name?: StringWithAggregatesFilter; profile?: JsonWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingField...'.
37 this.prismaService.user.groupBy(group);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/users/users.resolver.ts:37:37 - error TS2345: Argument of type 'UserGroupByArgs' is not assignable to parameter of type '{ where?: UserWhereInput; orderBy?: UserOrderByWithAggregationInput[]; by: UserScalarFieldEnum[]; having?: UserScalarWhereWithAggregatesInput; ... 6 more ...; _max?: UserMaxAggregateInput; } & { ...; } & (`Error: Field "${any}" used in "having" needs to be provided in "by".` | [...])'.
Type 'UserGroupByArgs' is not assignable to type '{ where?: UserWhereInput; orderBy?: UserOrderByWithAggregationInput[]; by: UserScalarFieldEnum[]; having?: UserScalarWhereWithAggregatesInput; ... 6 more ...; _max?: UserMaxAggregateInput; } & { ...; } & [...]'.
Type 'UserGroupByArgs' is not assignable to type '{ orderBy: Enumerable<UserOrderByWithAggregationInput>; }'.
Property 'orderBy' is optional in type 'UserGroupByArgs' but required in type '{ orderBy: Enumerable<UserOrderByWithAggregationInput>; }'.
37 this.prismaService.user.groupBy(group);
~~~~~
[00:22:13] Found 4 errors. Watching for file changes.
How to reproduce
- Create a project with prisma as a dependency
- initialise the project and configure db connection
- write schema and generate client
- use groupBy function with parameters as a typed GroupByArgs
- see error
Expected behavior
No type error should be raised when using groupBy with parameters as a typed GroupByArgs
Prisma information
Prisma schema
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount", "orderByRelation", "filterJson"]
}
generator nestgraphql {
provider = "node node_modules/prisma-nestjs-graphql"
output = "../src/graphql"
emitSingle = true
}
model User {
id Int @id @default(autoincrement())
name String
profile Json
}
Prisma client query
@Mutation(() => User)
async createUser(
@Args() params: CreateOneUserArgs,
@Info() info: GraphQLResolveInfo,
) {
const a: UserGroupByArgs = {
by: [UserScalarFieldEnum.id],
};
const b: Prisma.UserGroupByArgs = {
by: [Prisma.UserScalarFieldEnum.id],
};
this.prismaService.user.groupBy(b);
const select = new PrismaSelect(info).value;
params = { ...params, ...select };
return this.prismaService.user.create(params);
}
Environment & setup
- OS: Lubuntu 20.04
- Database: Postgresql 13.
- Node.js version: 14.17.0
Prisma Version
prisma : 2.23.0
@prisma/client : 2.23.0
Current platform : debian-openssl-1.1.x
Query Engine : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio : 0.393.0
Preview Features : selectRelationCount, orderByRelation, filterJson
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Use Pandas groupby() + apply() with arguments
pandas.core.groupby.GroupBy.apply does NOT have named parameter args , but pandas.DataFrame.apply does have it. So try this:
Read more >Group by: split-apply-combine — pandas 1.5.2 documentation
pandas objects can be split on any of their axes. The abstract definition of grouping is to provide a mapping of labels to...
Read more >pandas GroupBy: Your Guide to Grouping Data in Python
groupby () can accept several different arguments: A column or list of columns; A dict or pandas Series; A NumPy array or pandas...
Read more >4 Pandas GroupBy Tricks You Should Know | Medium
Python Pandas Groupby and aggregation functions rename columns, ... it can be used for filtering and transforming dataset just like what we ...
Read more >pyspark.pandas.groupby.GroupBy.apply - Apache Spark
GroupBy. apply (func: Callable, *args: Any, **kwargs: Any) ... The function passed to apply must take a DataFrame as its first argument and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are not using groupBy but we came across this error in some tests when trying to mock the Prisma client.
const mockPrismaClient = mockDeep<PrismaClient>();
This has worked fine on <= 2.19, but we are now trying to upgrade past that and it caused type errors for our entire schema on this mock. I think this is becausegroupBy
was made GA in the 2.20 release so it is now included in our Prisma client.This code was written to test custom middleware, is there a better way we should be mocking the Prisma client for this type of testing?
I’m currently blocked by this. It seems like a pretty core piece of functionality that is completely broken.