Skip to content

Commit

Permalink
fix(executor-http): improve the fetch signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 31, 2023
1 parent d1a0b7c commit cecf4c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-snakes-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/executor-http': patch
---

Fix fetch signature
10 changes: 8 additions & 2 deletions packages/executors/http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export type AsyncFetchFn = (
options?: RequestInit,
context?: any,
info?: GraphQLResolveInfo
) => Promise<Response>;
) => Promise<Response> | Response;

export type FetchFn = AsyncFetchFn | SyncFetchFn;
export type RegularFetchFn = (url: string) => Promise<Response> | Response;

export type FetchFn = AsyncFetchFn | SyncFetchFn | RegularFetchFn;

export type AsyncImportFn = (moduleName: string) => PromiseLike<any>;
export type SyncImportFn = (moduleName: string) => any;
Expand Down Expand Up @@ -74,6 +76,10 @@ export function buildHTTPExecutor(
options?: Omit<HTTPExecutorOptions, 'fetch'> & { fetch: AsyncFetchFn }
): AsyncExecutor<any, HTTPExecutorOptions>;

export function buildHTTPExecutor(
options?: Omit<HTTPExecutorOptions, 'fetch'> & { fetch: RegularFetchFn }
): AsyncExecutor<any, HTTPExecutorOptions>;

export function buildHTTPExecutor(
options?: Omit<HTTPExecutorOptions, 'fetch'>
): AsyncExecutor<any, HTTPExecutorOptions>;
Expand Down
2 changes: 1 addition & 1 deletion packages/executors/http/tests/buildHTTPExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('buildHTTPExecutor', () => {
it('method should be POST for mutations even if useGETForQueries=true', async () => {
const executor = buildHTTPExecutor({
useGETForQueries: true,
async fetch(_url, init) {
fetch(_url, init) {
return new Response(JSON.stringify({ data: init }), {
headers: { 'Content-Type': 'application/json' },
});
Expand Down

0 comments on commit cecf4c9

Please sign in to comment.