Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup json/yaml support for cli #3217

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ inputs:
fieldName: postComments
preset:
mergeType: 1
consolidateURL: 0.5
treeShake: true
inferTypeNames: true
output:
path: "./jsonplaceholder.graphql"
format: graphQL
path: "./jsonplaceholder-generated.graphql"
schema:
query: Query
78 changes: 78 additions & 0 deletions examples/jsonplaceholder-generated.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
schema @server @upstream(allowedHeaders: ["Accept", "Content-Type"]) {
query: Query
}

type Address {
city: String
geo: Geo
street: String
suite: String
zipcode: String
}

type Comment {
body: String
email: String
id: Int
name: String
postId: Int
}

type Company {
bs: String
catchPhrase: String
name: String
}

type Geo {
lat: String
lng: String
}

type Photo {
albumId: Int
id: Int
thumbnailUrl: String
title: String
url: String
}

type Post {
body: String
id: Int
title: String
userId: Int
}

type Query {
comment(GEN__1: Int!): Comment @http(url: "https://jsonplaceholder.typicode.com/comments/{{.args.GEN__1}}")
comments: [Comment] @http(url: "https://jsonplaceholder.typicode.com/comments")
photo(GEN__1: Int!): Photo @http(url: "https://jsonplaceholder.typicode.com/photos/{{.args.GEN__1}}")
photos: [Photo] @http(url: "https://jsonplaceholder.typicode.com/photos")
post(GEN__1: Int!): Post @http(url: "https://jsonplaceholder.typicode.com/posts/{{.args.GEN__1}}")
postComments(postId: Int): [Comment]
@http(url: "https://jsonplaceholder.typicode.com/comments", query: [{key: "postId", value: "{{.args.postId}}"}])
posts: [Post] @http(url: "https://jsonplaceholder.typicode.com/posts")
todo(GEN__1: Int!): Todo @http(url: "https://jsonplaceholder.typicode.com/todos/{{.args.GEN__1}}")
todos: [Todo] @http(url: "https://jsonplaceholder.typicode.com/todos")
user(GEN__1: Int!): User @http(url: "https://jsonplaceholder.typicode.com/users/{{.args.GEN__1}}")
users: [User] @http(url: "https://jsonplaceholder.typicode.com/users")
}

type Todo {
completed: Boolean
id: Int
title: String
userId: Int
}

type User {
address: Address
company: Company
email: String
id: Int
name: String
phone: String
username: String
website: String
}
6 changes: 0 additions & 6 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use clap::{Parser, Subcommand};
use strum_macros::Display;
use tailcall_version::VERSION;

use crate::core::config;

