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

feat(gatsby): Allow alternative import syntax for useStaticQuery #20330

Merged
merged 5 commits into from
Jan 7, 2020

Conversation

jfrolich
Copy link
Contributor

Description

Currently useStaticQuery can only be imported like this to work:

import { useStaticQuery } from 'gatsby'

I'm in process of writing bindings to Gatsby for ReasonML/Bucklescript. Currently it compiles every ES6 import like this

import * as Gatsby from 'gatsby'
...
Gatsby.useStaticQuery(...)

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.

@jfrolich jfrolich requested a review from a team as a code owner December 29, 2019 15:35
@jfrolich jfrolich changed the title Allow alternative import syntax Allow alternative import syntax for useStaticQuery Dec 29, 2019
@jfrolich
Copy link
Contributor Author

I didn't know there was some transformation code outside of this plugin, so I also fix the part in the gatsby package.

@lannonbr lannonbr changed the title Allow alternative import syntax for useStaticQuery feat(gatsby): Allow alternative import syntax for useStaticQuery Dec 30, 2019
Copy link
Contributor

@pvdz pvdz left a 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!

@jfrolich
Copy link
Contributor Author

jfrolich commented Jan 7, 2020

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
Copy link
Contributor

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

Copy link
Contributor Author

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!

@pvdz
Copy link
Contributor

pvdz commented Jan 7, 2020

Awesome! Thank you for your contribution 🚀

@pvdz pvdz merged commit 17eaa72 into gatsbyjs:master Jan 7, 2020
@gatsbot
Copy link

gatsbot bot commented Jan 7, 2020

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:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants