Describe the bug
Fluent API of TS client breaks in latest beta
To Reproduce
Use the latest beta: prisma/1.20.0-beta.22
prisma initUpdate the data model to this and deploy afterwards and regenerate the client afterwards:
type Post {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
title: String!
published: Boolean! @default(value: "false")
author: User
comments: [Comment!]!
}
type User {
id: ID! @unique
name: String
email: String! @unique
role: Role! @default(value: "USER")
posts: [Post!]!
comments: [Comment!]!
}
type Comment {
id: ID! @unique
createdAt: DateTime!
text: String!
post: Post!
writtenBy: User!
}
enum Role {
USER
ADMIN
}
Try to run the following TS code in a script:
import { prisma } from "../generated/prisma-client";
async function main() {
const posts = prisma.user({
email: "[email protected]"
}).posts()
}
main();
Property 'comments' does not exist on type 'Post'.Here's what my package.json looks like:
{
"devDependencies": {
"ts-node": "^7.0.1",
"typescript": "^3.1.4"
},
"dependencies": {
"graphql": "0.13",
"graphql-tools": "^4.0.3",
"prisma-client-lib": "^1.19.1"
},
"scripts": {
"ts-node": "ts-node",
"start": "ts-node ./src/index.ts"
}
}
Expected behavior
The Fluent API should work.
I'm getting a similar error.
I think the problem is that all queries are not using the right interface.
prisma-client/index.ts
export interface Prisma {
user: (where: UserWhereUniqueInput) => User;
}
should be changed to
export interface Prisma {
user: (where: UserWhereUniqueInput) => UserPromise;
}
After I updated my project to 1.20.0-beta.24 I'm getting the following error.
Cannot find name 'NodePromise'
export interface Prisma {
node: (args: { id: ID_Output }) => NodePromise;
}
Suggestion: It would be great to have some tests so that this cannot happen anymore.
Having the same problem. Changing NodePromise to Node fixed it for me (at least 'yarn start' starts the server now). BUT as we are not supposed to change the index.ts whatsoever I'm kind of confused what to do. I'm using the 1.21 alpha due to the mongodb support
I'm having same problem on 1.20 stable, I can't compile my project
This is fixed in [email protected] - please install it via npm install -g prisma@beta
@divyenduz Should I create a new ticket for adding tests or do you want to do this in this ticket?
The tests should include generating a prisma-client based on a more complex schema.graphql like in this project. After that the prisma-client should be successfully compiled. The test should fail when the compilation fails.
@sapkra : Thanks! please create a new issue, also add to that, that we should add executing operations against a live Prisma service in the test suite to test prisma-client-lib part and tag me on that issue 馃檹
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
After I updated my project to
1.20.0-beta.24I'm getting the following error.Suggestion: It would be great to have some tests so that this cannot happen anymore.