Skip to content

Commit

Permalink
#57
Browse files Browse the repository at this point in the history
manually setup a client to see what needs to be generated
  • Loading branch information
timostamm committed Jan 30, 2021
1 parent 78c35bb commit f41e78e
Show file tree
Hide file tree
Showing 9 changed files with 1,198 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/example-node-grpc-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
27 changes: 27 additions & 0 deletions packages/example-node-grpc-client/Makefile
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

60 changes: 60 additions & 0 deletions packages/example-node-grpc-client/client.ts
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());

Loading

0 comments on commit f41e78e

Please sign in to comment.