-
Notifications
You must be signed in to change notification settings - Fork 36
fix!: throw when querying drafts perspective with the API-CDN #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jordanl17
wants to merge
5
commits into
main
Choose a base branch
from
cursor/cdn-drafts-perspective-error-5863
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bfbea6b
feat!: throw when querying drafts perspective with the API-CDN
cursoragent 80e792d
chore: update auto-generated changeset for PR #1304
squiggler-app[bot] 72240c7
chore: retitle the CDN drafts throw as fix!
cursoragent 7a50711
chore: update auto-generated changeset for PR #1304
squiggler-app[bot] aa22946
chore: update auto-generated changeset for PR #1304
squiggler-app[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <!-- auto-generated --> | ||
| --- | ||
| '@sanity/client': major | ||
| --- | ||
|
|
||
| fix!: throw when querying drafts perspective with the API-CDN | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| import {afterAll, beforeEach, describe, expect, test, vi} from 'vitest' | ||
|
|
||
| import {CDN_INCOMPATIBLE_PERSPECTIVE_ERROR} from '../../src/config' | ||
| import {getActiveMock} from '../helpers/mockFetch' | ||
| import {createClient} from './helpers' | ||
|
|
||
| const liveHost = 'https://abc123.api.sanity.io' | ||
| const cdnHost = 'https://abc123.apicdn.sanity.io' | ||
| const draftsQueryPath = '/v1/data/query/foo?query=*&returnQuery=false&perspective=drafts' | ||
| const publishedQueryPath = '/v1/data/query/foo?query=*&returnQuery=false&perspective=published' | ||
| const rawQueryPath = '/v1/data/query/foo?query=*&returnQuery=false&perspective=raw' | ||
| const stackedQueryPath = | ||
| '/v1/data/query/foo?query=*&returnQuery=false&perspective=published%2Cdrafts' | ||
|
|
||
| describe('API-CDN and drafts perspective', () => { | ||
| const result = [{_id: 'njgNkngskjg', rating: 5}] | ||
| const warn = vi.spyOn(console, 'warn') | ||
| beforeEach(() => { | ||
| warn.mockReset() | ||
| }) | ||
| afterAll(() => { | ||
| warn.mockRestore() | ||
| }) | ||
|
|
||
| describe('after: allowed combinations still query', () => { | ||
| test('drafts with useCdn false uses the Live API', async () => { | ||
| getActiveMock() | ||
| .scope(liveHost) | ||
| .on('GET', draftsQueryPath) | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: false, | ||
| perspective: 'drafts', | ||
| }) | ||
| expect(await client.fetch('*', {})).toEqual(result) | ||
| }) | ||
|
|
||
| test('published with useCdn true uses the API-CDN', async () => { | ||
| getActiveMock() | ||
| .scope(cdnHost) | ||
| .on('GET', publishedQueryPath) | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'published', | ||
| }) | ||
| expect(await client.fetch('*', {})).toEqual(result) | ||
| }) | ||
|
|
||
| test('raw with useCdn true uses the API-CDN', async () => { | ||
| getActiveMock() | ||
| .scope(cdnHost) | ||
| .on('GET', rawQueryPath) | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'raw', | ||
| }) | ||
| expect(await client.fetch('*', {})).toEqual(result) | ||
| }) | ||
|
|
||
| test('drafts with useCdn true still queries when fetch overrides useCdn to false', async () => { | ||
| getActiveMock() | ||
| .scope(liveHost) | ||
| .on('GET', draftsQueryPath) | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'drafts', | ||
| }) | ||
| expect(await client.fetch('*', {}, {useCdn: false})).toEqual(result) | ||
| }) | ||
|
|
||
| test('stacked perspectives without drafts still fall back to the Live API when useCdn is true', async () => { | ||
| getActiveMock() | ||
| .scope(liveHost) | ||
| .on('GET', '/v1/data/query/foo?query=*&returnQuery=false&perspective=published%2Crrel123') | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: ['published', 'rrel123'], | ||
| }) | ||
| expect(await client.fetch('*', {})).toEqual(result) | ||
| }) | ||
|
|
||
| test('stacked perspectives with useCdn false use the Live API', async () => { | ||
| getActiveMock() | ||
| .scope(liveHost) | ||
| .on('GET', stackedQueryPath) | ||
| .respond({status: 200, body: {ms: 123, result}}) | ||
|
|
||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: false, | ||
| perspective: ['published', 'drafts'], | ||
| }) | ||
| expect(await client.fetch('*', {})).toEqual(result) | ||
| }) | ||
| }) | ||
|
|
||
| describe('after: incompatible combinations throw instead of warning', () => { | ||
| test('constructing the client with drafts and useCdn true does not throw', () => { | ||
| expect(() => | ||
| createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'drafts', | ||
| }), | ||
| ).not.toThrow() | ||
| }) | ||
|
|
||
| test('fetch throws when config has drafts and useCdn true', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'drafts', | ||
| }) | ||
| expect(() => client.fetch('*', {})).toThrow(CDN_INCOMPATIBLE_PERSPECTIVE_ERROR) | ||
| expect(warn).not.toHaveBeenCalledWith( | ||
| expect.stringContaining('The Live API will be used instead'), | ||
| ) | ||
| }) | ||
|
|
||
| test('fetch throws when config has previewDrafts and useCdn true', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: 'previewDrafts', | ||
| }) | ||
| expect(() => client.fetch('*', {})).toThrow(CDN_INCOMPATIBLE_PERSPECTIVE_ERROR) | ||
| }) | ||
|
|
||
| test('fetch throws when drafts is combined with the default useCdn true', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| perspective: 'drafts', | ||
| }) | ||
| expect(() => client.fetch('*', {})).toThrow(CDN_INCOMPATIBLE_PERSPECTIVE_ERROR) | ||
| }) | ||
|
|
||
| test('fetch throws when a drafts perspective override is used on a CDN client', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| }) | ||
| expect(() => client.fetch('*', {}, {perspective: 'drafts'})).toThrow( | ||
| CDN_INCOMPATIBLE_PERSPECTIVE_ERROR, | ||
| ) | ||
| }) | ||
|
|
||
| test('fetch throws when a previewDrafts perspective override is used on a CDN client', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| }) | ||
| expect(() => client.fetch('*', {}, {perspective: 'previewDrafts'})).toThrow( | ||
| CDN_INCOMPATIBLE_PERSPECTIVE_ERROR, | ||
| ) | ||
| }) | ||
|
|
||
| test('fetch throws when a stack including drafts is used with useCdn true', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: true, | ||
| perspective: ['published', 'drafts'], | ||
| }) | ||
| expect(() => client.fetch('*', {})).toThrow(CDN_INCOMPATIBLE_PERSPECTIVE_ERROR) | ||
| }) | ||
|
|
||
| test('fetch throws when useCdn is overridden to true on a drafts client', () => { | ||
| const client = createClient({ | ||
| projectId: 'abc123', | ||
| dataset: 'foo', | ||
| useCdn: false, | ||
| perspective: 'drafts', | ||
| }) | ||
| expect(() => client.fetch('*', {}, {useCdn: true})).toThrow( | ||
| CDN_INCOMPATIBLE_PERSPECTIVE_ERROR, | ||
| ) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol clanker, we are not doing a major for this