Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: grpc-web issue#239 where client streaming was producing incorr… #335

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified integration/generic-service-definitions/simple.bin
Binary file not shown.
45 changes: 45 additions & 0 deletions integration/grpc-web-client-streaming/client-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node

import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport';
import { DashAPICredsClientImpl, DashStateClientImpl, GrpcWebImpl } from './example';
import { grpc } from '@improbable-eng/grpc-web';

const rpc = new GrpcWebImpl('http://localhost:9090', {
transport: NodeHttpTransport(),
debug: false,
metadata: new grpc.Metadata({ SomeHeader: 'bar' }),
});

const client = new DashStateClientImpl(rpc);
const creds = new DashAPICredsClientImpl(rpc);

async function main() {
console.log('calling client.UserSettings');
console.log(await client.UserSettings({}));

console.log('calling creds.Create');
const cred = await creds.Create({ description: 'test desc fooo' });
console.log(cred);

console.log('calling creds.Delete');
const del = await creds.Delete({ id: cred.id });
console.log(del);

console.log('calling creds.Update');
try {
await creds.Update({ description: 'test desc2' });
} catch (e) {
console.log('got expected error', e.message);
}

const obs = client.ActiveUserSettingsStream({});
await obs.forEach((value) => {
console.log('Got', value);
client.ChangeUserSettingsStream({ id: String(Math.random()) });
});
}

main().then(
() => console.log('done'),
(err) => console.log('failed', err)
);
23 changes: 23 additions & 0 deletions integration/grpc-web-client-streaming/example-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DashStateClientImpl } from './example';

describe('grpc-web', () => {
it('at least compiles', () => {
// TODO move the hand-run `client-ts` integration into here, but for now
// at least check that things compile
const rpc = {
unary: jest.fn(),
invoke: jest.fn(),
};
const client = new DashStateClientImpl(rpc);
client.UserSettings({});
});
it('binds rpc function', () => {
const rpc = {
unary: jest.fn(),
invoke: jest.fn(),
};
const client = new DashStateClientImpl(rpc);
const userSettings = client.UserSettings;
userSettings({});
})
});
Binary file added integration/grpc-web-client-streaming/example.bin
Binary file not shown.
72 changes: 72 additions & 0 deletions integration/grpc-web-client-streaming/example.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
syntax = "proto3";

package rpx;

service DashState {
rpc UserSettings(Empty) returns (DashUserSettingsState);
rpc ActiveUserSettingsStream(Empty) returns (stream DashUserSettingsState);
rpc ChangeUserSettingsStream (stream Cred) returns (stream DashUserSettingsState) {}
}

message DashFlash {
string msg = 1;
Type type = 2;

enum Type {
Undefined = 0;
Success = 1;
Warn = 2;
Error = 3;
}
}

message DashUserSettingsState {
string email = 1;
URLs urls = 6;
repeated DashFlash flashes = 7;

message URLs {
string connect_google = 1;
string connect_github = 2;
}
}


//----------------------
// API Creds
//----------------------
service DashAPICreds {
rpc Create(DashAPICredsCreateReq) returns (DashCred);
rpc Update(DashAPICredsUpdateReq) returns (DashCred);
rpc Delete(DashAPICredsDeleteReq) returns (DashCred);
}

message Cred {
string id = 7;
}

message DashCred {
string description = 2;
string metadata = 3;
string token = 4;
string id = 7;
}

message DashAPICredsCreateReq {
string description = 1;
string metadata = 2;
}

message DashAPICredsUpdateReq {
string cred_sid = 1;
string description = 2;
string metadata = 3;
string id = 5;
}

message DashAPICredsDeleteReq {
string cred_sid = 1;
string id = 3;
}

message Empty {}
Loading