Skip to content

Commit

Permalink
refactor: Switch to @grpc/grpc-js altogether. Bump to nestjs v8. (#401)
Browse files Browse the repository at this point in the history
* Remove grpc in integrations as well. Bump to nestjs v8.

grpc is deprecated and the authors recommend to use @grpc/grpc-js instead.
While ts-proto does that almost everywhere, it still needed grpc for the
nestjs integration tests.

Since nestjs switched to v8, it uses @grpc/grpc-js as well, so bump to
nestjs v8. This also requires rxjs v7+.

* Change port number for nestjs-simple-restparameters test.

For me, it occassionally failed when running it together with the nestjs-simple
test, perhaps because the two shared a port number -- they never failed when running
them simultaneously. Perhaps there is some changed behaviour between nestjs 7 and 8?

* Fix test code on node 12.
  • Loading branch information
sgielen authored Nov 22, 2021
1 parent 32a17a6 commit c2e6f81
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 342 deletions.
2 changes: 1 addition & 1 deletion integration/nestjs-metadata-grpc-js/sample-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeroServiceController, HeroById, Hero, Villain, VillainById } from './hero';
import { Metadata } from 'grpc';
import { Metadata } from '@grpc/grpc-js';
import { Observable, Subject } from 'rxjs';

export class SampleService implements HeroServiceController {
Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-metadata-observables/sample-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HeroServiceController, HeroById, Hero, Villain, VillainById } from './hero';
import { Observable, of, Subject } from 'rxjs';
import { Metadata } from 'grpc';
import { Metadata } from '@grpc/grpc-js';

export class SampleService implements HeroServiceController {
findOneHero(request: HeroById, metadata?: Metadata): Observable<Hero> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeroServiceController, HeroById, Hero, Villain, VillainById } from './hero';
import { Metadata } from 'grpc';
import { Metadata } from '@grpc/grpc-js';
import { Observable, Subject } from 'rxjs';

export class SampleService implements HeroServiceController {
Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-metadata/sample-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeroServiceController, HeroById, Hero, Villain, VillainById } from './hero';
import { Metadata } from 'grpc';
import { Metadata } from '@grpc/grpc-js';
import { Observable, Subject } from 'rxjs';

export class SampleService implements HeroServiceController {
Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-restparameters/sample-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HeroServiceController, HeroById, Hero, Villain, VillainById } from './hero';
import { Metadata } from 'grpc';
import { Metadata } from '@grpc/grpc-js';
import { Observable, Subject } from 'rxjs';

export class SampleService implements HeroServiceController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { HERO_PACKAGE_NAME } from '../hero';
name: HERO_PACKAGE_NAME,
transport: Transport.GRPC,
options: {
url: '0.0.0.0:8080',
url: '0.0.0.0:8081',
package: HERO_PACKAGE_NAME,
protoPath: join(__dirname, '../hero.proto'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function createApp() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
transport: Transport.GRPC,
options: {
url: '0.0.0.0:8080',
url: '0.0.0.0:8081',
package: HERO_PACKAGE_NAME,
protoPath: join(__dirname, '../hero.proto'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('nestjs-simple-test nestjs', () => {
app = await createApp();
client = app.get(HERO_PACKAGE_NAME);
heroService = client.getService<HeroServiceClient>(HERO_SERVICE_NAME);
await app.listenAsync();
await app.listen();
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class HeroController implements HeroServiceController {

const onNext = (villainById: VillainById) => {
const item = this.villains.find(({ id }) => id === villainById.id);
hero$.next(item);
hero$.next(item!);
};
const onComplete = () => hero$.complete();
request.subscribe(onNext, null, onComplete);
Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-simple/nestjs-simple-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('nestjs-simple-test nestjs', () => {
app = await createApp();
client = app.get(HERO_PACKAGE_NAME);
heroService = client.getService<HeroServiceClient>(HERO_SERVICE_NAME);
await app.listenAsync();
await app.listen();
});

afterAll(async () => {
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"@grpc/proto-loader": "^0.5.6",
"@improbable-eng/grpc-web": "^0.14.0",
"@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
"@nestjs/common": "^7.6.15",
"@nestjs/core": "^7.6.15",
"@nestjs/microservices": "^7.6.15",
"@nestjs/common": "^8.2.2",
"@nestjs/core": "^8.2.2",
"@nestjs/microservices": "^8.2.2",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
Expand All @@ -36,11 +36,10 @@
"@semantic-release/release-notes-generator": "^9.0.2",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"grpc": "^1.24.6",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.7",
"rxjs": "^7.4.0",
"semantic-release": "^17.4.2",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
Expand Down
Loading

0 comments on commit c2e6f81

Please sign in to comment.