From b35b06e86d7c933400d362530e5c85ece6821a58 Mon Sep 17 00:00:00 2001 From: Serhii Tatarintsev Date: Tue, 16 Jan 2024 16:21:49 +0100 Subject: [PATCH] qe: Default `make-qe` task to JSON protocol and improve error message (#4644) * qe: Default `make-qe` task to JSON protocol and improve error message I beleive prisma/team-orm#710 was caused by engine defaulting to GraphQL via `.envrc` file. Error handling in BinaryEngine being broken in this case (prisma/prisma#22636) made finding this out really hard. So, while main fix is done on the client side, I beleive we can adjust few things on the engine side too: - `make-qe` task will now always use JSON protocol. - `make-qe-graphql` task added for cases where it is necessary. For example, using the playground. - Default `PRISMA_ENGINE_PROTOCOL` is removed from `.envrc`. If needed, it can be restored via `.envrc.local`. - Error message adjusted to mention incorrect protocol possiblity. Contributes to prisma/team-orm#710 * Update blackbox test * And again --- .envrc | 1 - Makefile | 5 ++++- query-engine/black-box-tests/tests/protocols/mismatched.rs | 4 ++-- query-engine/query-engine/src/server/mod.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.envrc b/.envrc index d75750f1c7cf..d2e4c1b0ca92 100644 --- a/.envrc +++ b/.envrc @@ -7,7 +7,6 @@ export RUST_LOG=info export PRISMA_DML_PATH=$(pwd)/dev_datamodel.prisma export PRISMA2_BINARY_PATH="/usr/local/lib/node_modules/prisma2/" export PRISMA_BINARY_PATH=$(pwd)/target/release/query-engine -export PRISMA_ENGINE_PROTOCOL="graphql" ### QE config vars, set to testing values ### export SQLITE_MAX_VARIABLE_NUMBER=250000 # This must be in sync with the setting in the engineer build CLI diff --git a/Makefile b/Makefile index dc57f350d750..82f3a81147ab 100644 --- a/Makefile +++ b/Makefile @@ -360,7 +360,10 @@ validate: cargo run --bin test-cli -- validate-datamodel dev_datamodel.prisma qe: - cargo run --bin query-engine -- --enable-playground --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-telemetry-in-response + cargo run --bin query-engine -- --engine-protocol json --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-telemetry-in-response + +qe-graphql: + cargo run --bin query-engine -- --engine-protocol graphql --enable-playground --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-telemetry-in-response qe-dmmf: cargo run --bin query-engine -- cli dmmf > dmmf.json diff --git a/query-engine/black-box-tests/tests/protocols/mismatched.rs b/query-engine/black-box-tests/tests/protocols/mismatched.rs index fe1060e038a3..7bd9969f51f3 100644 --- a/query-engine/black-box-tests/tests/protocols/mismatched.rs +++ b/query-engine/black-box-tests/tests/protocols/mismatched.rs @@ -63,7 +63,7 @@ mod mismatched { .unwrap(); assert_eq!(res.status(), reqwest::StatusCode::UNPROCESSABLE_ENTITY); - insta::assert_snapshot!(res.text().await.unwrap(), @r###"{"is_panic":false,"message":"Error parsing Json query. data did not match any variant of untagged enum JsonBody","backtrace":null}"###); + insta::assert_snapshot!(res.text().await.unwrap(), @r###"{"is_panic":false,"message":"Error parsing Json query. Ensure that engine protocol of the client and the engine matches. data did not match any variant of untagged enum JsonBody","backtrace":null}"###); }) .await } @@ -83,7 +83,7 @@ mod mismatched { .unwrap(); assert_eq!(res.status(), reqwest::StatusCode::UNPROCESSABLE_ENTITY); - insta::assert_snapshot!(res.text().await.unwrap(), @r###"{"is_panic":false,"message":"Error parsing Graphql query. data did not match any variant of untagged enum GraphqlBody","backtrace":null}"###); + insta::assert_snapshot!(res.text().await.unwrap(), @r###"{"is_panic":false,"message":"Error parsing Graphql query. Ensure that engine protocol of the client and the engine matches. data did not match any variant of untagged enum GraphqlBody","backtrace":null}"###); }) .await } diff --git a/query-engine/query-engine/src/server/mod.rs b/query-engine/query-engine/src/server/mod.rs index f3583df310d7..01b61a07b6b4 100644 --- a/query-engine/query-engine/src/server/mod.rs +++ b/query-engine/query-engine/src/server/mod.rs @@ -189,7 +189,7 @@ async fn request_handler(cx: Arc, req: Request) -> Result { let ufe: user_facing_errors::Error = request_handlers::HandlerError::query_conversion(format!( - "Error parsing {:?} query. {}", + "Error parsing {:?} query. Ensure that engine protocol of the client and the engine matches. {}", cx.engine_protocol(), e ))