Skip to content

Commit b979f5f

Browse files
NicolappsConvex, Inc.
authored and
Convex, Inc.
committed
Revert Fivetran POST requests (#37305) (#37351)
GitOrigin-RevId: c33d9f446aa01af64cee991557f829ee3ae51861
1 parent 967e5d2 commit b979f5f

File tree

2 files changed

+27
-68
lines changed

2 files changed

+27
-68
lines changed

crates/fivetran_source/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ derive_more = { workspace = true }
1919
futures = { workspace = true }
2020
futures-async-stream = { workspace = true }
2121
headers = { workspace = true }
22+
maplit = { workspace = true }
2223
prost = { workspace = true }
2324
prost-types = { workspace = true }
2425
reqwest = { workspace = true }
@@ -39,7 +40,6 @@ tonic-build = { workspace = true }
3940
cmd_util = { path = "../cmd_util" }
4041
convex = { path = "../convex", features = ["testing"] }
4142
convex_fivetran_common = { path = "../fivetran_common", features = ["testing"] }
42-
maplit = { workspace = true }
4343
proptest = { workspace = true }
4444
proptest-derive = { workspace = true }
4545
rand = { workspace = true }

crates/fivetran_source/src/convex_api.rs

+26-67
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ use std::{
77
use anyhow::Context;
88
use async_trait::async_trait;
99
use convex_fivetran_common::config::Config;
10-
use convex_fivetran_source::api_types::{
11-
DocumentDeltasArgs,
12-
ListSnapshotArgs,
13-
};
1410
use derive_more::{
1511
Display,
1612
From,
@@ -20,6 +16,7 @@ use headers::{
2016
HeaderName,
2117
HeaderValue,
2218
};
19+
use maplit::btreemap;
2320
use serde::{
2421
de::DeserializeOwned,
2522
Deserialize,
@@ -69,70 +66,35 @@ pub struct ConvexApi {
6966
}
7067

7168
impl ConvexApi {
72-
/// Performs a GET HTTP request to a given endpoint of the Convex API.
73-
async fn get<T: DeserializeOwned>(&self, endpoint: &str) -> anyhow::Result<T> {
74-
let url = self
75-
.config
76-
.deploy_url
77-
.join("api/")
78-
.unwrap()
79-
.join(endpoint)
80-
.unwrap();
81-
82-
match reqwest::Client::new()
83-
.get(url)
84-
.header(CONVEX_CLIENT_HEADER, &*CONVEX_CLIENT_HEADER_VALUE)
85-
.header(
86-
reqwest::header::AUTHORIZATION,
87-
format!("Convex {}", self.config.deploy_key),
88-
)
89-
.send()
90-
.await
91-
{
92-
Ok(resp) if resp.status().is_success() => Ok(resp
93-
.json::<T>()
94-
.await
95-
.context("Failed to deserialize query result")?),
96-
Ok(resp) => {
97-
if let Ok(text) = resp.text().await {
98-
anyhow::bail!(
99-
"Call to {endpoint} on {} returned an unsuccessful response: {text}",
100-
self.config.deploy_url
101-
)
102-
} else {
103-
anyhow::bail!(
104-
"Call to {endpoint} on {} returned no response",
105-
self.config.deploy_url
106-
)
107-
}
108-
},
109-
Err(e) => anyhow::bail!(e.to_string()),
110-
}
111-
}
112-
113-
/// Performs a POST HTTP request to a given endpoint of the Convex API using
114-
/// the given parameters as a JSON body.
115-
async fn post<P: Serialize, T: DeserializeOwned>(
69+
/// Performs a GET HTTP request to a given endpoint of the Convex API using
70+
/// the given query parameters.
71+
async fn get<T: DeserializeOwned>(
11672
&self,
11773
endpoint: &str,
118-
parameters: P,
74+
parameters: BTreeMap<&str, Option<String>>,
11975
) -> anyhow::Result<T> {
120-
let url = self
76+
let non_null_parameters: BTreeMap<&str, String> = parameters
77+
.into_iter()
78+
.filter_map(|(key, value)| value.map(|value| (key, value)))
79+
.collect();
80+
81+
let mut url = self
12182
.config
12283
.deploy_url
12384
.join("api/")
12485
.unwrap()
12586
.join(endpoint)
12687
.unwrap();
12788

89+
url.query_pairs_mut().extend_pairs(non_null_parameters);
90+
12891
match reqwest::Client::new()
129-
.post(url)
92+
.get(url)
13093
.header(CONVEX_CLIENT_HEADER, &*CONVEX_CLIENT_HEADER_VALUE)
13194
.header(
13295
reqwest::header::AUTHORIZATION,
13396
format!("Convex {}", self.config.deploy_key),
13497
)
135-
.json(&parameters)
13698
.send()
13799
.await
138100
{
@@ -161,22 +123,21 @@ impl ConvexApi {
161123
#[async_trait]
162124
impl Source for ConvexApi {
163125
async fn test_streaming_export_connection(&self) -> anyhow::Result<()> {
164-
self.get("test_streaming_export_connection").await
126+
self.get("test_streaming_export_connection", btreemap! {})
127+
.await
165128
}
166129

167130
async fn list_snapshot(
168131
&self,
169132
snapshot: Option<i64>,
170133
cursor: Option<ListSnapshotCursor>,
171134
) -> anyhow::Result<ListSnapshotResponse> {
172-
self.post(
135+
self.get(
173136
"list_snapshot",
174-
ListSnapshotArgs {
175-
snapshot,
176-
cursor: cursor.map(|c| c.into()),
177-
table_name: None,
178-
component: None,
179-
format: Some("convex_encoded_json".to_string()),
137+
btreemap! {
138+
"snapshot" => snapshot.map(|n| n.to_string()),
139+
"cursor" => cursor.map(|n| n.to_string()),
140+
"format" => Some("convex_encoded_json".to_string()),
180141
},
181142
)
182143
.await
@@ -186,21 +147,19 @@ impl Source for ConvexApi {
186147
&self,
187148
cursor: DocumentDeltasCursor,
188149
) -> anyhow::Result<DocumentDeltasResponse> {
189-
self.post(
150+
self.get(
190151
"document_deltas",
191-
DocumentDeltasArgs {
192-
cursor: Some(cursor.into()),
193-
table_name: None,
194-
component: None,
195-
format: Some("convex_encoded_json".to_string()),
152+
btreemap! {
153+
"cursor" => Some(cursor.to_string()),
154+
"format" => Some("convex_encoded_json".to_string()),
196155
},
197156
)
198157
.await
199158
}
200159

201160
async fn get_tables_and_columns(&self) -> anyhow::Result<BTreeMap<TableName, Vec<FieldName>>> {
202161
let tables_to_columns: BTreeMap<TableName, Vec<String>> =
203-
self.get("get_tables_and_columns").await?;
162+
self.get("get_tables_and_columns", btreemap! {}).await?;
204163

205164
tables_to_columns
206165
.into_iter()

0 commit comments

Comments
 (0)