-
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
feat(gatsby): Allow alternative import syntax for useStaticQuery #20330
feat(gatsby): Allow alternative import syntax for useStaticQuery #20330
Conversation
I didn't know there was some transformation code outside of this plugin, so I also fix the part in the gatsby package. |
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.
Hi! This looks good. I have some styling issues that should be trivial to address. Please have a look and let me know what you think.
Thank you for your contribution!
I incorporated all feedback and improved the babel code a bit more. Including allowing the following syntax for page queries: import { graphql } from 'gatsby'
const query = graphql`
query PageQueryIndirect2 {
foo
}
`;
const query2 = query;
export { query2 }; Let me know what you think! |
@@ -337,42 +358,50 @@ export default function({ types: t }) { | |||
}, | |||
}) | |||
|
|||
function followVariableDeclarations(binding) { | |||
const node = binding.path ? binding.path.node : undefined |
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.
For future reference (not blocking on this right now) we can do const node = binding.path?.node
here now :D
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.
Ah ok! Pretty nice indeed!
Awesome! Thank you for your contribution 🚀 |
Holy buckets, @jfrolich — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Description
Currently useStaticQuery can only be imported like this to work:
I'm in process of writing bindings to Gatsby for ReasonML/Bucklescript. Currently it compiles every ES6 import like this
With this syntax the static query is not extracted in the babel plugin. This PR fixes that.
Documentation
I don't think this needs to be a documented feature. It is nice though that it works for people that prefer this syntax for various reasons, but it shouldn't be the sanctioned way to import useStaticQuery.