-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(grpc): linking multiple proto files with the same package name
- Loading branch information
Showing
12 changed files
with
232 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Grpc when multiple proto files have the same package name | ||
|
||
```protobuf @file:errors.proto | ||
syntax = "proto3"; | ||
package news; | ||
// The error message definition. | ||
message ErrValidation { | ||
string error = 1; | ||
} | ||
``` | ||
|
||
```protobuf @file:news.proto | ||
syntax = "proto3"; | ||
import "google/protobuf/empty.proto"; | ||
package news; | ||
message News { | ||
int32 id = 1; | ||
string title = 2; | ||
string body = 3; | ||
string postImage = 4; | ||
} | ||
service NewsService { | ||
rpc GetAllNews (google.protobuf.Empty) returns (NewsList) {} | ||
rpc GetNews (NewsId) returns (News) {} | ||
rpc GetMultipleNews (MultipleNewsId) returns (NewsList) {} | ||
rpc DeleteNews (NewsId) returns (google.protobuf.Empty) {} | ||
rpc EditNews (News) returns (News) {} | ||
rpc AddNews (News) returns (News) {} | ||
} | ||
message NewsId { | ||
int32 id = 1; | ||
} | ||
message MultipleNewsId { | ||
repeated NewsId ids = 1; | ||
} | ||
message NewsList { | ||
repeated News news = 1; | ||
} | ||
``` | ||
|
||
```graphql @server | ||
schema | ||
@server(port: 8000, graphiql: true) | ||
@upstream(httpCache: true, batch: {delay: 10}) | ||
@link(id: "errors", src: "errors.proto", type: Protobuf) | ||
@link(id: "news", src: "news.proto", type: Protobuf) { | ||
query: Query | ||
} | ||
|
||
type Query { | ||
news: NewsData! @grpc(method: "news.NewsService.GetAllNews", baseURL: "http://localhost:50051") | ||
newsById(news: NewsInput!): News! | ||
@grpc(method: "news.NewsService.GetNews", baseURL: "http://localhost:50051", body: "{{args.news}}") | ||
} | ||
input NewsInput { | ||
id: Int | ||
title: String | ||
body: String | ||
postImage: String | ||
} | ||
type NewsData { | ||
news: [News]! | ||
} | ||
|
||
type News { | ||
id: Int | ||
title: String | ||
body: String | ||
postImage: String | ||
} | ||
``` | ||
|
||
```yml @mock | ||
- request: | ||
method: POST | ||
url: http://localhost:50051/news.NewsService/GetAllNews | ||
body: null | ||
response: | ||
status: 200 | ||
body: \0\0\0\0t\n#\x08\x01\x12\x06Note 1\x1a\tContent 1\"\x0cPost image 1\n#\x08\x02\x12\x06Note 2\x1a\tContent 2\"\x0cPost image 2 | ||
``` | ||
|
||
```yml @assert | ||
- method: POST | ||
url: http://localhost:8080/graphql | ||
body: | ||
query: query { news {news{ id }} } | ||
``` |
24 changes: 24 additions & 0 deletions
24
tests/snapshots/execution_spec__grpc-proto-with-same-package.md_assert_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
source: tests/execution_spec.rs | ||
expression: response | ||
--- | ||
{ | ||
"status": 200, | ||
"headers": { | ||
"content-type": "application/json" | ||
}, | ||
"body": { | ||
"data": { | ||
"news": { | ||
"news": [ | ||
{ | ||
"id": 1 | ||
}, | ||
{ | ||
"id": 2 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/snapshots/execution_spec__grpc-proto-with-same-package.md_client.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
source: tests/execution_spec.rs | ||
expression: client | ||
--- | ||
scalar Date | ||
|
||
scalar Email | ||
|
||
scalar Empty | ||
|
||
scalar JSON | ||
|
||
type News { | ||
body: String | ||
id: Int | ||
postImage: String | ||
title: String | ||
} | ||
|
||
type NewsData { | ||
news: [News]! | ||
} | ||
|
||
input NewsInput { | ||
body: String | ||
id: Int | ||
postImage: String | ||
title: String | ||
} | ||
|
||
scalar PhoneNumber | ||
|
||
type Query { | ||
news: NewsData! | ||
newsById(news: NewsInput!): News! | ||
} | ||
|
||
scalar Url | ||
|
||
schema { | ||
query: Query | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/snapshots/execution_spec__grpc-proto-with-same-package.md_merged.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
source: tests/execution_spec.rs | ||
expression: merged | ||
--- | ||
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "errors", src: "errors.proto", type: Protobuf) @link(id: "news", src: "news.proto", type: Protobuf) { | ||
query: Query | ||
} | ||
|
||
input NewsInput { | ||
body: String | ||
id: Int | ||
postImage: String | ||
title: String | ||
} | ||
|
||
type News { | ||
body: String | ||
id: Int | ||
postImage: String | ||
title: String | ||
} | ||
|
||
type NewsData { | ||
news: [News]! | ||
} | ||
|
||
type Query { | ||
news: NewsData! @grpc(baseURL: "http://localhost:50051", method: "news.NewsService.GetAllNews") | ||
newsById(news: NewsInput!): News! @grpc(baseURL: "http://localhost:50051", body: "{{args.news}}", method: "news.NewsService.GetNews") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters