Skip to content

Commit 34f4a84

Browse files
Merge pull request nestjs#2805 from Reasno/proxy-fix
bugfix(microservices) pass all arguments to request-scoped proxies
2 parents 311265f + 67a9b28 commit 34f4a84

14 files changed

Lines changed: 60 additions & 27 deletions

File tree

integration/graphql/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@nestjs/core": "6.5.3",
1414
"@nestjs/graphql": "6.4.2",
1515
"apollo-server-express": "2.8.1",
16-
"graphql": "14.5.0",
16+
"graphql": "14.5.1",
1717
"graphql-tools": "4.0.5",
1818
"reflect-metadata": "0.1.13",
1919
"rxjs": "6.5.2",

integration/typegraphql/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/typegraphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"apollo-server-express": "2.8.1",
1616
"class-transformer": "0.2.3",
1717
"class-validator": "0.10.0",
18-
"graphql": "14.5.0",
18+
"graphql": "14.5.1",
1919
"graphql-tools": "4.0.5",
2020
"reflect-metadata": "0.1.13",
2121
"rxjs": "6.5.2",

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"fastify-cors": "2.1.3",
5757
"fastify-formbody": "3.1.0",
5858
"fastify-multipart": "1.0.2",
59-
"graphql": "14.5.0",
59+
"graphql": "14.5.1",
6060
"grpc": "1.23.3",
6161
"http2": "3.3.7",
6262
"iterare": "1.2.0",

packages/microservices/listeners-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class ListenersController {
118118
contextId,
119119
wrapper.id,
120120
);
121-
return proxy(data);
121+
return proxy(...args);
122122
} catch (err) {
123123
let exceptionFilter = this.exceptionFiltersCache.get(
124124
instance[methodKey],

packages/microservices/test/listeners-controller.spec.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ describe('ListenersController', () => {
2020
metadataExplorer: ListenerMetadataExplorer,
2121
server: any,
2222
addSpy: sinon.SinonSpy,
23+
proxySpy: sinon.SinonSpy,
2324
container: NestContainer,
2425
injector: Injector,
26+
rpcContextCreator: RpcContextCreator,
2527
exceptionFiltersContext: ExceptionFiltersContext;
2628

2729
before(() => {
@@ -35,9 +37,12 @@ describe('ListenersController', () => {
3537
container,
3638
new ApplicationConfig(),
3739
);
40+
rpcContextCreator = sinon.createStubInstance(RpcContextCreator) as any;
41+
proxySpy = sinon.spy();
42+
(rpcContextCreator as any).create.callsFake(()=>proxySpy);
3843
instance = new ListenersController(
3944
new ClientsContainer(),
40-
sinon.createStubInstance(RpcContextCreator) as any,
45+
rpcContextCreator,
4146
container,
4247
injector,
4348
ClientProxyFactory,
@@ -81,16 +86,41 @@ describe('ListenersController', () => {
8186
let handleSpy: sinon.SinonSpy;
8287

8388
beforeEach(() => {
84-
sinon.stub(injector, 'loadPerContext').callsFake(() => {
85-
throw new Error();
86-
});
8789
handleSpy = sinon.spy();
8890
sinon.stub(exceptionFiltersContext, 'create').callsFake(
8991
() =>
9092
({
9193
handle: handleSpy,
9294
} as any),
9395
);
96+
97+
sinon.stub((instance as any), 'registerRequestProvider').callsFake(() => ({} as any));
98+
});
99+
100+
describe('when "loadPerContext" resolves', () => {
101+
const moduleKey = 'moduleKey';
102+
const methodKey = 'methodKey';
103+
const module = {
104+
controllers: new Map(),
105+
} as any;
106+
const pattern = {};
107+
const wrapper = new InstanceWrapper({ instance: { [methodKey]: {} } });
108+
109+
it('should pass all arguments to the proxy chain', async () => {
110+
sinon.stub(injector, 'loadPerContext').callsFake(() => Promise.resolve({}));
111+
const handler = instance.createRequestScopedHandler(
112+
wrapper,
113+
pattern,
114+
module,
115+
moduleKey,
116+
methodKey,
117+
);
118+
await handler("data", "metadata");
119+
120+
expect(proxySpy.called).to.be.true;
121+
expect(proxySpy.getCall(0).args[0]).to.be.eql("data");
122+
expect(proxySpy.getCall(0).args[1]).to.be.eql("metadata");
123+
});
94124
});
95125

96126
describe('when "loadPerContext" throws', () => {
@@ -103,6 +133,9 @@ describe('ListenersController', () => {
103133
const wrapper = new InstanceWrapper({ instance: { [methodKey]: {} } });
104134

105135
it('should delegete error to exception filters', async () => {
136+
sinon.stub(injector, 'loadPerContext').callsFake(() => {
137+
throw new Error();
138+
});
106139
const handler = instance.createRequestScopedHandler(
107140
wrapper,
108141
pattern,

sample/12-graphql-apollo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"apollo-server-express": "2.8.1",
1818
"class-transformer": "0.2.3",
1919
"class-validator": "0.10.0",
20-
"graphql": "14.5.0",
20+
"graphql": "14.5.1",
2121
"graphql-subscriptions": "1.1.0",
2222
"reflect-metadata": "0.1.13",
2323
"rxjs": "6.5.2",

sample/13-mongo-typeorm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@nestjs/core": "6.5.3",
1515
"@nestjs/platform-express": "6.5.3",
1616
"@nestjs/typeorm": "6.1.3",
17-
"mongodb": "3.2.7",
17+
"mongodb": "3.3.1",
1818
"reflect-metadata": "0.1.13",
1919
"rxjs": "6.5.2",
2020
"typeorm": "0.2.18",

0 commit comments

Comments
 (0)