Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(codegen): move Result appending into type generation #6082

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ describe('findQueries', () => {
expect(queries.length).toBe(0)
})

test("should name queries with 'Result' at the end", () => {
const source = `
import { groq } from "groq";
const postQuery = groq\`*[_type == "author"]\`
const res = sanity.fetch(postQueryResult);
`

const queries = findQueriesInSource(source, 'test.ts')
const queryResult = queries[0]

expect(queryResult?.name.substr(-6)).toBe('Result')
})

test('should import', () => {
const source = `
import { groq } from "groq";
Expand All @@ -106,8 +93,7 @@ describe('findQueries', () => {
}

const queries = findQueriesInSource(source, 'test.ts', undefined, resolver)
const queryResult = queries[0]

expect(queryResult?.name.substr(-6)).toBe('Result')
expect(queries.length).toBe(1)
expect(queries[0].result).toBe('*[_type == "foo"]')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function findQueriesInSource(
babelTypes.isIdentifier(node.id) &&
init.tag.name === groqTagName
) {
const queryName = `${node.id.name}Result`
const queryName = `${node.id.name}`
const queryResult = resolveExpression({
node: init,
file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ async function main() {
const ast = parse(query)
const queryTypes = typeEvaluate(ast, schema)

const type = typeGenerator.generateTypeNodeTypes(queryName, queryTypes)
const type = typeGenerator.generateTypeNodeTypes(`${queryName}Result`, queryTypes)

fileQueryTypes.push({
queryName: queryName,
queryName,
query,
type,
unknownTypes: countUnknownTypes(queryTypes),
Expand Down
Loading