jbolda / gatsby-source-airtable

MIT License
216 stars 43 forks source link

Passing .md Airtable attachments causes TypeError #15

Closed brendanmc6 closed 5 years ago

brendanmc6 commented 6 years ago

I am trying to attach .md files and bring them in using the "fileNode" mapping as stated in your docs.

I can attach, bring in, and locate .txt files without error, but then gatsby-transformer-remark does not recognize these as markdown. So then when I attach .md files instead, it causes the following typeError:

source and transform nodes
fetch all Airtable rows from 2 tables: 806.941ms
error Plugin gatsby-transformer-remark returned an error
  TypeError: Cannot read property 'resolve' of undefined
  - index.js:186 resolve
    [airtable-markdown-docs]/[gatsby]/dist/redux/index.js:186:39
  - debuggability.js:313 Promise._execute
    [airtable-markdown-docs]/[bluebird]/js/release/debuggability.js:313:9

Is this something to do with the way gatsby-source-airtable is bringing in attachments mapped as fileNode? Because obviously gatsby-transformer-remark should have no problem with .md files.

jbolda commented 6 years ago

Hmm, it seems this really is uncharted territory. (The gatsby issue is https://github.com/gatsbyjs/gatsby/issues/9056 for reference.)

We are using createRemoteFileNode from the gatsby-source-filesystem package directly. It looks like the file type is correctly set as gatsby-transformer-remark is picking it up. So I would surmise the transformer-remark is getting some value that isn't expected. That might get us somewhere in debugging, but I don't have time at the moment to dig deeper.

KyleAMathews commented 6 years ago

It seems like the easiest thing to do in the short term is to use onCreateNode to take the markdown fields and create new nodes that are linked to the original airtable node and set the mediaType of the new node to text/markdown so it gets processed correctly.

Another solution is for source-airtable to support mapping fields to media types similar to source-mongodb https://www.gatsbyjs.org/packages/gatsby-source-mongodb/?=mongo#mapping-mediatype-feature

jbolda commented 6 years ago

@KyleAMathews perhaps there is some confusion. We do have the ability to map media types already. The issue appears to be with nodes created from createRemoteFileNode. In this case, they "attached" markdown files and it appears the type is correctly set as remark does pick it up. Perhaps that isn't a popular use case, but moreso #18 might be a more popular / useful use case.

KyleAMathews commented 6 years ago

Oh ok, sorry for the confusion. This could just be a bug then in source-airtable then (or gatsby).

It's odd that this and #18 are happening.

jbolda commented 6 years ago

No worries.

Could this be an issue with setFieldsOnGraphQLNodeType when triggered through the createRemoteFileNode. I was reading code while putting the kiddo to bed, and it seems like both errors (#15 and #18) originate from there. I won't have a chance to try any code for at least a few weeks though so feel free if anyone else has a chance to investigate.

jbolda commented 6 years ago

@brendanmc6 were you using any remark plugins? gatsby-remark-images perhaps?

brendanmc6 commented 6 years ago

@jbolda I will have to set up a test and try again-- might be a few days until I can get around to it.

github-actions[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had any recent activity for 30 days. It will be closed if no further activity occurs within 7 days. Remove stale label, comment, and/or apply "ongoing issue" label to prevent this from being closed. Thank you for your contributions.