From 9ecb90c3be958cfbf81ba4c4be7e9ce6e6c0ee2e Mon Sep 17 00:00:00 2001 From: Pavel Lazar <85319655+lazpavel@users.noreply.github.com> Date: Sun, 21 Nov 2021 18:54:45 -0500 Subject: [PATCH] fix(graphql-transformer-migrator): fixed belongs to type relationshio check (#9003) --- .../__tests__/migration/__snapshots__/auth-tests.ts.snap | 4 ++-- .../__tests__/migration/__snapshots__/migrate-tests.ts.snap | 6 +++--- .../src/migrators/connection/index.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/auth-tests.ts.snap b/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/auth-tests.ts.snap index 642edbe869b..3bc04f4bbc5 100644 --- a/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/auth-tests.ts.snap +++ b/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/auth-tests.ts.snap @@ -275,7 +275,7 @@ exports[`Schema migration tests for @auth relational auth migrates as expected 1 "type Post @model @auth(rules: [{allow: owner}]) { id: ID! title: String! - author: User @hasOne(fields: [\\"owner\\"]) + author: User @belongsTo(fields: [\\"owner\\"]) owner: ID! @index(name: \\"byOwner\\", sortKeyFields: [\\"id\\"]) } @@ -302,7 +302,7 @@ type ConnectionProtected @model(queries: null) @auth(rules: [{allow: owner}]) { name: String owner: String topLevelID: ID! @index(name: \\"byTopLevel\\", sortKeyFields: [\\"id\\"]) - topLevel: OpenTopLevel @hasOne(fields: [\\"topLevelID\\"]) + topLevel: OpenTopLevel @belongsTo(fields: [\\"topLevelID\\"]) } " `; diff --git a/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/migrate-tests.ts.snap b/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/migrate-tests.ts.snap index aeaf7ea2fd1..cf10c220148 100644 --- a/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/migrate-tests.ts.snap +++ b/packages/amplify-graphql-transformer-migrator/src/__tests__/migration/__snapshots__/migrate-tests.ts.snap @@ -11,7 +11,7 @@ type Comment @model @auth(rules: [{allow: public}]) { id: ID! postID: ID! @index(name: \\"byPost\\", sortKeyFields: [\\"content\\"]) content: String! - post: Post @hasOne(fields: [\\"postID\\"]) + post: Post @belongsTo(fields: [\\"postID\\"]) } " `; @@ -85,8 +85,8 @@ type PostEditor @model(queries: null) @auth(rules: [{allow: public}]) { id: ID! postID: ID! @index(name: \\"byPost\\", sortKeyFields: [\\"editorID\\"]) editorID: ID! @index(name: \\"byEditor\\", sortKeyFields: [\\"postID\\"]) - post: Post! @hasOne(fields: [\\"postID\\"]) - editor: User! @hasOne(fields: [\\"editorID\\"]) + post: Post! @belongsTo(fields: [\\"postID\\"]) + editor: User! @belongsTo(fields: [\\"editorID\\"]) } type User @model @auth(rules: [{allow: public}]) { diff --git a/packages/amplify-graphql-transformer-migrator/src/migrators/connection/index.ts b/packages/amplify-graphql-transformer-migrator/src/migrators/connection/index.ts index 8436e60aad3..e98ab5e2e61 100644 --- a/packages/amplify-graphql-transformer-migrator/src/migrators/connection/index.ts +++ b/packages/amplify-graphql-transformer-migrator/src/migrators/connection/index.ts @@ -52,7 +52,7 @@ export function migrateConnection(node: any, ast: any) { } } else { const relatedType = getRelatedType(ast, getFieldType(connectionField)); - const biDirectionalRelation = relatedType.fields.some((relatedField: any) => { + const biDirectionalRelation = relatedType.fields.find((relatedField: any) => { if (getFieldType(relatedField) !== node.name.value) { return false; } @@ -62,7 +62,7 @@ export function migrateConnection(node: any, ast: any) { return false; } - return relatedField?.directives?.some((relatedDirective: any) => { + return relatedField?.directives?.find((relatedDirective: any) => { return validConnectionDirectiveNames.has(relatedDirective.name.value); }); });