Skip to content

Commit

Permalink
useGETForQueries was also activating GET for mutations (#4885)
Browse files Browse the repository at this point in the history
* useGETForQueries was also activating GET for mutations

* Added test: should be a GET operation when useGETForQueries=true

* Added test: should be a GET operation when useGETForQueries=true
  • Loading branch information
paales authored Dec 8, 2022
1 parent 5927768 commit 969e264
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/four-icons-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/executor-http': patch
---

useGETForQueries was also activating GET for mutations
2 changes: 1 addition & 1 deletion packages/executors/http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function buildHTTPExecutor(options?: HTTPExecutorOptions): Executor<any,
const operationAst = getOperationASTFromRequest(request);
const operationType = operationAst.operation;

if (options?.useGETForQueries || (request.extensions?.useGETForQueries && operationType === 'query')) {
if ((options?.useGETForQueries || request.extensions?.useGETForQueries) && operationType === 'query') {
method = 'GET';
}

Expand Down
29 changes: 29 additions & 0 deletions packages/executors/http/tests/buildHTTPExecutor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { parse } from 'graphql';
import { buildHTTPExecutor, SyncFetchFn } from '../src/index.js';

describe('buildHTTPExecutor', () => {
it('should be a GET operation when useGETForQueries=true', async () => {
const syncFetch: SyncFetchFn = (input, init) => {
return {
...new Response(),
url: input,
headers: new Headers(init?.headers),
text: () => JSON.stringify({ data: init }),
};
};

const executor = buildHTTPExecutor({
useGETForQueries: true,
fetch: syncFetch,
});

const mutation = parse(/* GraphQL */ `
mutation {
doSomething
}
`);

const res = executor({ document: mutation });
expect(res.data.method).toBe('POST');
});
});

0 comments on commit 969e264

Please sign in to comment.