Skip to content

Commit

Permalink
feat(codegen): add method to find all queries in a path
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed Aug 26, 2024
1 parent 7afcdb4 commit cc804ae
Show file tree
Hide file tree
Showing 8 changed files with 995 additions and 233 deletions.
4 changes: 2 additions & 2 deletions packages/@sanity/cli/src/workers/typegenGenerate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'

import {
findQueriesInPath,
findNamedQueriesInPath,
getResolver,
readSchema,
registerBabel,
Expand Down Expand Up @@ -80,7 +80,7 @@ async function main() {
length: schema.length,
} satisfies TypegenGenerateTypesWorkerMessage)

const queries = findQueriesInPath({
const queries = findNamedQueriesInPath({
path: opts.searchPath,
resolver,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/codegen/src/_exports/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {type CodegenConfig, readConfig} from '../readConfig'
export {readSchema} from '../readSchema'
export {safeParseQuery} from '../safeParseQuery'
export {findQueriesInPath} from '../typescript/findQueriesInPath'
export {findQueriesInSource} from '../typescript/findQueriesInSource'
export {findNamedQueriesInPath} from '../typescript/findQueriesInPath'
export {findNamedQueriesInSource} from '../typescript/findQueriesInSource'
export {getResolver} from '../typescript/moduleResolver'
export {registerBabel} from '../typescript/registerBabel'
export {TypeGenerator} from '../typescript/typeGenerator'
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import path from 'node:path'

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

import {findQueriesInPath} from '../findQueriesInPath'
import {findNamedQueriesInPath} from '../findQueriesInPath'

describe('findQueriesInPath', () => {
describe('findNamedQueriesInPath', () => {
test('Can find queries in path', async () => {
const stream = findQueriesInPath({
const stream = findNamedQueriesInPath({
path: path.join('**', 'typescript', '__tests__', 'fixtures', 'source1.ts'),
})
const res = []
Expand All @@ -28,7 +28,7 @@ describe('findQueriesInPath', () => {
expect(res[0].queries[0].result).toBe('*[_type == "author"]')
})
test('should throw an error if the query name already exists', async () => {
const stream = findQueriesInPath({
const stream = findNamedQueriesInPath({
path: path.join('**', 'fixtures', '{source1,source2}.ts'),
})
await stream.next()
Expand Down
Loading

0 comments on commit cc804ae

Please sign in to comment.