barcadia icon indicating copy to clipboard operation
barcadia copied to clipboard

gatsby develop fails - "Cannot query field "references""

Open WebGuyJeff opened this issue 2 years ago • 6 comments

Great starter, thanks for sharing! ✌

I get this when running gatsby develop:

ERROR in 
/home/jeff/shadow/projects/barcadia-wordpress/src/pages/news/{contentfu
lPost.url}.js
  26:9  error  Cannot query field "references" on type
"ContentfulPostContent"  graphql/template-strings

I'm a Contentful noob, but as far as I can make out, references is reserved for paid Contentful plans, and as such the data isn't present upon syncing with a free account.

A quick fix for me was to remove this content from the Graphql query in src/pages/news/{contentfulPost.url}.js

Resulting in this:

export const data = graphql`
    query postQuery($id: String) {
        contentfulPost(id: { eq: $id }) {
        title
        introduction
        content {
            raw
        }
        createdAt(formatString: "DD MMMM, YYYY")
        }
    }
    `

Apart from one missing image, I haven't noticed any drastic impact and it's got me up and running.

WebGuyJeff avatar Feb 26 '22 11:02 WebGuyJeff

References in this context relates to embedded assets in content (things like images...). It's different to the paid-for option you see in Contentful. The demo was built using the free version of Contentful so you shouldn't come across anything that is not available to you.

By the looks of it, graphql throws an error if none of the posts have embedded assets.

In my example one of the posts, Toolkit has an embedded asset, but the others do not so it does not cause an error. I'll need to test this theory locally but I imagine this is what is happening.

I'll need to see if there is a way of creating some sort of fallback, checking if none of the posts have embedded content as a way of preventing the error.

bagseye avatar Feb 27 '22 11:02 bagseye

Thanks for the update, @bigupjeff. Resolved the errors on my end as well.

Image imports were hitting timeout limits resulting in missing referenced images causing fetch errors with 404's.

There was an error in your GraphQL query: Cannot query field "references" on type "ContentfulPostContent"

PanAmericano avatar Apr 04 '22 02:04 PanAmericano

Hi there. I had to remove the reference field from the query as well. While I was messing with the post on Contentful, I figured the references field is a paid feature also.

@bagseye So is it possible to add images to a post in Contentful within the free plan?

Screen Shot 2022-05-14 at 00 34 04

salihayazdir avatar May 13 '22 21:05 salihayazdir

I solved it 🥳🥳 Go to Contentful > Content Model > Post > Content (Rich Text) > Settings Make sure the Asset is activated in the Embedded entries & assets.

And then the references field is enabled in the GraphiQL

Screen Shot 2022-05-14 at 11 44 34 Screen Shot 2022-05-14 at 11 47 37

salihayazdir avatar May 14 '22 08:05 salihayazdir

@salihayazdir 's solution worked for me - BUT before it did, I had to add some media to one post

OliverHuntsman avatar Dec 18 '22 18:12 OliverHuntsman

I'm getting the following errors :

(node:19866) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit

the-anointed-one avatar Jan 24 '23 09:01 the-anointed-one