diff --git a/.changeset/tall-eggs-remain.md b/.changeset/tall-eggs-remain.md new file mode 100644 index 000000000..3b746b932 --- /dev/null +++ b/.changeset/tall-eggs-remain.md @@ -0,0 +1,5 @@ +--- +'@farfetched/core': patch +--- + +Add missed header Accept in `createJsonQuery`/`createJsonMutation` diff --git a/packages/core/src/fetch/__tests__/json.request.headers.test.ts b/packages/core/src/fetch/__tests__/json.request.headers.test.ts index 14fca1fc5..54fd60e29 100644 --- a/packages/core/src/fetch/__tests__/json.request.headers.test.ts +++ b/packages/core/src/fetch/__tests__/json.request.headers.test.ts @@ -27,6 +27,7 @@ describe('fetch/json.request.headers', () => { expect(fetchMock.mock.calls[0][0].headers).toEqual( new Headers({ + Accept: 'application/json', 'content-type': 'application/json', }) ); @@ -46,6 +47,8 @@ describe('fetch/json.request.headers', () => { params: {}, }); - expect(fetchMock.mock.calls[0][0].headers).toEqual(new Headers({})); + expect(fetchMock.mock.calls[0][0].headers).toEqual( + new Headers({ Accept: 'application/json' }) + ); }); }); diff --git a/packages/core/src/fetch/json.ts b/packages/core/src/fetch/json.ts index 20b103e7c..51641ccf9 100644 --- a/packages/core/src/fetch/json.ts +++ b/packages/core/src/fetch/json.ts @@ -40,11 +40,16 @@ export function createJsonApiRequest( headers: normalizeStaticOrReactive(config.request.headers), }, ({ method, headers }) => - ['GET', 'HEAD'].includes(method!) // TODO: fix type inferences - ? headers - : mergeRecords(headers, { - 'Content-Type': 'application/json', - }) + // reversed merge order to allow any modifications in the user code + mergeRecords( + { + Accept: 'application/json', + 'Content-Type': ['GET', 'HEAD'].includes(method) + ? undefined + : 'application/json', + }, + headers + ) ); const jsonApiCallFx = createApiRequest<