Skip to content

Commit

Permalink
fix(schema): map tyhe schemaType type, and not the schematype
Browse files Browse the repository at this point in the history
fixes a bug where we cant map custom defined string fields etc
  • Loading branch information
sgulseth committed Mar 18, 2024
1 parent 6fa2460 commit f2ccf5b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/@sanity/schema/src/sanity/extractSchema.ts
Expand Up @@ -171,8 +171,8 @@ export function extractSchema(
}

// map some known types
if (typesMap.has(schemaType.name)) {
return typesMap.get(schemaType.name)
if (schemaType.type && typesMap.has(schemaType.type.name)) {
return typesMap.get(schemaType.type.name)
}

// Cross dataset references are not supported
Expand Down Expand Up @@ -495,6 +495,7 @@ function sortByDependencies(compiledSchema: SchemaDef): string[] {

walkDependencies(schemaType, dependencies)
dependencyMap.set(schemaType, dependencies)
seen.clear() // Clear the seen set for the next type
})

// Sorts the types by their dependencies
Expand Down
Expand Up @@ -222,6 +222,13 @@ Array [
"type": "object",
},
},
Object {
"name": "someTextType",
"type": "type",
"value": Object {
"type": "string",
},
},
Object {
"attributes": Object {
"_createdAt": Object {
Expand Down Expand Up @@ -4268,6 +4275,14 @@ Array [
"type": "inline",
},
},
"someTextType": Object {
"optional": true,
"type": "objectAttribute",
"value": Object {
"name": "someTextType",
"type": "inline",
},
},
"title": Object {
"optional": true,
"type": "objectAttribute",
Expand Down
11 changes: 11 additions & 0 deletions packages/@sanity/schema/test/extractSchema/extractSchema.test.ts
Expand Up @@ -89,6 +89,11 @@ describe('Extract schema test', () => {
name: 'manuscript',
type: 'manuscript',
},
{
title: 'Some text',
name: 'someTextType',
type: 'someTextType',
},
{
title: 'customStringType',
name: 'customStringType',
Expand Down Expand Up @@ -225,6 +230,10 @@ describe('Extract schema test', () => {
},
],
},
defineType({
name: 'someTextType',
type: 'text',
}),
],
})

Expand All @@ -235,6 +244,7 @@ describe('Extract schema test', () => {
'sanity.imageDimensions',
'geopoint',
'slug',
'someTextType',
'sanity.fileAsset',
'code',
'customStringType',
Expand Down Expand Up @@ -269,6 +279,7 @@ describe('Extract schema test', () => {
'number',
'someInlinedObject',
'manuscript',
'someTextType',
'customStringType',
'blocks',
'other',
Expand Down

0 comments on commit f2ccf5b

Please sign in to comment.