Skip to content

Commit

Permalink
fix(amplify-codegen-appsync-model-plugin): pass targetName for hasOne…
Browse files Browse the repository at this point in the history
… relationships (#6031)
  • Loading branch information
lawmicha committed Dec 11, 2020
1 parent d452e83 commit dc6bb85
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('process connection', () => {
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_ONE);
expect(connectionInfo.associatedWith).toEqual(modelMap.License.fields[0]);
expect(connectionInfo.isConnectingFieldAutoCreated).toEqual(true);
expect(connectionInfo.targetName).toEqual("personLicenseId");
});

it('should return BELONGS_TO License.person field', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type CodeGenFieldConnectionBelongsTo = CodeGenConnectionTypeBase & {
export type CodeGenFieldConnectionHasOne = CodeGenConnectionTypeBase & {
kind: CodeGenConnectionType.HAS_ONE;
associatedWith: CodeGenField;
targetName: string;
};

export type CodeGenFieldConnectionHasMany = CodeGenConnectionTypeBase & {
Expand Down Expand Up @@ -186,6 +187,7 @@ export function processConnections(
associatedWith: otherSideField,
connectedModel: otherSide,
isConnectingFieldAutoCreated,
targetName: connectionFields[0] || makeConnectionAttributeName(model.name, field.name),
};
} else {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class AppSyncSwiftVisitor extends AppSyncModelVisitor {
if (connectionInfo.kind === CodeGenConnectionType.HAS_ONE) {
return `.hasOne(${name}, is: ${isRequired}, ofType: ${typeName}, associatedWith: ${this.getModelName(
connectionInfo.connectedModel,
)}.keys.${this.getFieldName(connectionInfo.associatedWith)})`;
)}.keys.${this.getFieldName(connectionInfo.associatedWith)}, targetName: "${connectionInfo.targetName}")`;
}
if (connectionInfo.kind === CodeGenConnectionType.BELONGS_TO) {
return `.belongsTo(${name}, is: ${isRequired}, ofType: ${typeName}, targetName: "${connectionInfo.targetName}")`;
Expand Down

0 comments on commit dc6bb85

Please sign in to comment.