diff --git a/src/SanityClient.ts b/src/SanityClient.ts index 54f09aa8..d6eaf0e7 100644 --- a/src/SanityClient.ts +++ b/src/SanityClient.ts @@ -28,12 +28,14 @@ import type { QueryOptions, QueryParams, QueryWithoutParams, + RawQuerylessQueryResponse, RawQueryResponse, RawRequestOptions, SanityDocument, SanityDocumentStub, SingleMutationResult, UnfilteredResponseQueryOptions, + UnfilteredResponseWithoutQuery, } from './types' import {ObservableUsersClient, UsersClient} from './users/UsersClient' @@ -160,6 +162,18 @@ export class ObservableSanityClient { params: Q extends QueryWithoutParams ? QueryWithoutParams : Q, options: UnfilteredResponseQueryOptions, ): Observable> + /** + * Perform a GROQ-query against the configured dataset. + * + * @param query - GROQ-query to perform + * @param params - Optional query parameters + * @param options - Request options + */ + fetch( + query: string, + params: Q extends QueryWithoutParams ? QueryWithoutParams : Q, + options: UnfilteredResponseWithoutQuery, + ): Observable> fetch( query: string, params?: Q, @@ -799,6 +813,18 @@ export class SanityClient { params: Q extends QueryWithoutParams ? QueryWithoutParams : Q, options: UnfilteredResponseQueryOptions, ): Promise> + /** + * Perform a GROQ-query against the configured dataset. + * + * @param query - GROQ-query to perform + * @param params - Optional query parameters + * @param options - Request options + */ + fetch( + query: string, + params: Q extends QueryWithoutParams ? QueryWithoutParams : Q, + options: UnfilteredResponseWithoutQuery, + ): Promise> fetch(query: string, params?: Q, options?: QueryOptions): Promise | R> { return lastValueFrom( dataMethods._fetch( diff --git a/src/data/dataMethods.ts b/src/data/dataMethods.ts index fa4d6239..29f354af 100644 --- a/src/data/dataMethods.ts +++ b/src/data/dataMethods.ts @@ -80,6 +80,7 @@ export function _fetch( const params = stega.enabled ? vercelStegaCleanAll(_params) : _params const mapResponse = options.filterResponse === false ? (res: Any) => res : (res: Any) => res.result + const {cache, next, ...opts} = { // Opt out of setting a `signal` on an internal `fetch` if one isn't provided. // This is necessary in React Server Components to avoid opting out of Request Memoization. @@ -87,6 +88,9 @@ export function _fetch( // Set `resultSourceMap' when stega is enabled, as it's required for encoding. resultSourceMap: stega.enabled ? 'withKeyArraySelector' : options.resultSourceMap, ...options, + // Default to not returning the query, unless `filterResponse` is `false`, + // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy + returnQuery: options.filterResponse === false && options.returnQuery !== false, } const reqOpts = typeof cache !== 'undefined' || typeof next !== 'undefined' @@ -253,7 +257,7 @@ export function _dataRequest( const useGet = !isMutation && strQuery.length < getQuerySizeLimit const stringQuery = useGet ? strQuery : '' const returnFirst = options.returnFirst - const {timeout, token, tag, headers} = options + const {timeout, token, tag, headers, returnQuery} = options const uri = _getDataUrl(client, endpoint, stringQuery) @@ -267,6 +271,7 @@ export function _dataRequest( headers, token, tag, + returnQuery, perspective: options.perspective, resultSourceMap: options.resultSourceMap, canUseCdn: isQuery, @@ -369,6 +374,10 @@ export function _requestObservable( printCdnPreviewDraftsWarning() } } + + if (options.returnQuery === false) { + options.query = {returnQuery: 'false', ...options.query} + } } const reqOptions = requestOptions( diff --git a/src/data/encodeQueryString.ts b/src/data/encodeQueryString.ts index 3c9711a1..613d8eaf 100644 --- a/src/data/encodeQueryString.ts +++ b/src/data/encodeQueryString.ts @@ -11,7 +11,7 @@ export const encodeQueryString = ({ }) => { const searchParams = new URLSearchParams() // We generally want tag at the start of the query string - const {tag, ...opts} = options + const {tag, returnQuery, ...opts} = options // We're using `append` instead of `set` to support React Native: https://github.com/facebook/react-native/blob/1982c4722fcc51aa87e34cf562672ee4aff540f1/packages/react-native/Libraries/Blob/URL.js#L86-L88 if (tag) searchParams.append('tag', tag) searchParams.append('query', query) @@ -26,5 +26,8 @@ export const encodeQueryString = ({ if (value) searchParams.append(key, `${value}`) } + // `returnQuery` is default `true`, so needs an explicit `false` handling + if (returnQuery === false) searchParams.append('returnQuery', 'false') + return `?${searchParams}` } diff --git a/src/types.ts b/src/types.ts index 169d00b2..d7241bcd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -300,6 +300,7 @@ export interface RequestObservableOptions extends Omit { canUseCdn?: boolean useCdn?: boolean tag?: string + returnQuery?: boolean resultSourceMap?: boolean | 'withKeyArraySelector' perspective?: ClientPerspective } @@ -452,6 +453,8 @@ export interface QueryParams { /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ resultSourceMap?: never /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ + returnQuery?: never + /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ signal?: never /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ stega?: never @@ -721,6 +724,7 @@ export interface ListenOptions { export interface ResponseQueryOptions extends RequestOptions { perspective?: ClientPerspective resultSourceMap?: boolean | 'withKeyArraySelector' + returnQuery?: boolean useCdn?: boolean stega?: boolean | StegaConfig // The `cache` and `next` options are specific to the Next.js App Router integration @@ -736,10 +740,31 @@ export interface FilteredResponseQueryOptions extends ResponseQueryOptions { /** @public */ export interface UnfilteredResponseQueryOptions extends ResponseQueryOptions { filterResponse: false + + /** + * When `filterResponse` is `false`, `returnQuery` also defaults to `true` for + * backwards compatibility (on the client side, not from the content lake API). + * Can also explicitly be set to `true`. + */ + returnQuery?: true +} + +/** + * When using `filterResponse: false`, but you do not wish to receive back the query from + * the content lake API. + * + * @public + */ +export interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions { + filterResponse: false + returnQuery: false } /** @public */ -export type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions +export type QueryOptions = + | FilteredResponseQueryOptions + | UnfilteredResponseQueryOptions + | UnfilteredResponseWithoutQuery /** @public */ export interface RawQueryResponse { @@ -749,6 +774,9 @@ export interface RawQueryResponse { resultSourceMap?: ContentSourceMap } +/** @public */ +export type RawQuerylessQueryResponse = Omit, 'query'> + /** @internal */ export type BaseMutationOptions = RequestOptions & { visibility?: 'sync' | 'async' | 'deferred' diff --git a/test-next/client.test-d.ts b/test-next/client.test-d.ts index 24c43ae0..1fe5e23d 100644 --- a/test-next/client.test-d.ts +++ b/test-next/client.test-d.ts @@ -1,6 +1,12 @@ /// -import {createClient, QueryOptions, QueryParams, RawQueryResponse} from '@sanity/client' +import { + createClient, + type QueryOptions, + type QueryParams, + type RawQuerylessQueryResponse, + type RawQueryResponse, +} from '@sanity/client' import {describe, expectTypeOf, test} from 'vitest' describe('client.fetch', () => { @@ -33,6 +39,13 @@ describe('client.fetch', () => { {filterResponse: false, cache: 'force-cache', next: {revalidate: 60, tags: ['post']}}, ), ).toMatchTypeOf>() + expectTypeOf( + await client.fetch( + '*[_type == $type]', + {type: 'post'}, + {filterResponse: false, returnQuery: false}, + ), + ).toMatchTypeOf>() }) test('generics', async () => { expectTypeOf( diff --git a/test/client.test.ts b/test/client.test.ts index efdaaf72..9da84495 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -508,9 +508,8 @@ describe('client', async () => { const qs = 'beerfiesta.beer%5B.title%20%3D%3D%20%24beerName%5D&%24beerName=%22Headroom%20Double%20IPA%22' - nock(projectHost()).get(`/v1/data/query/foo?query=${qs}`).reply(200, { + nock(projectHost()).get(`/v1/data/query/foo?query=${qs}&returnQuery=false`).reply(200, { ms: 123, - query: query, result, }) @@ -527,7 +526,7 @@ describe('client', async () => { nock(projectHost()).get(`/v1/data/query/foo?query=${qs}`).reply(200, { ms: 123, - query: query, + query, result, }) @@ -538,13 +537,33 @@ describe('client', async () => { expect(res.result[0].rating, 'data should match').toBe(5) }) - test.skipIf(isEdge)('can query for documents with request tag', async () => { - nock(projectHost()).get(`/v1/data/query/foo?query=*&tag=mycompany.syncjob`).reply(200, { + test.skipIf(isEdge)('can explicitly ask to include query in response', async () => { + const query = 'beerfiesta.beer[.title == $beerName]' + const params = {beerName: 'Headroom Double IPA'} + const qs = + 'beerfiesta.beer%5B.title%20%3D%3D%20%24beerName%5D&%24beerName=%22Headroom%20Double%20IPA%22' + + nock(projectHost()).get(`/v1/data/query/foo?query=${qs}`).reply(200, { ms: 123, - query: '*', + query, result, }) + const res = await getClient().fetch(query, params, {filterResponse: false, returnQuery: true}) + expect(res.ms, 'should include timing info').toBe(123) + expect(res.query, 'should include query').toBe(query) + expect(res.result.length, 'length should match').toBe(1) + expect(res.result[0].rating, 'data should match').toBe(5) + }) + + test.skipIf(isEdge)('can query for documents with request tag', async () => { + nock(projectHost()) + .get(`/v1/data/query/foo?query=*&tag=mycompany.syncjob&returnQuery=false`) + .reply(200, { + ms: 123, + result, + }) + const res = await getClient().fetch('*', {}, {tag: 'mycompany.syncjob'}) expect(res.length, 'length should match').toBe(1) expect(res[0].rating, 'data should match').toBe(5) @@ -554,10 +573,11 @@ describe('client', async () => { 'can query for documents with resultSourceMap and perspective', async () => { nock(projectHost()) - .get(`/vX/data/query/foo?query=*&resultSourceMap=true&perspective=previewDrafts`) + .get( + `/vX/data/query/foo?query=*&returnQuery=false&resultSourceMap=true&perspective=previewDrafts`, + ) .reply(200, { ms: 123, - query: '*', result, resultSourceMap, }) @@ -578,11 +598,10 @@ describe('client', async () => { async () => { nock(projectHost()) .get( - `/vX/data/query/foo?query=*&resultSourceMap=withKeyArraySelector&perspective=previewDrafts`, + `/vX/data/query/foo?query=*&returnQuery=false&resultSourceMap=withKeyArraySelector&perspective=previewDrafts`, ) .reply(200, { ms: 123, - query: '*', result, resultSourceMap, }) @@ -600,10 +619,9 @@ describe('client', async () => { test.skipIf(isEdge)('automatically useCdn false if perspective is previewDrafts', async () => { nock('https://abc123.api.sanity.io') - .get(`/v1/data/query/foo?query=*&perspective=previewDrafts`) + .get(`/v1/data/query/foo?query=*&returnQuery=false&perspective=previewDrafts`) .reply(200, { ms: 123, - query: '*', result, }) @@ -622,10 +640,11 @@ describe('client', async () => { 'can query for documents with resultSourceMap and perspective using the third client.fetch parameter', async () => { nock(projectHost()) - .get(`/vX/data/query/foo?query=*&resultSourceMap=true&perspective=previewDrafts`) + .get( + `/vX/data/query/foo?query=*&returnQuery=false&resultSourceMap=true&perspective=previewDrafts`, + ) .reply(200, { ms: 123, - query: '*', result, resultSourceMap, }) @@ -644,12 +663,13 @@ describe('client', async () => { test.skipIf(isEdge)( 'setting resultSourceMap and perspective on client.fetch overrides the config', async () => { - nock(projectHost()).get(`/vX/data/query/foo?query=*&perspective=published`).reply(200, { - ms: 123, - query: '*', - result, - resultSourceMap, - }) + nock(projectHost()) + .get(`/vX/data/query/foo?query=*&returnQuery=false&perspective=published`) + .reply(200, { + ms: 123, + result, + resultSourceMap, + }) const client = getClient({ apiVersion: 'X', @@ -666,10 +686,9 @@ describe('client', async () => { 'setting a perspective previewDrafts override on client.fetch sets useCdn to false', async () => { nock('https://abc123.api.sanity.io') - .get(`/v1/data/query/foo?query=*&perspective=previewDrafts`) + .get(`/v1/data/query/foo?query=*&returnQuery=false&perspective=previewDrafts`) .reply(200, { ms: 123, - query: '*', result, }) @@ -681,11 +700,12 @@ describe('client', async () => { ) test.skipIf(isEdge)('allow overriding useCdn to false on client.fetch', async () => { - nock('https://abc123.api.sanity.io').get(`/v1/data/query/foo?query=*`).reply(200, { - ms: 123, - query: '*', - result, - }) + nock('https://abc123.api.sanity.io') + .get(`/v1/data/query/foo?query=*&returnQuery=false`) + .reply(200, { + ms: 123, + result, + }) const client = createClient({projectId: 'abc123', dataset: 'foo', useCdn: true}) const res = await client.fetch('*', {}, {useCdn: false}) @@ -694,11 +714,12 @@ describe('client', async () => { }) test.skipIf(isEdge)('allow overriding useCdn to true on client.fetch', async () => { - nock('https://abc123.apicdn.sanity.io').get(`/v1/data/query/foo?query=*`).reply(200, { - ms: 123, - query: '*', - result, - }) + nock('https://abc123.apicdn.sanity.io') + .get(`/v1/data/query/foo?query=*&returnQuery=false`) + .reply(200, { + ms: 123, + result, + }) const client = createClient({projectId: 'abc123', dataset: 'foo', useCdn: false}) const res = await client.fetch('*', {}, {useCdn: true}) @@ -707,23 +728,19 @@ describe('client', async () => { }) test.skipIf(isEdge)('throws on invalid request tag on request', () => { - nock(projectHost()).get(`/v1/data/query/foo?query=*&tag=mycompany.syncjob`).reply(200, { - ms: 123, - query: '*', - result, - }) - expect(() => { getClient().fetch('*', {}, {tag: 'mycompany syncjob ok'}) }).toThrow(/tag can only contain alphanumeric/i) }) test.skipIf(isEdge)('can use a tag-prefixed client', async () => { - nock(projectHost()).get(`/v1/data/query/foo?query=*&tag=mycompany.syncjob`).reply(200, { - ms: 123, - query: '*', - result, - }) + nock(projectHost()) + .get(`/v1/data/query/foo?query=*&returnQuery=false&tag=mycompany.syncjob`) + .reply(200, { + ms: 123, + query: '*', + result, + }) const res = await getClient({requestTagPrefix: 'mycompany'}).fetch('*', {}, {tag: 'syncjob'}) expect(res.length, 'length should match').toBe(1) @@ -739,7 +756,10 @@ describe('client', async () => { message: 'You are not allowed to access this resource', } - nock(projectHost()).get('/v1/data/query/foo?query=area51').times(5).reply(403, response) + nock(projectHost()) + .get('/v1/data/query/foo?query=area51&returnQuery=false') + .times(5) + .reply(403, response) try { await getClient().fetch('area51') @@ -766,7 +786,7 @@ describe('client', async () => { } nock(projectHost()) - .get('/v1/data/query/foo?query=foo.bar.baz%20%2012%23%5B%7B') + .get('/v1/data/query/foo?query=foo.bar.baz%20%2012%23%5B%7B&returnQuery=false') .reply(400, response) try { @@ -1180,7 +1200,7 @@ describe('client', async () => { test.skipIf(isEdge)('delete() can use query with params', async () => { const query = '*[_type == "beer" && title == $beerName]' const params = {beerName: 'Headroom Double IPA'} - const expectedBody = {mutations: [{delete: {query: query, params: params}}]} + const expectedBody = {mutations: [{delete: {query, params: params}}]} nock(projectHost()) .post( '/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', @@ -1188,7 +1208,7 @@ describe('client', async () => { ) .reply(200, {transactionId: 'abc123'}) - await expect(getClient().delete({query: query, params: params})).resolves.not.toThrow() + await expect(getClient().delete({query, params: params})).resolves.not.toThrow() }) test.skipIf(isEdge)('delete() can be told not to return documents', async () => { @@ -1375,10 +1395,9 @@ describe('client', async () => { nock(projectHost()) .get('/v1/data/query/foo') - .query({query, ...qParams}) + .query({query, ...qParams, returnQuery: 'false'}) .reply(200, { ms: 123, - query: query, result, }) @@ -1399,14 +1418,12 @@ describe('client', async () => { // Again, just... don't do this. const query = `*[_type == "beer" && (${clause.join(' || ')})]` - nock(projectHost()) - .filteringRequestBody(/.*/, '*') - .post('/v1/data/query/foo', '*') - .reply(200, { - ms: 123, - query: query, - result, - }) + const expectedBody = JSON.stringify({query, params}) + nock(projectHost()).post('/v1/data/query/foo?returnQuery=false', expectedBody).reply(200, { + ms: 123, + query, + result, + }) const res = await getClient().fetch(query, params) expect(res.length, 'length should match').toEqual(1) @@ -1424,20 +1441,14 @@ describe('client', async () => { // Again, just... don't do this. const query = `*[_type == "beer" && (${clause.join(' || ')})]` + const expectedBody = JSON.stringify({query, params}) - nock(projectHost()) - .filteringRequestBody(/.*/, '*') - .post('/v1/data/query/foo', '*') - .reply(code, {}) + nock(projectHost()).post('/v1/data/query/foo?returnQuery=false', expectedBody).reply(code, {}) - nock(projectHost()) - .filteringRequestBody(/.*/, '*') - .post('/v1/data/query/foo', '*') - .reply(200, { - ms: 123, - query: query, - result, - }) + nock(projectHost()).post('/v1/data/query/foo?returnQuery=false', expectedBody).reply(200, { + ms: 123, + result, + }) const res = await getClient().fetch(query, params) expect(res.length, 'length should match').toEqual(1) @@ -1456,13 +1467,13 @@ describe('client', async () => { // Again, just... don't do this. const query = `*[_type == "beer" && (${clause.join(' || ')})]` + const expectedBody = JSON.stringify({query, params}) nock(projectHost()) - .filteringRequestBody(/.*/, '*') - .post('/v1/data/query/foo?tag=myapp.silly-query', '*') + .post('/v1/data/query/foo?tag=myapp.silly-query&returnQuery=false', expectedBody) .reply(200, { ms: 123, - query: query, + query, result, }) @@ -1484,13 +1495,16 @@ describe('client', async () => { // Again, just... don't do this. const query = `*[_type == "beer" && (${clause.join(' || ')})]` + const expectedBody = JSON.stringify({query, params}) nock(projectHost()) - .filteringRequestBody(/.*/, '*') - .post('/vX/data/query/foo?resultSourceMap=true&perspective=previewDrafts', '*') + .post( + '/vX/data/query/foo?resultSourceMap=true&perspective=previewDrafts&returnQuery=false', + expectedBody, + ) .reply(200, { ms: 123, - query: query, + query, result, resultSourceMap, }) @@ -1517,13 +1531,14 @@ describe('client', async () => { } const query = `*[_type == "beer" && (${clause.join(' || ')})]` + //const expectedBody = JSON.stringify({query, params}) nock('https://abc123.apicdn.sanity.io') .filteringRequestBody(/.*/, '*') - .post('/v1/data/query/foo', '*') + .post('/v1/data/query/foo?returnQuery=false', '*') .reply(200, { ms: 123, - query: query, + query, result, }) @@ -2560,7 +2575,9 @@ describe('client', async () => { const client = createClient({projectId: 'abc123', dataset: 'foo'}) const response = {result: []} - nock('https://abc123.apicdn.sanity.io').get('/v1/data/query/foo?query=*').reply(200, response) + nock('https://abc123.apicdn.sanity.io') + .get('/v1/data/query/foo?query=*&returnQuery=false') + .reply(200, response) const docs = await client.fetch('*') expect(docs.length).toEqual(0) @@ -2570,7 +2587,9 @@ describe('client', async () => { const client = createClient({projectId: 'abc123', dataset: 'foo', useCdn: false}) const response = {result: []} - nock('https://abc123.api.sanity.io').get('/v1/data/query/foo?query=*').reply(200, response) + nock('https://abc123.api.sanity.io') + .get('/v1/data/query/foo?query=*&returnQuery=false') + .reply(200, response) const docs = await client.fetch('*') expect(docs.length).toEqual(0) @@ -2596,7 +2615,7 @@ describe('client', async () => { const reqheaders = {Authorization: 'Bearer foo'} nock('https://abc123.apicdn.sanity.io', {reqheaders}) - .get('/v1/data/query/foo?query=*') + .get('/v1/data/query/foo?query=*&returnQuery=false') .reply(200, {result: []}) await expect(client.fetch('*')).resolves.not.toThrow() @@ -2612,7 +2631,7 @@ describe('client', async () => { const reqheaders = {foo: 'bar'} nock('https://abc123.api.sanity.io', {reqheaders}) - .get('/v1/data/query/foo?query=*') + .get('/v1/data/query/foo?query=*&returnQuery=false') .reply(200, {result: []}) await expect(client.fetch('*', {}, {headers: {foo: 'bar'}})).resolves.not.toThrow() @@ -2627,7 +2646,7 @@ describe('client', async () => { }) nock('https://abc123.api.sanity.io') - .get('/v1/data/query/foo?query=*') + .get('/v1/data/query/foo?query=*&returnQuery=false') .reply(200, {result: []}) await expect(client.fetch('*')).resolves.not.toThrow() @@ -2636,7 +2655,7 @@ describe('client', async () => { describe('HTTP REQUESTS', () => { test.skipIf(isEdge)('includes token if set', async () => { - const qs = '?query=foo.bar' + const qs = '?query=foo.bar&returnQuery=false' const token = 'abcdefghijklmnopqrstuvwxyz' const reqheaders = {Authorization: `Bearer ${token}`} nock(projectHost(), {reqheaders}).get(`/v1/data/query/foo${qs}`).reply(200, {result: []}) @@ -2646,7 +2665,7 @@ describe('client', async () => { }) test.skipIf(isEdge)('allows overriding token', async () => { - const qs = '?query=foo.bar' + const qs = '?query=foo.bar&returnQuery=false' const token = 'abcdefghijklmnopqrstuvwxyz' const override = '123456789' const reqheaders = {Authorization: `Bearer ${override}`} @@ -2657,7 +2676,7 @@ describe('client', async () => { }) test.skipIf(isEdge)('allows overriding timeout', async () => { - const qs = `?query=${encodeURIComponent('*[][0]')}` + const qs = `?query=${encodeURIComponent('*[][0]')}&returnQuery=false` nock(projectHost()).get(`/v1/data/query/foo${qs}`).reply(200, {result: []}) const docs = await getClient().fetch('*[][0]', {}, {timeout: 60 * 1000}) diff --git a/test/stega/client.test.ts b/test/stega/client.test.ts index 468fb804..cc7116a1 100644 --- a/test/stega/client.test.ts +++ b/test/stega/client.test.ts @@ -131,8 +131,10 @@ describe('@sanity/client/stega', async () => { test.skipIf(isEdge)('it returns stega strings in the response', async () => { nock(projectHost()) - .get(`/v1/data/query/foo?query=${qs}&resultSourceMap=withKeyArraySelector`) - .reply(200, {ms: 123, query, result, resultSourceMap}) + .get( + `/v1/data/query/foo?query=${qs}&returnQuery=false&resultSourceMap=withKeyArraySelector`, + ) + .reply(200, {ms: 123, result, resultSourceMap}) const res = await getClient({stega: {enabled: true, studioUrl: '/studio'}}).fetch( query, @@ -164,8 +166,10 @@ describe('@sanity/client/stega', async () => { test.skipIf(isEdge)('it strips stega strings from params', async () => { nock(projectHost()) - .get(`/v1/data/query/foo?query=${qs}&resultSourceMap=withKeyArraySelector`) - .reply(200, {ms: 123, query, result, resultSourceMap}) + .get( + `/v1/data/query/foo?query=${qs}&returnQuery=false&resultSourceMap=withKeyArraySelector`, + ) + .reply(200, {ms: 123, result, resultSourceMap}) const res = await getClient({stega: {enabled: true, studioUrl: '/studio'}}).fetch(query, { id: vercelStegaCombine(params.id, JSON.stringify({origin: 'sanity.io', href: '/studio'})), @@ -177,8 +181,10 @@ describe('@sanity/client/stega', async () => { describe.skipIf(isEdge)('client.fetch', async () => { test('the stega option accepts booleans as a shortcut to toggle `enabled`', async () => { nock(projectHost()) - .get(`/v1/data/query/foo?query=${qs}&resultSourceMap=withKeyArraySelector`) - .reply(200, {ms: 123, query, result, resultSourceMap}) + .get( + `/v1/data/query/foo?query=${qs}&returnQuery=false&resultSourceMap=withKeyArraySelector`, + ) + .reply(200, {ms: 123, result, resultSourceMap}) const res = await getClient({stega: {studioUrl}}).fetch(query, params, { stega: true, @@ -199,8 +205,8 @@ describe('@sanity/client/stega', async () => { test('the stega option accepts booleans as a shortcut to toggle `enabled`', async () => { nock(projectHost()) - .get(`/v1/data/query/foo?query=${qs}`) - .reply(200, {ms: 123, query, result, resultSourceMap}) + .get(`/v1/data/query/foo?query=${qs}&returnQuery=false`) + .reply(200, {ms: 123, result, resultSourceMap}) const res = await getClient({stega: {studioUrl, enabled: true}}).fetch(query, params, { stega: false, @@ -210,8 +216,10 @@ describe('@sanity/client/stega', async () => { test('the stega option merges in defaults', async () => { nock(projectHost()) - .get(`/v1/data/query/foo?query=${qs}&resultSourceMap=withKeyArraySelector`) - .reply(200, {ms: 123, query, result, resultSourceMap}) + .get( + `/v1/data/query/foo?query=${qs}&returnQuery=false&resultSourceMap=withKeyArraySelector`, + ) + .reply(200, {ms: 123, result, resultSourceMap}) const res = await getClient({stega: {studioUrl, enabled: true}}).fetch(query, params, { stega: {