Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.75k stars 106 forks source link

Prisma Client From Trait QueryError to rspc::Error not working #464

Closed alelopezperez closed 1 hour ago

alelopezperez commented 4 days ago

Error: the trait From<QueryError> is not implemented for rspc::Error, which is required by `QueryError: Into<>_

I see that in prisma-client-rust error.rs has the trait for, but when tryint to use it does not work

#[cfg(feature = "rspc")]
impl From<QueryError> for rspc::Error {
    fn from(err: QueryError) -> Self {
        rspc::Error::with_cause(
            rspc::ErrorCode::InternalServerError,
            "Internal server error occurred while completing database operation!".into(),
            err,
        )
    }
}

cargo.toml

prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.11", features = [
    "mysql",
    "rspc",
    "migrations",
    "specta",
], default-features = false }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.11", features = [
    "mysql",
    "rspc",
    "migrations",
    "specta",
], default-features = false }

rspc = { git = "https://github.com/oscartbeaumont/rspc", tag = 'v0.2.0' }
rspc-axum = { git = "https://github.com/oscartbeaumont/rspc", tag = "v0.2.0", features = [
    "ws",
] }

src/main.rs

  let client_api_routes = rspc::Router::<PrismaClient>::new().mutation("/create", |t| {
        t(|ctx, input: prisma::client::Data| async move {
            let ans = ctx
                .client()
                .create(
                    "Name".to_string(),
                    "1234567".to_string(),
                    "/menu".to_string(),
                    vec![],
                )
                .exec()
                .await;
            let get_error_for_test = ans.unwrap_err();
            let into: rspc::Error = get_error_for_test.into();
        })
    });
oscartbeaumont commented 1 day ago

I suspect the issue is here to due to your projects rspc and PCR's rspc version not matching as Rust types across crate versions are treated as being discrete.

You could try:

rspc = "0.2.0"
rspc-axum = { git = "https://github.com/oscartbeaumont/rspc", tag = "v0.2.0", features = [
    "ws",
] }

# I am fairly sure these patches apply to dependencies too (which you want for the `rspc` dependency in PCR)
# Be aware this needs to go in your workspaces `Cargo.toml` if your using a Cargo workspace.
[patch.crates-io]
rspc = { git = "https://github.com/oscartbeaumont/rspc", tag = 'v0.2.0' }

Alternatively you might have to fork PCR and change the rspc import to match your one (or just use the crates.io release of rspc which should be fine).