From e6ea2734258af981a4eaf71c293e5f198e7de65c Mon Sep 17 00:00:00 2001 From: DLillard0 <565570086@qq.com> Date: Mon, 16 Dec 2024 16:20:48 +0800 Subject: [PATCH] feat: link config support proto paths --- generated/.tailcallrc.schema.json | 10 ++++++++++ src/core/config/directives/link.rs | 5 +++++ src/core/config/reader.rs | 8 +++++++- 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 + 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/generated/.tailcallrc.schema.json b/generated/.tailcallrc.schema.json index 62a29551d1d..55fbf80df19 100644 --- a/generated/.tailcallrc.schema.json +++ b/generated/.tailcallrc.schema.json @@ -269,6 +269,16 @@ "meta": { "description": "Additional metadata pertaining to the linked resource." }, + "proto_paths": { + "description": "The proto paths to be used when resolving dependencies. Only valid when [`Link::type_of`] is [`LinkType::Protobuf`]", + "type": [ + "array", + "null" + ], + "items": { + "type": "string" + } + }, "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/directives/link.rs b/src/core/config/directives/link.rs index 5063812a2f4..e045caf98c3 100644 --- a/src/core/config/directives/link.rs +++ b/src/core/config/directives/link.rs @@ -93,4 +93,9 @@ pub struct Link { /// Additional metadata pertaining to the linked resource. #[serde(default, skip_serializing_if = "is_default")] pub meta: Option, + /// + /// The proto paths to be used when resolving dependencies. + /// Only valid when [`Link::type_of`] is [`LinkType::Protobuf`] + #[serde(default, skip_serializing_if = "is_default")] + pub proto_paths: Option>, } diff --git a/src/core/config/reader.rs b/src/core/config/reader.rs index 675c6a9d42a..5240e658e80 100644 --- a/src/core/config/reader.rs +++ b/src/core/config/reader.rs @@ -79,7 +79,13 @@ impl ConfigReader { }); } LinkType::Protobuf => { - let meta = self.proto_reader.read(path, None).await?; + let proto_paths = link.proto_paths.as_ref().map(|paths| { + paths + .iter() + .map(|p| Self::resolve_path(p, parent_dir)) + .collect::>() + }); + let meta = self.proto_reader.read(path, proto_paths.as_deref()).await?; extensions.add_proto(meta); } LinkType::Script => { diff --git a/src/core/generator/generator.rs b/src/core/generator/generator.rs index 98cb81515ef..5bcee1f5564 100644 --- a/src/core/generator/generator.rs +++ b/src/core/generator/generator.rs @@ -99,6 +99,7 @@ impl Generator { type_of: LinkType::Protobuf, headers: None, meta: None, + proto_paths: None, }); Ok(config) } diff --git a/src/core/grpc/data_loader_request.rs b/src/core/grpc/data_loader_request.rs index 1f49188d6f2..7ee4bba124b 100644 --- a/src/core/grpc/data_loader_request.rs +++ b/src/core/grpc/data_loader_request.rs @@ -74,6 +74,7 @@ mod tests { type_of: LinkType::Protobuf, headers: None, meta: None, + proto_paths: None, }]); let method = GrpcMethod { package: "greetings".to_string(), diff --git a/src/core/grpc/protobuf.rs b/src/core/grpc/protobuf.rs index 979b7afb2fc..6332bf9bf8a 100644 --- a/src/core/grpc/protobuf.rs +++ b/src/core/grpc/protobuf.rs @@ -268,6 +268,7 @@ pub mod tests { type_of: LinkType::Protobuf, headers: None, meta: None, + proto_paths: 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 b1cb5653e4a..4643c5965f3 100644 --- a/src/core/grpc/request_template.rs +++ b/src/core/grpc/request_template.rs @@ -160,6 +160,7 @@ mod tests { type_of: LinkType::Protobuf, headers: None, meta: None, + proto_paths: None, }]); let method = GrpcMethod { package: id.to_string(),