Skip to content

Commit d8d3541

Browse files
Merge branch 'master' into patch-1
2 parents 95b74ac + 49d3b70 commit d8d3541

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ typings file will also be generated for the protobuf messages and service stub.
104104
in TypeScript. See **TypeScript Support** below for information on how to
105105
generate TypeScript files.
106106

107-
**Note: The `commonjs+dts` and `typescript` styles are only supported by
108-
`--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`.**
107+
> **Note:** The `commonjs+dts` and `typescript` styles are only supported by
108+
`--grpc-web_out=import_style=...`, not by `--js_out=import_style=...`.
109109

110110
### Wire Format Mode
111111

@@ -294,9 +294,14 @@ call.on('status', (status: grpcWeb.Status) => {
294294

295295
### (Option) Using Promises (Limited features)
296296

297-
NOTE: It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used.
297+
> **NOTE:** It is not possible to access the `.on(...)` callbacks (e.g. for `metadata` and `status`) when Promise is used.
298298
299299
```ts
300+
// Create a Promise client instead
301+
const echoService = new EchoServicePromiseClient('http://localhost:8080', null, null);
302+
303+
... (same as above)
304+
300305
this.echoService.echo(request, {'custom-header-1': 'value1'})
301306
.then((response: EchoResponse) => {
302307
console.log(`Received response: ${response.getMessage()}`);
@@ -308,6 +313,18 @@ this.echoService.echo(request, {'custom-header-1': 'value1'})
308313
For the full TypeScript example, see
309314
[ts-example/client.ts](net/grpc/gateway/examples/echo/ts-example/client.ts) with the [instructions](net/grpc/gateway/examples/echo/ts-example) to run.
310315

316+
## Custom Interceptors
317+
318+
Custom interceptors can be implemented and chained, which could be useful for features like auth, retries, etc.
319+
320+
There are 2 types of interceptors ([interfaces](https://github.com/grpc/grpc-web/blob/3cd7e0d43493d4694fed78400e4ad78031d70c09/packages/grpc-web/index.d.ts#L55-L65)):
321+
322+
- `UnaryInterceptor` ([doc](https://grpc.io/blog/grpc-web-interceptor/#stream-interceptor-example), [example](https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/test/tsc-tests/client04.ts)) - Intercept Unary RPCs; can only be used with Promise clients.
323+
- `StreamInterceptor` ([doc](https://grpc.io/blog/grpc-web-interceptor/#stream-interceptor-example), [example](https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/test/tsc-tests/client03.ts)) - More versatile; can be used with regular clients.
324+
325+
For more details, see [this blog post](https://grpc.io/blog/grpc-web-interceptor/).
326+
327+
311328
## Ecosystem
312329

313330
### Proxy Interoperability

javascript/net/grpc/web/generator/grpc_generator.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,11 +940,12 @@ void PrintProtoDtsFile(Printer* printer, const FileDescriptor* file) {
940940
printer->Print("import * as jspb from 'google-protobuf'\n\n");
941941

942942
for (int i = 0; i < file->dependency_count(); i++) {
943-
const string& name = file->dependency(i)->name();
943+
const string& proto_filename = file->dependency(i)->name();
944944
// We need to give each cross-file import an alias.
945-
printer->Print("import * as $alias$ from '$dep_filename$_pb';\n", "alias",
946-
ModuleAlias(name), "dep_filename",
947-
GetRootPath(file->name(), name) + StripProto(name));
945+
printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n",
946+
"alias", ModuleAlias(proto_filename),
947+
"dep_filename", GetRootPath(file->name(), proto_filename) + StripProto(proto_filename),
948+
"proto_filename", proto_filename);
948949
}
949950
printer->Print("\n\n");
950951

0 commit comments

Comments
 (0)