fix: relations issues (#2497)

* fix: relations issues

one-to-one relation not working
alias should not be used on the foreignKey side

* fix: naming
This commit is contained in:
Jérémy M
2023-11-14 12:07:17 +01:00
committed by GitHub
parent 448f256a35
commit 65af954671
4 changed files with 50 additions and 7 deletions

View File

@ -95,10 +95,20 @@ export class CompositeFieldAliasFactory {
}
`;
}
let relationAlias = fieldKey;
// For one to one relations, pg_graphql use the targetTableName on the side that is not storing the foreign key
// so we need to alias it to the field key
if (
relationMetadata.relationType === RelationMetadataType.ONE_TO_ONE &&
relationDirection === RelationDirection.FROM
) {
relationAlias = `${fieldKey}: ${referencedObjectMetadata.targetTableName}`;
}
// Otherwise it means it's a relation destination is of kind ONE
return `
${fieldKey} {
${relationAlias} {
${this.fieldsStringFactory.createFieldsStringRecursive(
info,
fieldValue,