Skip to content

Commit c11da0c

Browse files
authored
fix(query-graphql): Fixed relations not respecting the given name (#218)
BREAKING CHANGE: Relation names are no longer automatically pluralized and respect the given name Fixes #217
2 parents a50bdf7 + 99e3cb3 commit c11da0c

File tree

7 files changed

+30
-26
lines changed

7 files changed

+30
-26
lines changed

examples/dataloader-configuration/schema.gql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type SubTask {
197197
created: DateTime!
198198
updated: DateTime!
199199
todoItemId: String!
200-
todoItems(
200+
todoItem(
201201
"""Specify to filter the records returned."""
202202
filter: TodoItemFilter! = {}
203203

packages/query-graphql/__tests__/resolvers/federation/__snapshots__/federation.resolver.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type TestFederated {
6767
"""Specify to sort results."""
6868
sorting: [TestRelationDTOSort!]! = []
6969
): [TestRelationDTO!]!
70-
relationOffsetConnections(
70+
relationOffset(
7171
"""Limit or page results."""
7272
paging: OffsetPaging! = {limit: 10}
7373
@@ -76,7 +76,7 @@ type TestFederated {
7676
7777
"""Specify to sort results."""
7878
sorting: [TestRelationDTOSort!]! = []
79-
): TestFederatedRelationOffsetConnectionsConnection!
79+
): TestFederatedRelationOffsetConnection!
8080
relationCursorConnections(
8181
"""Limit or page results."""
8282
paging: CursorPaging! = {first: 10}
@@ -216,7 +216,7 @@ type OffsetPageInfo {
216216
hasPreviousPage: Boolean
217217
}
218218
219-
type TestFederatedRelationOffsetConnectionsConnection {
219+
type TestFederatedRelationOffsetConnection {
220220
"""Paging information"""
221221
pageInfo: OffsetPageInfo!
222222

packages/query-graphql/__tests__/resolvers/federation/federation.resolver.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ describe('FederationResolver', () => {
3131
@Relation('relation', () => TestRelationDTO)
3232
@Relation('custom', () => TestRelationDTO, { relationName: 'other' })
3333
@UnPagedRelation('unPagedRelations', () => TestRelationDTO)
34-
@OffsetConnection('relationOffsetConnection', () => TestRelationDTO)
35-
@CursorConnection('relationCursorConnection', () => TestRelationDTO)
34+
@OffsetConnection('relationOffset', () => TestRelationDTO, {
35+
relationName: 'relationOffsetConnection'
36+
})
37+
@CursorConnection('relationCursorConnections', () => TestRelationDTO, {
38+
relationName: 'relationCursorConnection'
39+
})
3640
class TestFederatedDTO extends TestResolverDTO {
3741
@FilterableField(() => ID)
3842
id!: string
@@ -131,7 +135,7 @@ describe('FederationResolver', () => {
131135
when(
132136
mockService.queryRelations(
133137
TestRelationDTO,
134-
'relationCursorConnections',
138+
'relationCursorConnection',
135139
deepEqual([dto]),
136140
objectContaining({ ...query, paging: { limit: 2, offset: 0 } })
137141
)
@@ -181,14 +185,14 @@ describe('FederationResolver', () => {
181185
when(
182186
mockService.queryRelations(
183187
TestRelationDTO,
184-
'relationOffsetConnections',
188+
'relationOffsetConnection',
185189
deepEqual([dto]),
186190
objectContaining({ ...query, paging: { limit: 2 } })
187191
)
188192
).thenResolve(new Map([[dto, output]]))
189193
// @ts-ignore
190194
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
191-
const result = await resolver.queryRelationOffsetConnections(dto, query, {})
195+
const result = await resolver.queryRelationOffset(dto, query, {})
192196
return expect(result).toEqual({
193197
nodes: output,
194198
pageInfo: { hasNextPage: false, hasPreviousPage: false },

packages/query-graphql/__tests__/resolvers/relations/read-relation/many/__snapshots__/1.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ exports[`ReadRelationsResolver - many - 1 should not add filter argument if disa
44
"type TestResolverDTO {
55
id: ID!
66
stringField: String!
7-
relations(
7+
relation(
88
"""Limit or page results."""
99
paging: CursorPaging! = {first: 10}
1010
1111
"""Specify to sort results."""
1212
sorting: [TestRelationDTOSort!]! = []
13-
): TestResolverDTORelationsConnection!
13+
): TestResolverDTORelationConnection!
1414
}
1515
1616
input CursorPaging {
@@ -80,7 +80,7 @@ type PageInfo {
8080
endCursor: ConnectionCursor
8181
}
8282
83-
type TestResolverDTORelationsConnection {
83+
type TestResolverDTORelationConnection {
8484
"""Paging information"""
8585
pageInfo: PageInfo!
8686

packages/query-graphql/__tests__/resolvers/relations/read-relation/many/__snapshots__/2.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ exports[`ReadRelationsResolver - many - 2 should not add sorting argument if dis
44
"type TestResolverDTO {
55
id: ID!
66
stringField: String!
7-
relations(
7+
relation(
88
"""Limit or page results."""
99
paging: CursorPaging! = {first: 10}
1010
1111
"""Specify to filter the records returned."""
1212
filter: TestRelationDTOFilter! = {}
13-
): TestResolverDTORelationsConnection!
13+
): TestResolverDTORelationConnection!
1414
}
1515
1616
input CursorPaging {
@@ -98,7 +98,7 @@ type PageInfo {
9898
endCursor: ConnectionCursor
9999
}
100100
101-
type TestResolverDTORelationsConnection {
101+
type TestResolverDTORelationConnection {
102102
"""Paging information"""
103103
pageInfo: PageInfo!
104104

packages/query-graphql/__tests__/resolvers/relations/read-relation/many/__snapshots__/4.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`ReadRelationsResolver - many - 4 should use the dtoName if provided 1`]
44
"type TestResolverDTO {
55
id: ID!
66
stringField: String!
7-
tests(
7+
test(
88
"""Limit or page results."""
99
paging: CursorPaging! = {first: 10}
1010
@@ -13,7 +13,7 @@ exports[`ReadRelationsResolver - many - 4 should use the dtoName if provided 1`]
1313
1414
"""Specify to sort results."""
1515
sorting: [TestRelationDTOSort!]! = []
16-
): TestResolverDTOTestsConnection!
16+
): TestResolverDTOTestConnection!
1717
}
1818
1919
input CursorPaging {
@@ -124,7 +124,7 @@ type PageInfo {
124124
endCursor: ConnectionCursor
125125
}
126126
127-
type TestResolverDTOTestsConnection {
127+
type TestResolverDTOTestConnection {
128128
"""Paging information"""
129129
pageInfo: PageInfo!
130130

packages/query-graphql/src/resolvers/relations/read-relations.resolver.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ const ReadManyRelationMixin =
8484
const commonResolverOpts = removeRelationOpts(relation)
8585
const relationDTO = relation.DTO
8686
const dtoName = getDTONames(DTOClass).baseName
87-
const { pluralBaseNameLower, pluralBaseName } = getDTONames(relationDTO, { dtoName: relation.dtoName })
88-
const relationName = relation.relationName ?? pluralBaseNameLower
89-
const relationLoaderName = `load${pluralBaseName}For${DTOClass.name}`
90-
const countRelationLoaderName = `count${pluralBaseName}For${DTOClass.name}`
87+
const { baseNameLower, baseName } = getDTONames(relationDTO, { dtoName: relation.dtoName })
88+
const relationName = relation.relationName ?? baseNameLower
89+
const relationLoaderName = `load${baseName}For${DTOClass.name}`
90+
const countRelationLoaderName = `count${baseName}For${DTOClass.name}`
9191
const queryLoader = new QueryRelationsLoader<DTO, Relation>(relationDTO, relationName)
9292
const countLoader = new CountRelationsLoader<DTO, Relation>(relationDTO, relationName)
93-
const connectionName = `${dtoName}${pluralBaseName}Connection`
93+
const connectionName = `${dtoName}${baseName}Connection`
9494

9595
@ArgsType()
9696
class RelationQA extends QueryArgsType(relationDTO, {
@@ -105,17 +105,17 @@ const ReadManyRelationMixin =
105105
@Resolver(() => DTOClass, { isAbstract: true })
106106
class ReadManyMixin extends Base {
107107
@ResolverField(
108-
pluralBaseNameLower,
108+
baseNameLower,
109109
() => CT.resolveType,
110110
{ nullable: relation.nullable, complexity: relation.complexity, description: relation?.description },
111111
commonResolverOpts,
112112
{ interceptors: [AuthorizerInterceptor(DTOClass)] }
113113
)
114-
async [`query${pluralBaseName}`](
114+
async [`query${baseName}`](
115115
@Parent() dto: DTO,
116116
@Args() q: RelationQA,
117117
@Context() context: ExecutionContext,
118-
@RelationAuthorizerFilter(pluralBaseNameLower, {
118+
@RelationAuthorizerFilter(baseNameLower, {
119119
operationGroup: OperationGroup.READ,
120120
many: true
121121
})

0 commit comments

Comments
 (0)