Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While giving Gatsby 4 a spin using gatsby-source-graphql, I found that DSG is not working :( #33906

Closed
pragmaticpat opened this issue Nov 9, 2021 · 5 comments · Fixed by #33977
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem) type: bug An issue or pull request relating to a bug in Gatsby

Comments

@pragmaticpat
Copy link
Contributor

While giving Gatsby 4 a spin using gatsby-source-graphql, I found that DSG is not working :(

I've set my codebase https://github.com/laurenskling/using-gatsby-source-graphql to defer rendering the film pages, and now these pages get an errors prop.

Example on Gatsby Cloud: https://build-58701a40-9907-423a-9f26-9f80e4b3beea.gtsb.io/ZmlsbXM6Mg== Saying: Cannot query field "swapi" on type "Query". So the entire external Graphql isn't found.

Building and serving locally I do no get this specific error, but another one. I'm getting in my errors prop:

{
  message: "nodeFetch is not a function"
  path: (2) ['swapi', 'film']
}

Originally posted by @laurenskling in #33218 (comment)

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 9, 2021
@LekoArts LekoArts added topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem) type: bug An issue or pull request relating to a bug in Gatsby and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Nov 15, 2021
@LekoArts
Copy link
Contributor

From #33218 (reply in thread)


Probably caused by the issue in node-fetch when bundled with webpack: node-fetch/node-fetch#450

The fix described in node-fetch/node-fetch#450 (comment) should probably help. I encourage you to submit a PR! I guess it should just change a single line:

const nodeFetch = require(`node-fetch`)

to:

const nodeFetch = require(`node-fetch`).default

But please double check if it works for you in normal develop/build workflow!

@LekoArts LekoArts added good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. labels Nov 15, 2021
@laurenskling
Copy link
Contributor

@laurenskling
Copy link
Contributor

This led me to investigate something.. Because gatsby-source-graphql allows you to bring your own fetch: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/gatsby-node.js#L42
and since nodeFetch was not a function, I tried passing something like cross-fetch to fix it, but that didn't do much.

Now I found, that fetch is undefined in the options when I log it out here: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/gatsby-node.js#L34 not during build time, but when starting with gatsby serve. (this is also true for createLink by the way.) I guess it goes thru something that doesn't accept functions in the object?

@LekoArts
Copy link
Contributor

LekoArts commented Nov 15, 2021

Functions are not serializable so when passed in through options they won't be working.

@laurenskling
Copy link
Contributor

Functions are not serializable so when passed in through options they won't be working.

Yeah this is what I figured. So now gatsby-source-graphql is able to run on the client, and passing functions doesn't work, this actually creates bugging experiences. The documentation states you can use fetch or createLink to add auth headers. So this will not be working in DSG. Should we change the docs, or?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem) type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants