Skip to content

Commit

Permalink
fix(sync-utils): fix relationship syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
good-idea committed May 30, 2020
1 parent c53700f commit 7d90789
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
16 changes: 10 additions & 6 deletions packages/sync-utils/src/sanity/syncRelationships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ export const createSyncRelationships = (
)

if (newLinks.length) {
const aToBRelationships = toDocs.map((toDoc) => ({
_type: 'reference',
_ref: toDoc._id,
_key: `${toDoc._rev}-${toDoc._id}`,
}))
const aToBRelationships = toDocs
.map((toDoc) => ({
_type: 'reference',
_ref: toDoc._id,
_key: `${toDoc._rev}-${toDoc._id}`,
}))
.filter(
(toDoc) => !existingRelationships.some((er) => er._id === toDoc._ref)
)

await client
.patch(from._id)
Expand All @@ -88,7 +92,7 @@ export const createSyncRelationships = (
}

const archivedRelationships = existingRelationships.filter(
(er) => er.archived === true
(er) => er.archived === true || er.shopifyId === null
)

if (archivedRelationships.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-utils/src/sanity/syncSanityDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const createSyncSanityDocument = (

const doc = await client.fetch<SanityShopifyDocument>(
`
*[shopifyId == $shopifyId && defined(archived) && archived != true]{
*[shopifyId == $shopifyId]{
products[]->,
collections[]->,
"collectionKeys": collections[]{
Expand Down
3 changes: 0 additions & 3 deletions packages/sync-utils/src/syncingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export const syncUtils = (
*/
const {
fetchItemById,
fetchShopifyProduct,
fetchShopifyCollection,
fetchAllShopifyProducts,
fetchAllShopifyCollections,
testSecrets,
Expand All @@ -58,7 +56,6 @@ export const syncUtils = (
syncRelationships,
fetchRelatedDocs,
documentByShopifyId,
documentByHandle,
fetchSecrets,
archiveSanityDocument,
saveSecrets: saveSecretsToSanity,
Expand Down

0 comments on commit 7d90789

Please sign in to comment.