Skip to content

Commit

Permalink
Rest directive: don't send body for GET (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleF83 authored Mar 20, 2021
1 parent 58cba31 commit ec44701
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions services/src/modules/directives/rest/datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions services/src/modules/directives/rest/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class RESTDirectiveDataSource extends RESTDataSource<RequestContext> {
}

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');
Expand Down

0 comments on commit ec44701

Please sign in to comment.