From 392851497c50bdefb020a65b414a23bb905b2cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 31 Jan 2025 15:09:53 +0100 Subject: [PATCH 1/2] fix(migrate): always use raw perspective for migrations perspective=raw is currently default for all current API versions, but that might not be true in for all future versions. For migrations, perspective=raw is the most sensible default, so this PR explicitly sets perspective=raw when fetching documents for migration. If there's a compelling use case for having user-provided perspectives, we can always consider adding support for that that later, but this change ensures that perspective=raw is always used, no matter what the default is backend side. --- packages/@sanity/migrate/src/fetch-utils/endpoints.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@sanity/migrate/src/fetch-utils/endpoints.ts b/packages/@sanity/migrate/src/fetch-utils/endpoints.ts index c5fa7713a5f..345278a1c0b 100644 --- a/packages/@sanity/migrate/src/fetch-utils/endpoints.ts +++ b/packages/@sanity/migrate/src/fetch-utils/endpoints.ts @@ -20,7 +20,7 @@ export const endpoints = { global: false, method: 'GET', path: `/query/${dataset}`, - searchParams: [], + searchParams: [['perspective', 'raw']], }), export: (dataset: string, documentTypes?: string[]): Endpoint => ({ global: false, From 82f303328b4221701969f153ea65bef5d5a6657f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 31 Jan 2025 15:31:35 +0100 Subject: [PATCH 2/2] chore(test): add test for explicit perspective=raw --- .../__test__/sanityRequestOptions.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packages/@sanity/migrate/src/fetch-utils/__test__/sanityRequestOptions.test.ts diff --git a/packages/@sanity/migrate/src/fetch-utils/__test__/sanityRequestOptions.test.ts b/packages/@sanity/migrate/src/fetch-utils/__test__/sanityRequestOptions.test.ts new file mode 100644 index 00000000000..077a988c8e6 --- /dev/null +++ b/packages/@sanity/migrate/src/fetch-utils/__test__/sanityRequestOptions.test.ts @@ -0,0 +1,24 @@ +import {expect, test} from 'vitest' + +import {endpoints} from '../endpoints' +import {toFetchOptions} from '../sanityRequestOptions' + +test('toFetchOptions', () => { + expect( + toFetchOptions({ + projectId: 'xyz', + apiVersion: 'v2025-01-31', + apiHost: 'api.sanity.io', + endpoint: endpoints.data.query('my-dataset'), + }), + ).toEqual({ + init: { + headers: { + 'Content-Type': 'application/json', + 'User-Agent': '@sanity/migrate@3.72.1', + }, + method: 'GET', + }, + url: 'https://xyz.api.sanity.io//v2025-01-31/query/my-dataset?perspective=raw', + }) +})