Skip to content

refactor: use ORM mode as core for RQ mode#689

Closed
yyyyaaa wants to merge 8 commits intomainfrom
feat/graphql-codegen-orm-core
Closed

refactor: use ORM mode as core for RQ mode#689
yyyyaaa wants to merge 8 commits intomainfrom
feat/graphql-codegen-orm-core

Conversation

@yyyyaaa
Copy link
Contributor

@yyyyaaa yyyyaaa commented Feb 5, 2026

Testing a bit more before merging but all tests passing..

@yyyyaaa yyyyaaa changed the title (WIP) refactor: use ORM mode as core for RQ mode refactor: use ORM mode as core for RQ mode Feb 7, 2026
@yyyyaaa yyyyaaa requested a review from pyramation February 7, 2026 07:36
if (depth > 3 || fields.length === 0) {
// Use first field if available, otherwise fallback to 'id'
const fallbackName = fields.length > 0 ? fields[0].name : 'id';
return t.objectExpression([t.objectProperty(t.identifier(fallbackName), t.booleanLiteral(true))]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should maybe just remove defaults. I think it could be trouble to assume id, and why not just force people to select?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can get us into trouble, also removing buildDefaultSelectExpression and not doing defaults can simplify the code.

I know that it will make our current migration a bit more hard, but I think this type of thing feels like it can make code harder to maintain, and also maybe some surprising issues like id doesn't exist...

const pkField = pkFields[0];
const pkFieldName = pkField?.name ?? 'id';
const pkFieldTsType = pkField?.tsType ?? 'string';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if there is no primary key? I know it's a rare case.

const patchTypeName = `${typeName}Patch`;

const pkFields = getPrimaryKeyInfo(table);
const pkField = pkFields[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there is no pk field?

): { document: string; variables: Record<string, unknown> } {
const entitySelections = select
? buildSelections(select as Record<string, unknown>, connectionFieldsMap, operationName)
: [t.field({ name: 'id' })];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another assumption that we have an id

): { document: string; variables: Record<string, unknown> } {
const selections = select
? buildSelections(select as Record<string, unknown>, connectionFieldsMap, operationName)
: [t.field({ name: 'id' })];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumption that we have an id

): { document: string; variables: Record<string, unknown> } {
const entitySelections = select
? buildSelections(select as Record<string, unknown>, connectionFieldsMap, operationName)
: [t.field({ name: 'id' })];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumption that we have id

lines.push(`import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';`);
lines.push(`import { getClient } from '../client';`);
lines.push(`import { buildSelectionArgs } from '../selection';`);
lines.push(`import type { SelectionConfig } from '../selection';`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AST to string regression

lines.push(` const args = buildSelectionArgs<${selectTypeName}>(params?.selection);`);
lines.push(` const { selection: _selection, ...mutationOptions } = params ?? {};`);
lines.push(` void _selection;`);
lines.push(` return useMutation({`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another regression — let's make sure these are AST


lines.push(` ...mutationOptions,`);
lines.push(` });`);
lines.push(`}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more regressions up until here, needs to be 100% AST based.

reactQueryTypeImport.importKind = 'type';
statements.push(reactQueryTypeImport);
lines.push(`import { useQuery } from '@tanstack/react-query';`);
lines.push(`import type { UseQueryOptions, UseQueryResult, QueryClient } from '@tanstack/react-query';`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more AST regressions

lines.push(`import type { SelectionConfig } from '../selection';`);

if (useCentralizedKeys) {
lines.push(`import { customQueryKeys } from '../query-keys';`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more AST regressions

@yyyyaaa
Copy link
Contributor Author

yyyyaaa commented Feb 9, 2026

closed in favor of Dan's PR with my fixes on top
#697

@yyyyaaa yyyyaaa closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants