diff --git a/examples/generate.yml b/examples/generate.yml index 13b1a909ea..ff353659e6 100644 --- a/examples/generate.yml +++ b/examples/generate.yml @@ -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 diff --git a/examples/jsonplaceholder-generated.graphql b/examples/jsonplaceholder-generated.graphql new file mode 100644 index 0000000000..9236d733c4 --- /dev/null +++ b/examples/jsonplaceholder-generated.graphql @@ -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 +} diff --git a/src/cli/command.rs b/src/cli/command.rs index cb62f4816e..0f1849a67e 100644 --- a/src/cli/command.rs +++ b/src/cli/command.rs @@ -2,8 +2,6 @@ use clap::{Parser, Subcommand}; use strum_macros::Display; use tailcall_version::VERSION; -use crate::core::config; - const ABOUT: &str = r" __ _ __ ____ / /_____ _(_) /________ _/ / / @@ -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, - /// Controls SSL/TLS certificate verification for remote config files /// Set to false to skip certificate verification (not recommended for /// production) diff --git a/src/cli/generator/config.rs b/src/cli/generator/config.rs index 1e6e8f119c..b753ab9c46 100644 --- a/src/cli/generator/config.rs +++ b/src/cli/generator/config.rs @@ -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)] @@ -102,8 +101,6 @@ pub enum Source { pub struct Output { #[serde(skip_serializing_if = "Location::is_empty")] pub path: Location, - #[serde(skip_serializing_if = "Option::is_none")] - pub format: Option, } #[derive(Debug)] @@ -202,10 +199,7 @@ impl Headers { impl Output { pub fn resolve(self, parent_dir: Option<&Path>) -> anyhow::Result> { - Ok(Output { - format: self.format, - path: self.path.into_resolved(parent_dir), - }) + Ok(Output { path: self.path.into_resolved(parent_dir) }) } } @@ -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); } @@ -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"; diff --git a/src/cli/generator/generator.rs b/src/cli/generator/generator.rs index 94ef7319cd..3fa3165396 100644 --- a/src/cli/generator/generator.rs +++ b/src/cli/generator/generator.rs @@ -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; @@ -34,9 +35,8 @@ impl Generator { 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")), }; if self.should_overwrite(output_path)? { diff --git a/src/cli/tc/check.rs b/src/cli/tc/check.rs index 6816836092..9aca36c783 100644 --- a/src/cli/tc/check.rs +++ b/src/cli/tc/check.rs @@ -4,7 +4,6 @@ use super::helpers::{display_schema, log_endpoint_set}; 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; @@ -12,18 +11,14 @@ pub(super) struct CheckParams { pub(super) file_paths: Vec, pub(super) n_plus_one_queries: bool, pub(super) schema: bool, - pub(super) format: Option, 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; 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 { diff --git a/src/cli/tc/run.rs b/src/cli/tc/run.rs index 61f93f4394..ecb8d2a55f 100644 --- a/src/cli/tc/run.rs +++ b/src/cli/tc/run.rs @@ -46,11 +46,11 @@ async fn run_command(cli: Cli) -> Result<()> { 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 } => { 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 }, &config_reader, ) .await?; diff --git a/tailcall-fixtures/fixtures/generator/simple-json.json b/tailcall-fixtures/fixtures/generator/simple-json.json deleted file mode 100644 index 9e1d8f61cf..0000000000 --- a/tailcall-fixtures/fixtures/generator/simple-json.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "inputs": [ - { - "curl": { - "src": "https://jsonplaceholder.typicode.com/posts/1", - "headers": { - "Content-Type": "application/json", - "Accept": "application/json" - }, - "fieldName": "post" - } - }, - { - "curl": { - "src": "https://jsonplaceholder.typicode.com/posts", - "fieldName": "posts" - } - }, - { - "proto": { - "src": "../protobuf/news.proto" - } - } - ], - "preset": { - "mergeType": 1.0, - "consolidateURL": 0.5 - }, - "output": { - "path": "./output.graphql", - "format": "graphQL" - }, - "schema": { - "query": "Query" - } -} diff --git a/tests/cli/fixtures/generator/gen_deezer.md b/tests/cli/fixtures/generator/gen_deezer.md index 744b7e1bc8..3dc19e88d3 100644 --- a/tests/cli/fixtures/generator/gen_deezer.md +++ b/tests/cli/fixtures/generator/gen_deezer.md @@ -56,8 +56,7 @@ "inferTypeNames": true }, "output": { - "path": "./output.graphql", - "format": "graphQL" + "path": "./output.graphql" }, "schema": { "query": "Query" diff --git a/tests/cli/fixtures/generator/gen_json_proto_mix_config.md b/tests/cli/fixtures/generator/gen_json_proto_mix_config.md index 5fe595e5f0..42a8406490 100644 --- a/tests/cli/fixtures/generator/gen_json_proto_mix_config.md +++ b/tests/cli/fixtures/generator/gen_json_proto_mix_config.md @@ -20,8 +20,7 @@ "treeShake": true }, "output": { - "path": "./output.graphql", - "format": "graphQL" + "path": "./output.graphql" }, "schema": { "query": "Query" diff --git a/tests/cli/fixtures/generator/gen_jsonplaceholder.md b/tests/cli/fixtures/generator/gen_jsonplaceholder.md index 9c3066ff49..d1f6335ea2 100644 --- a/tests/cli/fixtures/generator/gen_jsonplaceholder.md +++ b/tests/cli/fixtures/generator/gen_jsonplaceholder.md @@ -78,8 +78,7 @@ "inferTypeNames": true }, "output": { - "path": "./output.graphql", - "format": "graphQL" + "path": "./output.graphql" }, "schema": { "query": "Query" diff --git a/tests/cli/fixtures/generator/gen_proto_with_proto_paths_config.md b/tests/cli/fixtures/generator/gen_proto_with_proto_paths_config.md index 618da86ab5..5b508368e3 100644 --- a/tests/cli/fixtures/generator/gen_proto_with_proto_paths_config.md +++ b/tests/cli/fixtures/generator/gen_proto_with_proto_paths_config.md @@ -21,8 +21,7 @@ "treeShake": true }, "output": { - "path": "./output.graphql", - "format": "graphQL" + "path": "./output.graphql" }, "schema": { "query": "Query" diff --git a/tests/cli/fixtures/generator/proto-connect-rpc.md b/tests/cli/fixtures/generator/proto-connect-rpc.md index cd16f7bc2c..8bbe9bde78 100644 --- a/tests/cli/fixtures/generator/proto-connect-rpc.md +++ b/tests/cli/fixtures/generator/proto-connect-rpc.md @@ -21,8 +21,7 @@ "treeShake": true }, "output": { - "path": "./output.graphql", - "format": "graphQL" + "path": "./output.graphql" }, "schema": { "query": "Query"