Skip to content

Commit

Permalink
enhance(transport-rest): use the default fetch if no fetch exists in …
Browse files Browse the repository at this point in the history
…the transport context (#8351)
  • Loading branch information
ardatan authored Jan 31, 2025
1 parent 93b17fe commit 0b6ee9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-crabs-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/transport-rest': patch
---

Use `@whatwg-node/fetch` when the transport context doesn't have one
7 changes: 2 additions & 5 deletions packages/transports/rest/src/directives/httpOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
import type { Logger, MeshFetch, MeshFetchRequestInit } from '@graphql-mesh/types';
import { DefaultLogger, getHeadersObj } from '@graphql-mesh/utils';
import { createGraphQLError, memoize1 } from '@graphql-tools/utils';
import { Blob, File, FormData, URLSearchParams } from '@whatwg-node/fetch';
import { Blob, fetch as defaultFetch, File, FormData, URLSearchParams } from '@whatwg-node/fetch';
import { isFileUpload } from './isFileUpload.js';
import { getJsonApiFieldsQuery } from './jsonApiFields.js';
import { resolveDataByUnionInputType } from './resolveDataByUnionInputType.js';
Expand Down Expand Up @@ -296,10 +296,7 @@ export function addHTTPRootFieldResolver(
}

operationLogger.debug(`=> Fetching `, fullPath, `=>`, requestInit);
const fetch: typeof globalFetch = context?.fetch || globalFetch;
if (!fetch) {
return new TypeError(`You should have fetch defined in either the config or the context!`);
}
const fetch: typeof globalFetch = context?.fetch || globalFetch || defaultFetch;
// Trick to pass `sourceName` to the `fetch` function for tracing
const response = await fetch(fullPath, requestInit, context, {
...info,
Expand Down

0 comments on commit 0b6ee9c

Please sign in to comment.