Skip to content

Commit

Permalink
chore(schema): optimize(readability) document dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed Mar 18, 2024
1 parent dcd5537 commit 6fa2460
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/@sanity/schema/src/sanity/extractSchema.ts
Expand Up @@ -457,18 +457,20 @@ function sortByDependencies(compiledSchema: SchemaDef): string[] {

if ('fields' in schemaType) {
for (const field of gatherFields(schemaType)) {
const last = lastType(field.type)
if (last.name === 'document') {
dependencies.add(last)
continue
}

let schemaTypeName: string | undefined
if (schemaType.type.type) {
schemaTypeName = field.type.type.name
} else if ('jsonType' in schemaType.type) {
schemaTypeName = field.type.jsonType
}

if (
schemaTypeName === 'document' ||
schemaTypeName === 'object' ||
schemaTypeName === 'block'
) {
if (schemaTypeName === 'object' || schemaTypeName === 'block') {
if (isReferenceType(field.type)) {
field.type.to.forEach((ref) => dependencies.add(ref.type))
} else {
Expand Down

0 comments on commit 6fa2460

Please sign in to comment.