progital / gatsby-wpgraphql-inline-images

Solution for Gatsby and WPGraphQL sourced content. Downloads images locally.
MIT License
35 stars 12 forks source link

URI in gatsby-node.js Empty - and createNodeId must be a String error #10

Closed robmarshall closed 5 years ago

robmarshall commented 5 years ago

Hi,

I am using your plugin for my build, and am unable to swap images out using the contentParser. After tracing the issue back it seems that there is no URI key on the source object passed from WordPress: https://github.com/progital/gatsby-wpgraphql-inline-images/blob/6c360a75202e5f9bdff92a3f092e5290da42dcc2/gatsby-node.js#L23

This means all the content is returned without being run through the sourceParser.

What is the reason for checking for a URI? Where is this set in WordPress?

When I remove the URI checker, I end up getting errors from createRemoteFileNode within the utils.js file: https://github.com/progital/gatsby-wpgraphql-inline-images/blob/6c360a75202e5f9bdff92a3f092e5290da42dcc2/src/utils.js#L14

Error:

Parameter passed to createNodeId must be a String or Number (got undefined)

Any ideas what this could be?

Thanks

progital commented 5 years ago

Hi,

Yes, I expect that the uri is present in your graphql queries. Why wouldn't it be there? Uri is used as a key to cache parsed content and to avoid parsing it again when requested more than once. https://github.com/progital/gatsby-wpgraphql-inline-images/blob/6c360a75202e5f9bdff92a3f092e5290da42dcc2/gatsby-node.js#L31 Why would you not use uri?

robmarshall commented 5 years ago

Thanks for the quick reply.

It seems URI isn't showing up in the source. But it is in GraphQL. Not sure why!

progital commented 5 years ago

Could it be that you have more than one query? For example, one query to get all posts and then another one in a post component to get post content.

robmarshall commented 5 years ago

Does your query include the URI? This may be the issue. Or should the resolver find this itself?

progital commented 5 years ago

All your queries should include the URI.

robmarshall commented 5 years ago

Really? That would be the issue then! It's not mentioned in the readme, as far as I can see.

progital commented 5 years ago

Could you check if adding the uri solves your issue? Not mentioning it was my oversight.

robmarshall commented 5 years ago

URI solves it. I was overlooking this section here: https://github.com/progital/gatsby-wpgraphql-inline-images/blob/6c360a75202e5f9bdff92a3f092e5290da42dcc2/gatsby-node.js#L49

So didn't understand the URI requirement. Only looked in the parser file.

Great stuff!