Skip to content

Commit

Permalink
Merge pull request #164 from julianbenegas/master
Browse files Browse the repository at this point in the history
fix weird turbopack behavior
  • Loading branch information
remorses authored Feb 2, 2024
2 parents a6fd508 + 4a1ce7b commit ad22096
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions cli/src/runtime/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,32 @@ export const createFetcher = ({
if (!url && !fetcher) {
throw new Error('url or fetcher is required')
}
if (!fetcher) {
fetcher = async (body) => {
let headersObject =
typeof headers == 'function' ? await headers() : headers
headersObject = headersObject || {}
if (typeof fetch === 'undefined' && !_fetch) {
throw new Error(
'Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`',
)
}
let fetchImpl = _fetch || fetch
const res = await fetchImpl(url!, {
headers: {
'Content-Type': 'application/json',
...headersObject,
},
method: 'POST',
body: JSON.stringify(body),
...rest,
})
if (!res.ok) {
throw new Error(`${res.statusText}: ${await res.text()}`)
}
const json = await res.json()
return json

fetcher = fetcher || (async (body) => {
let headersObject =
typeof headers == 'function' ? await headers() : headers
headersObject = headersObject || {}
if (typeof fetch === 'undefined' && !_fetch) {
throw new Error(
'Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`',
)
}
}
let fetchImpl = _fetch || fetch
const res = await fetchImpl(url!, {
headers: {
'Content-Type': 'application/json',
...headersObject,
},
method: 'POST',
body: JSON.stringify(body),
...rest,
})
if (!res.ok) {
throw new Error(`${res.statusText}: ${await res.text()}`)
}
const json = await res.json()
return json
})

if (!batch) {
return async (body) => {
Expand Down

0 comments on commit ad22096

Please sign in to comment.