Skip to content

Commit

Permalink
chore(link): add meta support
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Sep 15, 2024
1 parent d02b6e6 commit 4314363
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 0 deletions.
4 changes: 4 additions & 0 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
3 changes: 3 additions & 0 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/core/config/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<serde_json::Value>,
}
1 change: 1 addition & 0 deletions src/core/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl Generator {
id: None,
src: metadata.path.to_owned(),
type_of: LinkType::Protobuf,
meta: 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 @@ -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(),
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 @@ -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() };
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 {
id: Some(id.clone()),
src: test_file.to_string(),
type_of: LinkType::Protobuf,
meta: None,
}]);
let method = GrpcMethod {
package: id.to_string(),
Expand Down
55 changes: 55 additions & 0 deletions tests/core/snapshots/test-link-support.md_client.snap
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions tests/core/snapshots/test-link-support.md_merged.snap
Original file line number Diff line number Diff line change
@@ -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")
}
50 changes: 50 additions & 0 deletions tests/execution/test-link-support.md
Original file line number Diff line number Diff line change
@@ -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")
}
```

0 comments on commit 4314363

Please sign in to comment.