datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

Multi-paragraph text fields unable to query markdown #210

Closed claygiffin closed 1 year ago

claygiffin commented 1 year ago

After updating to v5.0.x, it appears that you've changed the way multi-paragraph text fields are queried.

If I am understanding correctly, although I can't find any documentation on this, we would now query:

    body(markdown:true)

instead of

    body { childMarkdownRemark { html } }

But now I get the error message Unknown argument "markdown" on field "body".

The only thing that I can query properly now is the untransformed markdown.

What is the proper way to handle this query now?

mordonez commented 1 year ago

I have the same problem, when updating to Gatsby 5 the schema for text fields with markdown can no longer be queried with GraphQL

For example, this query that works in Gatsby 4:

text
textNode {
  childMarkdownRemark {
    html
  }
}

now returns the following error:

Cannot query field "textNode" on type "DatoCmsTranscription".

If you don't expect "textNode" to exist on the type "DatoCmsTranscription" it is most likely a typo. However, if you expect "textNode" to exist there are a couple of
solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node/gatsby-config, please try a restart of your development server.
- You want to optionally use your field "textNode" and right now it is not used anywhere.

It is recommended to explicitly type your GraphQL schema if you want to use optional fields.

Querying the GraphiQL is correct, the field textNode no longer exists in Gatsby 5

imagen

Here is the same query with Gatsby 4

imagen

What is the best way to fix this issue and update to Gatsby 5?

floriangosse commented 1 year ago

I've upgraded the datocms plugin to the v5 and I have the same problem with the childMarkdownRemark on the non existing field *Node. So this is actually a critical bug and should be fixed urgent as it is completely incompatibly with plugins like remark.

Maybe @stefanoverna can have a look into it.

matjack1 commented 1 year ago

@claygiffin @mordonez @floriangosse I confirm that this functionality is not present anymore on our source plugin v5. If you really need it you can use the v4 of our plugin for now.

The reason why this functionality has been removed is because it was creating too many nodes, in particular one per markdown field, per record, per locale. In an effort to improve the performance of our plugin we have removed this feature.

We are understanding where this functionality should live. So for now either use v4 or render the HTML in the front end code of your Gatsby site. More news on this as soon as we decide where to go.

floriangosse commented 1 year ago

@matjack1 Thanks for the update.

I confirm that this functionality is not present anymore on our source plugin v5. If you really need it you can use the v4 of our plugin for now.

The problem with using the v4 is that it can't be used with Gatsby 5 because the peer dependency only allows Gatbsy 4 as max version.

More news on this as soon as we decide where to go.

Do you know when you know more about it?

mordonez commented 1 year ago

My workaround was to convert the markdown to html directly in frontend . I've used the marked library that comes as dependency

import { marked } from 'marked'
...
            <div
              className={transStyles.content}
              dangerouslySetInnerHTML={{
                __html: marked.parse(page.transcription.text)
              }}
            />
floriangosse commented 1 year ago

@mordonez I thought about it as well but decided against it because it means an additional library will be sent to the client and increases the load time.

matjack1 commented 1 year ago

@mordonez I thought about it as well but decided against it because it means an additional library will be sent to the client and increases the load time.

not necessarily, right? If you statically build your HTML pages can't you generate the HTML at build time? In that case you are using the same dependencies, but instead of being us to manage it in our source plugin, it's in your code. What do you think?

sistrall commented 1 year ago

Hi @claygiffin @mordonez @floriangosse

I just opened a PR that introduces Markdown support for gatsby-source-datocms version 5.

Let me know if you have the chance to test the branch. :-)

sistrall commented 1 year ago

Hey @claygiffin @mordonez @floriangosse

I merged the PR I opened some time ago to cook a pre-minor release: so it should be easier to test the new features.

Should you need help, I'm here.

floriangosse commented 1 year ago

I now had the time to test it out as I was working on the project. It looks good right now. Was only able to test it with Gatsby v4 as the migration to Gatsby v5 takes some time.

akrawchyk commented 1 year ago

@sistrall i tested your 5.1.0-0 prerelease on a v5 project, looks good

sistrall commented 1 year ago

Thanks @floriangosse and @akrawchyk,

I just released a proper 5.1.0 version.