gatsbyjs/gatsby

ERROR #85901 GRAPHQL | gatsby-source-contentful requires Media uploaded to work

jingxuan98 opened this issue Β· 41 comments

Description

When I try to link my gatsby project with my self -created Contentful space, it shows this issue all the time

But when I try to link my gatsby to a contentful spaces with I created with their templates or examples, it runs fine

But for self created spaces, it shows this error....

Any solutions?

##Error Message

ERROR #85901 GRAPHQL

There was an error in your GraphQL query:

Unknown type "ContentfulFixed". Did you mean "ContentfulSecondTry", "ContentfulContentType", or "ContentfulSecondTryEdge"?

Environment

I was in the latest gatsby-source-contentful and gatsby.

Any solutions?

It's possible that you don't have any data for type Fixed in your self created space. Currently Contentful source needs data inside the types before it can generate it. We are fixing this in new version of contentful plugin, but currently you have to create something in your data table before it works.

I've got the same issue here

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Unknown type "ContentfulSizes". Did you mean "ContentfulPost", "ContentfulPostEdge", "ContentfulContentType", "ContentfulPostSortInput", or "ContentfulPostFieldsEnum"?

File: node_modules/gatsby-source-contentful/src/fragments.js:4:55

Can someone give me more information about it how I can fix this. I don't really get your response @freiksenet can you maybe explain it a bit further to me.. I'm just to dump to get it right now :(

pieh commented

@jingxuan98 @andrew-secret as temporary workaround, please add dummy image to contentful space. In #15344 (comment) one user said it works then.

@pieh thanks I'll try it out and let you know if it worked out πŸ‘

@jingxuan98 @pieh I can confirm that it worked for me too... thank u soo much πŸ’―

@jingxuan98 @pieh confirmed. Uploading an image to "Media" resolved errors. Thanks!

Thanks guys!

I don't have any media type in my content model. Is there any way to fix this without adding it?
Note: I've added a media type just with a dummy pic and it worked. However I would like not to do this.

ffael commented

It worked for me too! Thanks @pieh

I have the same error and I deleted all the content of the file: node_modules/gatsby-source-contentful/src/fragments.js and it's working.

This worked for me as well!

is this just going to be closed and not fixed? i dont think a workaround is considered a fix

Agree with @ryudice. Adding dummy data to my contentful space isn't an option. Just curious. I've used this package before without this issue. Anyone know how or when this bug was introduced?

add dummy image also work for me

I'm reopening this issue as adding dummy data workaround isn't a fix.

I ran into the issue because i wanted to add gatsby-source-contentful as a theme option but will have to get the user to add their gatsby site.

It's especially frustrating because people that clone down an OSS (or any) the project now need to create contentful space and addd an image just because gatsby-source-contentful is in package.json.

Tried what @maximechofflet mentioned and it worked, though it would randomly automatically break the app after 10 minutes.

@jingxuan98 @andrew-secret as temporary workaround, please add dummy image to contentful space. In #15344 (comment) one user said it works then.

Its worked for me, thank

Fixed by #12816

Please use the workarounds mentioned here or in the PR.

@pieh thank you!

If anyone was wondering what they meant by "adding dummy image there", follow these steps:

  1. Login to Contenify
  2. On the top navigation, select Media
  3. Upload any asset (I uploaded a 100px by 100px white square)
  4. Try rebuilding, and it just works

I have so many questions, but already wasted enough time on this to try to understand why that matters.

Hiya!

This issue has gone quiet. Spooky quiet. πŸ‘»

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! πŸ’ͺπŸ’œ

@pieh thank you!

If anyone was wondering what they meant by "adding dummy image there", follow these steps:

  1. Login to Contenify
  2. On the top navigation, select Media
  3. Upload any asset (I uploaded a 100px by 100px white square)
  4. Try rebuilding, and it just works

I have so many questions, but already wasted enough time on this to try to understand why that matters.

This has helped fix the issue temporarily. Thank you so much!

So when I installed contentful-source-gatsby and I added into the gatsby config file plugins. and then added the environmental variables for the space id and access token. it kept coming up with this error.

the space I was trying to connect to was empty.

I then added some content and an image into the the contentful space that was empty before. that pretty much fixed it. you can put some content in but you need to have a image in there.

Overall, There are 2 solutions to fix this problem:

  • solution 1: go to contentful and upload (publish) an image there.
  • solution 2: go to "node_modules/gatsby-source-contentful/src/fragments.js" and comment all the code, then save
    .
    After doing one of those solutions, run the project again.
    For me, I highly recommend you using the solution 1 so that the file "fragment.js" is still doing its job natively.

Not sure if this will work for others but I ran gatsby clean to clear the cache and it fixed this issue for me. I already had media assets in Contentful, however. The issue seems to reappear when I add new content. Clearing the cache again solves it for me.

An extra note on the "dummy image" - I believe you need to publish it too as it didn't work for me when in draft mode.

Not sure if this will work for others but I ran gatsby clean to clear the cache and it fixed this issue for me. I already had media assets in Contentful, however. The issue seems to reappear when I add new content. Clearing the cache again solves it for me.

this has worked for me. Thank you.

Seems like this was introduced #15284 (assumption of prior support based on leftover comments).

// Check if there are any ContentfulAsset nodes and if gatsby-image is installed. If so,
// add fragments for ContentfulAsset and gatsby-image. The fragment will cause an error
// if there's not ContentfulAsset nodes and without gatsby-image, the fragment is useless.
exports.onPreExtractQueries = async ({ store, getNodesByType }) => {
https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/src/gatsby-node.js#L243-L246

In the newer mode of query generation filtering out the gatsby-source-contentful fragments from creation inside the query-compiler.js removes the error.

https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/query/query-compiler.js#L137 on this line you can dump files=files.filter(d=>!d.includes('/gatsby-source-contentful/'))

just before the findGraphQLTags function in file-parser.js it seems reasonable it could also parse for some basic function that can once again check for the existence of assets in .cache/contentful/assets

This issue has now returned for me.

Hitting this issue again sadly.

Hello, a google search for this error brought me here :)
ERROR #85901 GRAPHQL contentful

I added an image to contentful as mentioned above and also did clear cache as mentioned above at the same time!

So I can't share which one fixed it but the compilation errors went away and the project was successfully built.

The dummy image is what fixed this issue for me. I don't use Contentful for images, so seems like an odd requirement to have at least one published image.

Tried gastby clean but that did not resolve issue. I can agree that adding a media asset removes the error.

It works for me too. Thanks )

Is there any development to this problem? I have the same issue if I don't upload a random picture to Contentful then it fails.

pieh commented

@lappang-cheung Did you try recent Gatsby version? gatsby@^2.21.29 might have a fix for it (assuming that you don't try to use those image fragments)

Creating an asset in the media tab also solved it for me

Getting this issue too=/ Already tried gatsby clean, adding an image - This is the error I am getting:
7:9 error Cannot query field "allContentfulBlogPost" on type "Query". Did you mean "allContentfulAsset", "contentfulAsset", or "allContentfulContentType"? graphql/template-strings

From the Contentful interface upload an image manually, restart your Gatsby developmente server, and you should be good to go πŸ‘ .