Skip to content

Commit

Permalink
feat: link config support proto paths
Browse files Browse the repository at this point in the history
  • Loading branch information
DLillard0 committed Dec 16, 2024
1 parent 76fc565 commit e6ea273
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/core/config/directives/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ pub struct Link {
/// Additional metadata pertaining to the linked resource.
#[serde(default, skip_serializing_if = "is_default")]
pub meta: Option<serde_json::Value>,
///
/// 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<Vec<String>>,
}
8 changes: 7 additions & 1 deletion src/core/config/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()

Check warning on line 86 in src/core/config/reader.rs

View check run for this annotation

Codecov / codecov/patch

src/core/config/reader.rs#L83-L86

Added lines #L83 - L86 were not covered by tests
});
let meta = self.proto_reader.read(path, proto_paths.as_deref()).await?;
extensions.add_proto(meta);
}
LinkType::Script => {
Expand Down
1 change: 1 addition & 0 deletions src/core/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Generator {
type_of: LinkType::Protobuf,
headers: None,
meta: None,
proto_paths: None,
});
Ok(config)
}
Expand Down
1 change: 1 addition & 0 deletions src/core/grpc/data_loader_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod tests {
type_of: LinkType::Protobuf,
headers: None,
meta: None,
proto_paths: None,
}]);
let method = GrpcMethod {
package: "greetings".to_string(),
Expand Down
1 change: 1 addition & 0 deletions src/core/grpc/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down
1 change: 1 addition & 0 deletions src/core/grpc/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ mod tests {
type_of: LinkType::Protobuf,
headers: None,
meta: None,
proto_paths: None,
}]);
let method = GrpcMethod {
package: id.to_string(),
Expand Down

0 comments on commit e6ea273

Please sign in to comment.