From ec447017905d51c42d29f9695cec6a4d0bfbc67e Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 20 Mar 2021 23:52:27 +0200 Subject: [PATCH] Rest directive: don't send body for GET (#307) --- .../src/modules/directives/rest/datasource.spec.ts | 12 ++++++++++++ services/src/modules/directives/rest/datasource.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/services/src/modules/directives/rest/datasource.spec.ts b/services/src/modules/directives/rest/datasource.spec.ts index 97332d19..b8fa3dac 100644 --- a/services/src/modules/directives/rest/datasource.spec.ts +++ b/services/src/modules/directives/rest/datasource.spec.ts @@ -247,6 +247,18 @@ const testCases: [string, TestCase][] = [ fieldResolverParams: {}, }, ], + [ + 'GET with arg named "input"', + { + setup: () => nock(remoteHost).get('/').reply(200, remoteHostResponse), + restParams: {}, + fieldResolverParams: { + args: { + input: '1', + }, + }, + }, + ], ]; const emptyContext = { diff --git a/services/src/modules/directives/rest/datasource.ts b/services/src/modules/directives/rest/datasource.ts index 1f5448ae..5f698307 100644 --- a/services/src/modules/directives/rest/datasource.ts +++ b/services/src/modules/directives/rest/datasource.ts @@ -45,6 +45,9 @@ export class RESTDirectiveDataSource extends RESTDataSource { } private setBody(requestParams: RequestParams, params: RestParams, fieldResolverParams: FieldResolverParams) { + if (!requestParams.method || ['GET', 'HEAD'].includes(requestParams.method.toUpperCase())) { + return; + } const { body: bodyObj, bodyArg } = params; if (bodyObj && bodyArg) { throw new Error('Set either "body" or "bodyArg" argument but not both');