From 0075b99eeca7de77f9b5efec490826ebc1bb8843 Mon Sep 17 00:00:00 2001 From: mattddean Date: Mon, 18 Nov 2024 15:25:42 -0500 Subject: [PATCH] fix(graphql): loading of polymorphic hasMany relationships (#9175) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What? Bug #9173 ### Why? `collectionSlug` is an array when `isRelatedToManyCollections` is true ### How? Compare array to array Fixes #9173 ![Screenshot 2024-11-13 at 12 37 52 PM](https://github.com/user-attachments/assets/3eae497d-90d8-474a-afd0-baf69f017459) --- packages/graphql/src/schema/buildObjectType.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/graphql/src/schema/buildObjectType.ts b/packages/graphql/src/schema/buildObjectType.ts index 87cb69dc1..37cc866e4 100644 --- a/packages/graphql/src/schema/buildObjectType.ts +++ b/packages/graphql/src/schema/buildObjectType.ts @@ -432,8 +432,11 @@ export function buildObjectType({ const createPopulationPromise = async (relatedDoc, i) => { let id = relatedDoc let collectionSlug = field.relationTo + const isValidGraphQLCollection = isRelatedToManyCollections + ? graphQLCollections.some((collection) => collectionSlug.includes(collection.slug)) + : graphQLCollections.some((collection) => collectionSlug === collection.slug) - if (graphQLCollections.some((collection) => collection.slug === collectionSlug)) { + if (isValidGraphQLCollection) { if (isRelatedToManyCollections) { collectionSlug = relatedDoc.relationTo id = relatedDoc.value