From 4314363bd5ff97d7956fc46c0b04a337bf4a608b Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Sun, 15 Sep 2024 17:16:49 -0400 Subject: [PATCH] chore(link): add `meta` support --- generated/.tailcallrc.graphql | 4 ++ generated/.tailcallrc.schema.json | 3 + src/core/config/link.rs | 3 + src/core/generator/generator.rs | 1 + src/core/grpc/data_loader_request.rs | 1 + src/core/grpc/protobuf.rs | 1 + src/core/grpc/request_template.rs | 1 + .../test-link-support.md_client.snap | 55 +++++++++++++++++++ .../test-link-support.md_merged.snap | 26 +++++++++ tests/execution/test-link-support.md | 50 +++++++++++++++++ 10 files changed, 145 insertions(+) create mode 100644 tests/core/snapshots/test-link-support.md_client.snap create mode 100644 tests/core/snapshots/test-link-support.md_merged.snap create mode 100644 tests/execution/test-link-support.md diff --git a/generated/.tailcallrc.graphql b/generated/.tailcallrc.graphql index a2ba1acf44..9839a55c87 100644 --- a/generated/.tailcallrc.graphql +++ b/generated/.tailcallrc.graphql @@ -207,6 +207,10 @@ directive @link( """ id: String """ + Metadata + """ + metadata: JSON + """ The source of the link. It can be a URL or a path to a file. If a path is provided, it is relative to the file that imports the link. """ diff --git a/generated/.tailcallrc.schema.json b/generated/.tailcallrc.schema.json index 76e5cab3c2..5e4efe5fac 100644 --- a/generated/.tailcallrc.schema.json +++ b/generated/.tailcallrc.schema.json @@ -803,6 +803,9 @@ "null" ] }, + "metadata": { + "description": "Metadata" + }, "src": { "description": "The source of the link. It can be a URL or a path to a file. If a path is provided, it is relative to the file that imports the link.", "type": "string" diff --git a/src/core/config/link.rs b/src/core/config/link.rs index d8cf0ecd1c..d99fdc7770 100644 --- a/src/core/config/link.rs +++ b/src/core/config/link.rs @@ -57,4 +57,7 @@ pub struct Link { /// The type of the link. It can be `Config`, or `Protobuf`. #[serde(default, skip_serializing_if = "is_default", rename = "type")] pub type_of: LinkType, + /// Metadata + #[serde(default, skip_serializing_if = "is_default")] + pub meta: Option, } diff --git a/src/core/generator/generator.rs b/src/core/generator/generator.rs index ce04350304..bd5fc0387c 100644 --- a/src/core/generator/generator.rs +++ b/src/core/generator/generator.rs @@ -90,6 +90,7 @@ impl Generator { id: None, src: metadata.path.to_owned(), type_of: LinkType::Protobuf, + meta: None, }); Ok(config) } diff --git a/src/core/grpc/data_loader_request.rs b/src/core/grpc/data_loader_request.rs index 7179a19005..b8b02c3f35 100644 --- a/src/core/grpc/data_loader_request.rs +++ b/src/core/grpc/data_loader_request.rs @@ -73,6 +73,7 @@ mod tests { id: None, src: test_file.to_string(), type_of: LinkType::Protobuf, + meta: None, }]); let method = GrpcMethod { package: "greetings".to_string(), diff --git a/src/core/grpc/protobuf.rs b/src/core/grpc/protobuf.rs index adcea67407..df28845dbd 100644 --- a/src/core/grpc/protobuf.rs +++ b/src/core/grpc/protobuf.rs @@ -266,6 +266,7 @@ pub mod tests { id: Some(id.clone()), src: path.to_string(), type_of: LinkType::Protobuf, + meta: None, }]); let method = GrpcMethod { package: id, service: "a".to_owned(), name: "b".to_owned() }; diff --git a/src/core/grpc/request_template.rs b/src/core/grpc/request_template.rs index ceddf1ac2a..c96bd1a2f5 100644 --- a/src/core/grpc/request_template.rs +++ b/src/core/grpc/request_template.rs @@ -160,6 +160,7 @@ mod tests { id: Some(id.clone()), src: test_file.to_string(), type_of: LinkType::Protobuf, + meta: None, }]); let method = GrpcMethod { package: id.to_string(), diff --git a/tests/core/snapshots/test-link-support.md_client.snap b/tests/core/snapshots/test-link-support.md_client.snap new file mode 100644 index 0000000000..3127ff26a7 --- /dev/null +++ b/tests/core/snapshots/test-link-support.md_client.snap @@ -0,0 +1,55 @@ +--- +source: tests/core/spec.rs +expression: formatted +--- +scalar Bytes + +scalar Date + +scalar DateTime + +scalar Email + +scalar Empty + +scalar Int128 + +scalar Int16 + +scalar Int32 + +scalar Int64 + +scalar Int8 + +scalar JSON + +type News { + id: Int +} + +input NewsInput { + id: Int +} + +scalar PhoneNumber + +type Query { + newsById(news: NewsInput!): News! +} + +scalar UInt128 + +scalar UInt16 + +scalar UInt32 + +scalar UInt64 + +scalar UInt8 + +scalar Url + +schema { + query: Query +} diff --git a/tests/core/snapshots/test-link-support.md_merged.snap b/tests/core/snapshots/test-link-support.md_merged.snap new file mode 100644 index 0000000000..3f7d7e033d --- /dev/null +++ b/tests/core/snapshots/test-link-support.md_merged.snap @@ -0,0 +1,26 @@ +--- +source: tests/core/spec.rs +expression: formatter +--- +schema + @server(port: 8000) + @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000}) + @link(id: "news", src: "news.proto", metadata: {description: "Test"}, type: Protobuf) { + query: Query +} + +input NewsInput { + id: Int +} + +type News { + id: Int +} + +type NewsData { + news: [News] +} + +type Query { + newsById(news: NewsInput!): News! @grpc(body: "{{.args.news}}", method: "news.NewsService.GetNews") +} diff --git a/tests/execution/test-link-support.md b/tests/execution/test-link-support.md new file mode 100644 index 0000000000..0377f8bd5a --- /dev/null +++ b/tests/execution/test-link-support.md @@ -0,0 +1,50 @@ +--- +identity: true +--- + +# test-link-support + +```protobuf @file:news.proto +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package news; + +message News { + int32 id = 1; +} + +service NewsService { + rpc GetNews (NewsId) returns (News) {} +} + +message NewsId { + int32 id = 1; +} +``` + +```graphql @config +schema + @server(port: 8000) + @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000}) +@link(id: "news", src: "news.proto", metadata: {description: "Test"}, type: Protobuf) { + query: Query +} + +input NewsInput { + id: Int +} + +type News { + id: Int +} + +type NewsData { + news: [News] +} + +type Query { + newsById(news: NewsInput!): News! @grpc(body: "{{.args.news}}", method: "news.NewsService.GetNews") +} +```