Closed shendriksza closed 5 years ago
Hi thanks for the link.
I verified, but it looks to me like my Moltin ID is still being used where it should be. The same master build that compiled yesterday is also failing now on Netlify with the same error.
I gave all my products main images, now the error states:
error Plugin @moltin/gatsby-source-moltin returned an error
TypeError: Cannot read property 'href' of undefined
- gatsby-node.js:272 imageNodes.filter.fileNode
[kooi-dev-store]/[@moltin]/gatsby-source-moltin/gatsby-node.js:272:55
- Array.filter
- gatsby-node.js:271 getFileNodes
[kooi-dev-store]/[@moltin]/gatsby-source-moltin/gatsby-node.js:271:33
- gatsby-node.js:299 Object.exports.onCreateNode
[kooi-dev-store]/[@moltin]/gatsby-source-moltin/gatsby-node.js:299:32
So it still seems some links are missing. Anything else I could possibly check?
I̶t̶ ̶s̶e̶e̶m̶s̶ ̶t̶o̶ ̶m̶e̶ ̶t̶h̶e̶ ̶M̶o̶l̶t̶i̶n̶ ̶A̶P̶I̶ ̶c̶h̶a̶n̶g̶e̶d̶?̶ ̶I̶ ̶r̶e̶m̶e̶m̶b̶e̶r̶ ̶i̶t̶ ̶u̶s̶e̶d̶ ̶t̶o̶ ̶r̶e̶t̶u̶r̶n̶ ̶t̶h̶e̶ ̶m̶a̶i̶n̶I̶m̶a̶g̶e̶H̶r̶e̶f̶,̶ ̶n̶o̶w̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶d̶e̶r̶e̶f̶e̶r̶e̶n̶c̶e̶ ̶t̶h̶e̶ ̶m̶a̶i̶n̶I̶m̶a̶g̶e̶ ̶f̶r̶o̶m̶ ̶t̶h̶e̶ ̶r̶e̶l̶a̶t̶i̶o̶n̶s̶h̶i̶p̶ ̶i̶d̶'̶s̶ ̶f̶i̶r̶s̶t̶
@shendriksza not sure I follow...
You can make the following query:
{
allMoltinProduct {
nodes {
id
mainImageHref
}
}
}
What does that query return inside GraphiQL?
Sorry I was distracted on a tangent.
I have identified the issue. It seems when we updated/deleted images on Moltin, the references to those images where not deleted as we assumed they were. So there are relationship id's on our products to images that don't exist anymore.
@notrab I fixed the issue by writing a script that fetches all products and verifies that each relationship id exists and deleting it when it does not.
Is it really the responsibility on our side, to verify the integrity of Moltin's internal references? Shouldn't the relationships be deleted automatically once the file no longer exists?
@shendriksza Thanks for highlighting this issue. This is an issue with the API in which the main_image
or file
relationship field to the deleted file is not removed from the product record.
I've raised this internally.
@shendriksza can you share your solution. I'm running into the same issue. Thanks!
@domtaylor basicallly the following (Python code)
The "moltin" in this case is just a small wrapper library I wrote to call the Moltin endpoints
# Check file relationships to make sure they are valid
def checkRelationships():
moltin.getProducts()
# Iterate and verify current file ID's are valid
for product in moltin.allProducts:
if 'main_image' in product['relationships']:
fileItem = product['relationships']['main_image']['data']
# Product has a main image. Let's make sure it exists
resp = moltin.getFile(fileItem)
if (not resp):
moltin.deleteMainFileRelationship(product, fileItem)
if 'files' in product['relationships']:
# Product has other images. Let's make sure they exists
for fileItem in product['relationships']['files']['data']:
resp = moltin.getFile(fileItem)
if (not resp):
moltin.deleteFileRelationship(product, fileItem)
@shendriksza thanks so much for sharing. In the end I just created a new store and re-uploaded my products as I only have a few, but in case this happens again I'll rewrite your script for GatsbyJS.
A new error cropped up for me while compiling:
In your gatsby-node.js where you destructure the main-image href:
Any idea why this is happening? Is there an issue with Moltin at the moment, not providing links to my images? Or does this happen because I might have posted images to Moltin without "public: true"?
Either way though, the plugin fails compilation due to it