Skip to content

Commit cc804ae

Browse files
committed
feat(codegen): add method to find all queries in a path
1 parent 7afcdb4 commit cc804ae

File tree

8 files changed

+995
-233
lines changed

8 files changed

+995
-233
lines changed

packages/@sanity/cli/src/workers/typegenGenerate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'
22

33
import {
4-
findQueriesInPath,
4+
findNamedQueriesInPath,
55
getResolver,
66
readSchema,
77
registerBabel,
@@ -80,7 +80,7 @@ async function main() {
8080
length: schema.length,
8181
} satisfies TypegenGenerateTypesWorkerMessage)
8282

83-
const queries = findQueriesInPath({
83+
const queries = findNamedQueriesInPath({
8484
path: opts.searchPath,
8585
resolver,
8686
})
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export {type CodegenConfig, readConfig} from '../readConfig'
22
export {readSchema} from '../readSchema'
33
export {safeParseQuery} from '../safeParseQuery'
4-
export {findQueriesInPath} from '../typescript/findQueriesInPath'
5-
export {findQueriesInSource} from '../typescript/findQueriesInSource'
4+
export {findNamedQueriesInPath} from '../typescript/findQueriesInPath'
5+
export {findNamedQueriesInSource} from '../typescript/findQueriesInSource'
66
export {getResolver} from '../typescript/moduleResolver'
77
export {registerBabel} from '../typescript/registerBabel'
88
export {TypeGenerator} from '../typescript/typeGenerator'

packages/@sanity/codegen/src/typescript/__tests__/findQueriesInPath.test.ts renamed to packages/@sanity/codegen/src/typescript/__tests__/findNamedQueriesInPath.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import path from 'node:path'
33

44
import {describe, expect, test} from '@jest/globals'
55

6-
import {findQueriesInPath} from '../findQueriesInPath'
6+
import {findNamedQueriesInPath} from '../findQueriesInPath'
77

8-
describe('findQueriesInPath', () => {
8+
describe('findNamedQueriesInPath', () => {
99
test('Can find queries in path', async () => {
10-
const stream = findQueriesInPath({
10+
const stream = findNamedQueriesInPath({
1111
path: path.join('**', 'typescript', '__tests__', 'fixtures', 'source1.ts'),
1212
})
1313
const res = []
@@ -28,7 +28,7 @@ describe('findQueriesInPath', () => {
2828
expect(res[0].queries[0].result).toBe('*[_type == "author"]')
2929
})
3030
test('should throw an error if the query name already exists', async () => {
31-
const stream = findQueriesInPath({
31+
const stream = findNamedQueriesInPath({
3232
path: path.join('**', 'fixtures', '{source1,source2}.ts'),
3333
})
3434
await stream.next()

0 commit comments

Comments
 (0)