-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manually setup a client to see what needs to be generated
- Loading branch information
Showing
9 changed files
with
1,198 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
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,27 @@ | ||
.PHONY: default npm-install generate run-client | ||
|
||
|
||
default: npm-install run-client | ||
#default: npm-install generate run-client | ||
|
||
npm-install: | ||
npm i | ||
|
||
#generate: | ||
# npx protoc -I . --ts_out . --ts_opt client_none,generate_dependencies,optimize_code_size service-example.proto | ||
|
||
run-client: | ||
npx ts-node client.ts | ||
|
||
|
||
fix-build: | ||
# the packages grpc-backend, grpc-transport and this package all use @grpc/grpc-js, | ||
# and all of them are installed separately, which breaks the code. | ||
# lerna does not link them without hoisting. | ||
# because we don't know what else hoisting will break, we use the following workaround | ||
# and link manually. | ||
rm -rf ../grpc-backend/node_modules/@grpc/grpc-js | ||
rm -rf ../grpc-transport/node_modules/@grpc/grpc-js | ||
ln -s -f ../../../example-node-grpc-transport-client/node_modules/@grpc/grpc-js ../grpc-backend/node_modules/@grpc/grpc-js | ||
ln -s -f ../../../example-node-grpc-transport-client/node_modules/@grpc/grpc-js ../grpc-transport/node_modules/@grpc/grpc-js | ||
|
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,60 @@ | ||
import {ChannelCredentials} from "@grpc/grpc-js"; | ||
import {FailRequest} from "./service-example"; | ||
import {ExampleServiceClient} from "./todo-generate"; | ||
|
||
|
||
const client = new ExampleServiceClient( | ||
"localhost:5000", | ||
ChannelCredentials.createInsecure(), | ||
{}, | ||
{} | ||
); | ||
|
||
|
||
async function main() { | ||
|
||
await callUnary(client); | ||
|
||
// await callServerStream(client); | ||
// | ||
// await callClientStream(client); | ||
// | ||
// await callBidi(client); | ||
|
||
} | ||
|
||
|
||
async function callUnary(client: ExampleServiceClient) { | ||
|
||
console.log(`### calling method "unary"...`) | ||
|
||
const call = client.unary({ | ||
question: 'whats up?', | ||
pleaseDelayResponseMs: 50, | ||
pleaseFail: FailRequest.FAIL_REQUEST_NONE, | ||
disableSendingExampleResponseHeaders: false, | ||
}, (err, value) => { | ||
if (err) { | ||
console.log("got err: ", err) | ||
} | ||
if (value) { | ||
console.log("got response message: ", value) | ||
} | ||
}); | ||
|
||
call.on('metadata', arg1 => { | ||
console.log("got response headers: ", arg1) | ||
}); | ||
|
||
call.on('status', arg1 => { | ||
console.log("got status: ", arg1) | ||
}); | ||
|
||
return new Promise(resolve => { | ||
call.on('status', () => resolve()); | ||
}); | ||
} | ||
|
||
|
||
main().catch(e => console.error(e)).finally(() => process.exit()); | ||
|
Oops, something went wrong.