Skip to content

Commit af958db

Browse files
committed
feat(typeEvaluator): add support for global::references
1 parent 5460dd3 commit af958db

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/typeEvaluator/functions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
5353
return {type: 'null'} satisfies NullTypeNode
5454
})
5555
}
56+
57+
case 'global.references': {
58+
return {type: 'boolean'}
59+
}
60+
5661
case 'global.string': {
5762
const arg = walk({node: node.args[0], scope})
5863
return mapConcrete(arg, scope, (node) => {

test/typeEvaluate.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,29 @@ t.test('function: global::string', (t) => {
20692069
t.end()
20702070
})
20712071

2072+
t.test('function: references', (t) => {
2073+
const query = `*[_type == "post"] {
2074+
"references": references(_id)
2075+
}`
2076+
const ast = parse(query)
2077+
const res = typeEvaluate(ast, schemas)
2078+
t.strictSame(res, {
2079+
type: 'array',
2080+
of: {
2081+
type: 'object',
2082+
attributes: {
2083+
references: {
2084+
type: 'objectAttribute',
2085+
value: {
2086+
type: 'boolean',
2087+
},
2088+
},
2089+
},
2090+
},
2091+
})
2092+
t.end()
2093+
})
2094+
20722095
function findSchemaType(name: string): TypeNode {
20732096
const type = schemas.find((s) => s.name === name)
20742097
if (!type) {

0 commit comments

Comments
 (0)