Skip to content

Commit 474d2e0

Browse files
committed
fix(codegen): use singular noun (not by-id query name) as findFirst/findOne result key
1 parent 9b618da commit 474d2e0

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

graphql/codegen/src/__tests__/codegen/__snapshots__/model-generator.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class OrganizationModel {
306306
findFirst<S extends OrganizationSelect>(args: FindFirstArgs<S, OrganizationFilter, OrganizationsOrderBy> & {
307307
select: S;
308308
} & StrictSelect<S, OrganizationSelect>): QueryBuilder<{
309-
organizationById: InferSelectResult<OrganizationWithRelations, S> | null;
309+
organization: InferSelectResult<OrganizationWithRelations, S> | null;
310310
}> {
311311
const {
312312
document,
@@ -319,23 +319,23 @@ export class OrganizationModel {
319319
client: this.client,
320320
operation: "query",
321321
operationName: "Organization",
322-
fieldName: "organizationById",
322+
fieldName: "organization",
323323
document,
324324
variables,
325325
transform: (data: {
326326
allOrganizations?: {
327327
nodes?: InferSelectResult<OrganizationWithRelations, S>[];
328328
};
329329
}) => ({
330-
"organizationById": data.allOrganizations?.nodes?.[0] ?? null
330+
"organization": data.allOrganizations?.nodes?.[0] ?? null
331331
})
332332
});
333333
}
334334
findOne<S extends OrganizationSelect>(args: {
335335
id: string;
336336
select: S;
337337
} & StrictSelect<S, OrganizationSelect>): QueryBuilder<{
338-
organizationById: InferSelectResult<OrganizationWithRelations, S> | null;
338+
organization: InferSelectResult<OrganizationWithRelations, S> | null;
339339
}> {
340340
const {
341341
document,
@@ -345,7 +345,7 @@ export class OrganizationModel {
345345
client: this.client,
346346
operation: "query",
347347
operationName: "Organization",
348-
fieldName: "organizationById",
348+
fieldName: "organization",
349349
document,
350350
variables
351351
});

graphql/codegen/src/core/codegen/orm/model-generator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
getGeneratedFileHeader,
2020
getOrderByTypeName,
2121
getPrimaryKeyInfo,
22-
getSingleRowQueryName,
2322
getTableNames,
2423
hasValidPrimaryKey,
2524
lcFirst,
@@ -193,7 +192,10 @@ export function generateModelFile(
193192
const pkField = pkFields[0];
194193
const pluralQueryName = table.query?.all ?? pluralName;
195194
const singleQueryName = table.query?.one;
196-
const singleResultFieldName = getSingleRowQueryName(table);
195+
// The unwrapped result key for findFirst/findOne — must be the friendly
196+
// singular noun (e.g. "animal"), NOT the GraphQL by-id query name (e.g.
197+
// "animalById"), so the surface aligns with the rest of the SDK.
198+
const singleResultFieldName = singularName;
197199
const createMutationName = table.query?.create ?? `create${typeName}`;
198200
const updateMutationName = table.query?.update;
199201
const deleteMutationName = table.query?.delete;

0 commit comments

Comments
 (0)