prismic-gatsby: Data returning null

Description: LocalFile and StructureText data is returned as null, whereas it is available in the dataRaw.

Data:

{
  "data": {
    "allPrismicPageTemplate": {
      "edges": [
        {
          "node": {
            "data": {
              "background_image": {
                "localFile": null
              },
              "left_content_copy": {
                "text": null
              }
            },
            "dataRaw": {
              "page_title": [
                {
                  "type": "heading1",
                  "text": "Test page template",
                  "spans": []
                }
              ],
              "background_image": {
                "dimensions": {
                  "width": 1667,
                  "height": 1003
                },
                "alt": null,
                "copyright": null,
                "url": "https://images.prismic.io/raecreative%2Fba4837cb-d2ed-42fb-9b68-4c8c9d4a5a8d_collection_management_campaign_editorial.jpg?auto=compress,format"
              },
              "left_content_copy": [
                {
                  "type": "paragraph",
                  "text": "Some left hand content",
                  "spans": []
                }
              ],
              "right_content_copy": [
                {
                  "type": "paragraph",
                  "text": "Some right hand content",
                  "spans": []
                }
              ],
              "right_content_video": {
                "link_type": "Media",
                "name": "RC Behind The Scenes FINAL_web quality.mp4",
                "kind": "document",
                "url": "https://raecreative.cdn.prismic.io/raecreative%2F6eb0e38b-827e-46d7-9695-3ce15a068ca1_rc+behind+the+scenes+final_web+quality.mp4",
                "size": "51702480"
              },
              "right_content_image": {
                "dimensions": {
                  "width": 3840,
                  "height": 5760
                },
                "alt": null,
                "copyright": null,
                "url": "https://images.prismic.io/raecreative%2F374a22bf-0ecd-4ef4-91da-e48eb73354f3_4.jpg?auto=compress,format"
              }
            }
          }
        }
      ]
    }
  }
}

Version: "gatsby-source-prismic": "^3.0.0-beta.14",

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 23 (8 by maintainers)

Most upvoted comments

Big thanks to @angeloashmore for his help.

tl;dr Make sure to use the correct API IDs for Prismic. Do not convert foo-bar to fooBar.

Summary

If your API ID in Prismic uses a - like in page-foo, make sure you use 'page-foo': require('./src/schemas/page-foo.json') the schema definition in your gatsby-config.js

✅ Correct

schemas: {
  'page-foo': require('./src/schemas/page-foo.json')
},

‼️ Wrong

schemas: {
  pageFoo: require('./src/schemas/page-foo.json')
},

This may look like it works, but it does not! The key for the data will not match up and you’ll get issues like this one here.

Improvements

As I understand @angeloashmore is planning to add some checks, to make sure this mistake gets detected automatically and you ll be warned.

Be aware

Technically you could setup two prismic types named foo-bar and fooBar. Just … just don’t do that, okay?

Hey @mrseanbaines (sorry for the delayed response!) and @larsenwork,

This definitely looks related to the transformFieldName option. I’ll investigate and let you know what I find!

Thanks @angeloashmore! I had to continue without the camelCasing so I’ll need to do some refactoring at some point to try this out. Will let you know how it goes when I get the chance

I can confirm that it fixes my issue. Thanks 🙏

I’m using the v4 beta plugin and I think I have a similar issue. I was camelCasing field names with the transformFieldName config option and also using the custom types API with the customTypesApiToken config option:

import camelCase from 'camelcase'

// ...
customTypesApiToken: process.env.PRISMIC_CUSTOM_TYPES_API_TOKEN,
transformFieldName: camelCase,

This initially seemed to work, as the field names were camelCased in the GraphiQL editor, but anything that was more than one word would just return null (since single word fields are the same in snake_case and camelCase):

image

When removing the transformFieldName option, it return the correct value (but no camelCasing ☹️):

image

Is this the same issue, or should I write up a separate issue for this @angeloashmore? This feels like a bug with the transformFieldName option (or maybe customTypesApiToken, or a combination of the two).

Version: "gatsby-source-prismic": "4.0.0-beta.17"

@rubas Yes, that would be helpful. Just the schema that’s failing should be enough. You could send me a secret Gist link via Twitter (@angeloashmore).