-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
refactor(gatsby): Page dependency resolver #9732
Conversation
Trying to build gatsbyjs.org with this changes I'm getting theses errors:
I will do some research to hopefully pinpoint what change triggers this |
if (path) { | ||
const asArray = _.isArray(result) ? result : [result] | ||
for (const node of asArray) { | ||
// using module.exports here so it can be mocked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should split those into separate module/files if we want to mock it - this feels pretty hacky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I hated myself for doing it. But I couldn't figure out any other way to mock it properly (and had wasted hours on it by that point). Another module sounds like a good idea
const asArray = _.isArray(result) ? result : [result] | ||
for (const node of asArray) { | ||
// using module.exports here so it can be mocked | ||
module.exports.createPageDependency({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to check if node is defined here - null
can be passed and in that case we definitely don't want to try to create dependency as it will fail on accessing node.id
@pieh added check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
Anywhere in Gatsby where a graphql resolver returns a node, we need to declare a dependency from the node to the page `context.path`. This code is littered throughout `schema`. Eventually, it would be great to figure out an alternative way to declare these dependencies, since causing side effects in query resolvers isn't ideal, but in the mean time, this PR cleans up the code a bit by introducing a resolver middleware called `pageDependencyResolver`. It executes a given resolver and then creates a page dependency. Another alternative would be to use [graphql-middleware](https://github.com/prisma/graphql-middleware) to run this on all field resolvers. Perhaps another day.
Anywhere in Gatsby where a graphql resolver returns a node, we need to declare a dependency from the node to the page
context.path
. This code is littered throughoutschema
. Eventually, it would be great to figure out an alternative way to declare these dependencies, since causing side effects in query resolvers isn't ideal, but in the mean time, this PR cleans up the code a bit by introducing a resolver middleware calledpageDependencyResolver
. It executes a given resolver and then creates a page dependency.Another alternative would be to use graphql-middleware to run this on all field resolvers. Perhaps another day.