Skip to content

Commit

Permalink
fix: generator config clean up. (#2251)
Browse files Browse the repository at this point in the history
Co-authored-by: meskill <[email protected]>
Co-authored-by: Ranjit Mahadik <[email protected]>
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
4 people authored Jun 23, 2024
1 parent 84e57f2 commit 2606a1f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
44 changes: 18 additions & 26 deletions src/cli/generator/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,22 @@ impl Location<UnResolved> {
pub struct Input<Status = UnResolved> {
#[serde(flatten)]
pub source: Source<Status>,
pub field_name: String,
pub operation: Operation,
}

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum Source<Status = UnResolved> {
Curl { src: Location<Status> },
Proto { src: Location<Status> },
Config { src: Location<Status> },
#[serde(rename_all = "camelCase")]
Curl {
src: Location<Status>,
field_name: String,
},
Proto {
src: Location<Status>,
},
Config {
src: Location<Status>,
},
}

#[derive(Deserialize, Serialize, Debug, Default)]
Expand All @@ -104,14 +110,6 @@ pub struct Output<Status = UnResolved> {
pub format: Option<config::Source>,
}

#[derive(Deserialize, Serialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub enum Operation {
#[default]
Query,
Mutation,
}

#[derive(Debug)]
pub enum Resolved {}

Expand Down Expand Up @@ -139,9 +137,9 @@ impl Output<UnResolved> {
impl Source<UnResolved> {
pub fn resolve(self, parent_dir: Option<&Path>) -> anyhow::Result<Source<Resolved>> {
match self {
Source::Curl { src } => {
Source::Curl { src, field_name } => {
let resolved_path = src.into_resolved(parent_dir);
Ok(Source::Curl { src: resolved_path })
Ok(Source::Curl { src: resolved_path, field_name })
}
Source::Proto { src, .. } => {
let resolved_path = src.into_resolved(parent_dir);
Expand All @@ -158,11 +156,7 @@ impl Source<UnResolved> {
impl Input<UnResolved> {
pub fn resolve(self, parent_dir: Option<&Path>) -> anyhow::Result<Input<Resolved>> {
let resolved_source = self.source.resolve(parent_dir)?;
Ok(Input {
source: resolved_source,
field_name: self.field_name,
operation: self.operation,
})
Ok(Input { source: resolved_source })
}
}

Expand Down Expand Up @@ -193,14 +187,12 @@ mod tests {

#[test]
fn test_config_codec() {
let config = Config::default().inputs(vec![
//
Input {
let config = Config::default().inputs(vec![Input {
source: Source::Curl {
src: location("https://example.com"),
field_name: "test".to_string(),
operation: Operation::Query,
source: Source::Curl { src: location("https://example.com") },
},
]);
}]);
let actual = serde_json::to_string_pretty(&config).unwrap();
insta::assert_snapshot!(actual)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ impl Generator {

for input in config.inputs {
match input.source {
Source::Curl { src, .. } => {
Source::Curl { src, field_name } => {
let url = src.0;
let contents = reader.read_file(&url).await?.content;
input_samples.push(Input::Json {
url: url.parse()?,
response: serde_json::from_str(&contents)?,
field_name: input.field_name,
field_name,
});
}
Source::Proto { src } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ expression: actual
"inputs": [
{
"curl": {
"src": "https://example.com"
},
"fieldName": "test",
"operation": "query"
"src": "https://example.com",
"fieldName": "test"
}
}
],
"output": {},
Expand Down
18 changes: 7 additions & 11 deletions tailcall-fixtures/fixtures/generator/simple-json.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"inputs": [
{
"URL": {
"url": "https://jsonplaceholder.typicode.com/posts/1"
},
"fieldName": "post",
"operation": "Query"
"curl": {
"src": "https://jsonplaceholder.typicode.com/posts/1",
"fieldName": "post"
}
},
{
"URL": {
"url": "https://jsonplaceholder.typicode.com/posts"
},
"fieldName": "posts",
"operation": "Query"
"proto": {
"src": "../protobuf/news.proto"
}
}
],

"preset": {
"mergeType": 1,
"consolidateURL": 0.5
Expand Down

1 comment on commit 2606a1f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.59ms 2.94ms 73.84ms 71.73%
Req/Sec 3.83k 132.76 4.40k 85.25%

457888 requests in 30.01s, 2.30GB read

Requests/sec: 15258.50

Transfer/sec: 78.32MB

Please sign in to comment.