const ABOUT: &str = r"
__ _ __ ____
/ /_____ _(_) /________ _/ / /
Expand Down Expand Up @@ -49,10 +47,6 @@ pub enum Command {
#[arg(short, long)]
schema: bool,

/// Prints the input config in the provided format
#[clap(short, long)]
format: Option<config::Source>,

/// Controls SSL/TLS certificate verification for remote config files
/// Set to false to skip certificate verification (not recommended for
/// production)
Expand Down
15 changes: 4 additions & 11 deletions src/cli/generator/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use tailcall_valid::{Valid, ValidateFrom, Validator};
use url::Url;

use crate::core::config::transformer::Preset;
use crate::core::config::{self};
use crate::core::http::Method;

#[derive(Deserialize, Serialize, Debug, Default, Setters)]
Expand Down Expand Up @@ -102,8 +101,6 @@ pub enum Source<Status = UnResolved> {
pub struct Output<Status = UnResolved> {
#[serde(skip_serializing_if = "Location::is_empty")]
pub path: Location<Status>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<config::Source>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -202,10 +199,7 @@ impl Headers {

impl Output<UnResolved> {
pub fn resolve(self, parent_dir: Option<&Path>) -> anyhow::Result<Output<Resolved>> {
Ok(Output {
format: self.format,
path: self.path.into_resolved(parent_dir),
})
Ok(Output { path: self.path.into_resolved(parent_dir) })
}
}

Expand Down Expand Up @@ -451,10 +445,9 @@ mod tests {
let json = r#"
{"output": {
"paths": "./output.graphql",
}}
}}
"#;
let expected_error =
"unknown field `paths`, expected `path` or `format` at line 3 column 21";
let expected_error = "unknown field `paths`, expected `path` at line 3 column 21";
assert_deserialization_error(json, expected_error);
}

Expand All @@ -463,7 +456,7 @@ mod tests {
let json = r#"
{"schema": {
"querys": "Query",
}}
}}
"#;
let expected_error =
"unknown field `querys`, expected `query` or `mutation` at line 3 column 22";
Expand Down
4 changes: 2 additions & 2 deletions src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;
use std::path::Path;

use anyhow::anyhow;
use http::header::{HeaderMap, HeaderName, HeaderValue};
use inquire::Confirm;
use pathdiff::diff_paths;
Expand Down Expand Up @@ -34,9 +35,8 @@
async fn write(self, graphql_config: &ConfigModule, output_path: &str) -> anyhow::Result<()> {
let output_source = config::Source::detect(output_path)?;
let config = match output_source {
config::Source::Json => graphql_config.to_json(true)?,
config::Source::Yml => graphql_config.to_yaml()?,
config::Source::GraphQL => graphql_config.to_sdl(),
_ => return Err(anyhow!("Only graphql output format is currently supported")),

Check warning on line 39 in src/cli/generator/generator.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/generator/generator.rs#L39

Added line #L39 was not covered by tests
};

if self.should_overwrite(output_path)? {
Expand Down
7 changes: 1 addition & 6 deletions src/cli/tc/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
use crate::cli::fmt::Fmt;
use crate::core::blueprint::Blueprint;
use crate::core::config::reader::ConfigReader;
use crate::core::config::Source;
use crate::core::runtime::TargetRuntime;
use crate::core::Errata;

pub(super) struct CheckParams {
pub(super) file_paths: Vec<String>,
pub(super) n_plus_one_queries: bool,
pub(super) schema: bool,
pub(super) format: Option<Source>,
pub(super) runtime: TargetRuntime,
}

pub(super) async fn check_command(params: CheckParams, config_reader: &ConfigReader) -> Result<()> {
let CheckParams { file_paths, n_plus_one_queries, schema, format, runtime } = params;
let CheckParams { file_paths, n_plus_one_queries, schema, runtime } = params;

Check warning on line 18 in src/cli/tc/check.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/check.rs#L18

Added line #L18 was not covered by tests

let config_module = (config_reader.read_all(&file_paths)).await?;
log_endpoint_set(&config_module.extensions().endpoint_set);
if let Some(format) = format {
Fmt::display(format.encode(&config_module)?);
}
let blueprint = Blueprint::try_from(&config_module).map_err(Errata::from);

match blueprint {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/tc/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
validate_rc_config_files(runtime, &file_paths).await;
start::start_command(file_paths, &config_reader).await?;
}
Command::Check { file_paths, n_plus_one_queries, schema, format, verify_ssl } => {
Command::Check { file_paths, n_plus_one_queries, schema, verify_ssl } => {

Check warning on line 49 in src/cli/tc/run.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/run.rs#L49

Added line #L49 was not covered by tests
let (runtime, config_reader) = get_runtime_and_config_reader(verify_ssl);
validate_rc_config_files(runtime.clone(), &file_paths).await;
check::check_command(
check::CheckParams { file_paths, n_plus_one_queries, schema, format, runtime },
check::CheckParams { file_paths, n_plus_one_queries, schema, runtime },

Check warning on line 53 in src/cli/tc/run.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/run.rs#L53

Added line #L53 was not covered by tests
&config_reader,
)
.await?;
Expand Down
36 changes: 0 additions & 36 deletions tailcall-fixtures/fixtures/generator/simple-json.json

This file was deleted.

3 changes: 1 addition & 2 deletions tests/cli/fixtures/generator/gen_deezer.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"inferTypeNames": true
},
"output": {
"path": "./output.graphql",
"format": "graphQL"
"path": "./output.graphql"
},
"schema": {
"query": "Query"
Expand Down
3 changes: 1 addition & 2 deletions tests/cli/fixtures/generator/gen_json_proto_mix_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"treeShake": true
},
"output": {
"path": "./output.graphql",
"format": "graphQL"
"path": "./output.graphql"
},
"schema": {
"query": "Query"
Expand Down
3 changes: 1 addition & 2 deletions tests/cli/fixtures/generator/gen_jsonplaceholder.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
"inferTypeNames": true
},
"output": {
"path": "./output.graphql",
"format": "graphQL"
"path": "./output.graphql"
},
"schema": {
"query": "Query"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"treeShake": true
},
"output": {
"path": "./output.graphql",
"format": "graphQL"
"path": "./output.graphql"
},
"schema": {
"query": "Query"
Expand Down
3 changes: 1 addition & 2 deletions tests/cli/fixtures/generator/proto-connect-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"treeShake": true
},
"output": {
"path": "./output.graphql",
"format": "graphQL"
"path": "./output.graphql"
},
"schema": {
"query": "Query"
Expand Down
Loading