Skip to content
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

fix: fixes schema extraction with nested union refs #8096

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ export function extractFromSanitySchema(
}

try {
unionRecursionGuards.add(guardPathName)
if (guardPathName !== 'reference') {
unionRecursionGuards.add(guardPathName)
}

candidates.forEach((def, i) => {
if (typeNeedsHoisting(def)) {
Expand Down
11 changes: 10 additions & 1 deletion packages/sanity/test/cli/graphql/extract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {extractFromSanitySchema} from '../../../src/_internal/cli/actions/graphql/extractFromSanitySchema'
import {type ApiSpecification} from '../../../src/_internal/cli/actions/graphql/types'
import testStudioSchema from './fixtures/test-studio'
import unionRefsSchema from './fixtures/union-refs'

describe('GraphQL - Schema extraction', () => {
beforeEach(() => {
Expand All @@ -15,13 +16,21 @@
vi.runAllTimers()
})

it('Should be able to extract schema', () => {
it('Should be able to extract schema 1', () => {
const extracted = extractFromSanitySchema(testStudioSchema, {
nonNullDocumentFields: false,
})

expect(sortExtracted(extracted)).toMatchSnapshot()

Check failure on line 24 in packages/sanity/test/cli/graphql/extract.test.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 20)

test/cli/graphql/extract.test.ts > GraphQL - Schema extraction > Should be able to extract schema 1

Error: Snapshot `GraphQL - Schema extraction > Should be able to extract schema 1 1` mismatched ❯ test/cli/graphql/extract.test.ts:24:38

Check failure on line 24 in packages/sanity/test/cli/graphql/extract.test.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 18)

test/cli/graphql/extract.test.ts > GraphQL - Schema extraction > Should be able to extract schema 1

Error: Snapshot `GraphQL - Schema extraction > Should be able to extract schema 1 1` mismatched ❯ test/cli/graphql/extract.test.ts:24:38
})

it('Should be able to extract schema 2', () => {
const extracted = extractFromSanitySchema(unionRefsSchema, {
nonNullDocumentFields: false,
})

expect(sortExtracted(extracted)).toMatchSnapshot()

Check failure on line 32 in packages/sanity/test/cli/graphql/extract.test.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 20)

test/cli/graphql/extract.test.ts > GraphQL - Schema extraction > Should be able to extract schema 2

Error: Snapshot `GraphQL - Schema extraction > Should be able to extract schema 2 1` mismatched ❯ test/cli/graphql/extract.test.ts:32:38

Check failure on line 32 in packages/sanity/test/cli/graphql/extract.test.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 18)

test/cli/graphql/extract.test.ts > GraphQL - Schema extraction > Should be able to extract schema 2

Error: Snapshot `GraphQL - Schema extraction > Should be able to extract schema 2 1` mismatched ❯ test/cli/graphql/extract.test.ts:32:38
})
})

function sortExtracted(schema: ApiSpecification) {
Expand Down
Loading
Loading