-
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
A way to extract graphql queries when tagged template literal is not available? #20311
Comments
Sadly, this is not possible at the moment. Tagged templates are a convenient way to extract data from JS AST at build time and we rely on them heavily. Technically, we could provide a way to override the default parsing, but it will have significant maintenance costs. Also, other client-side GraphQL libraries also rely on tagged templates to extract persisted queries. So I guess it makes sense to request interop support for them in Bucklescript. Or maybe try using existing escape hatches? |
Why is it a tagged template literal (as a string is just being passed in)? Would be nice to be able to do |
We don't execute this function. Queries are extracted from JS sources during the compile step to perform validation, fragment insertion, deduplication, etc. In fact, executing it is treated as error. We use tagged templates for several reasons:
const query = `{ foo }`
export const result = graphql(query) While in reality, they can't - we need an argument to be a literal value (which is precisely why tagged templates are such a good fit here). |
It would be nice to -- as an escape hatch -- allow |
I think we can accept a PR that would enable this if it doesn't add too much complexity. Thanks for suggesting this! |
Actually I dove in the internals, and the TaggedTemplate literal is used everywhere to identify graphql queries, so I think this would be tricky. I guess we need to wait for Bucklescript to adopt tagged template literals in some way. |
since the tagged template literal is just a helper to extract the (first/last/only one) query text from the js via the JS AST. maybe an other idea is: save the graphql query in an separate file with the same file name and the
|
@jfrolich It isn't likely that we'll be adding support for I would suggest the escape hatches that @vladar linked to. Thank you so much. Let's close this issue. |
Yes I figured that out. There is actually a hacky way to generate tagged template literals in Bucklescript, and I opened a ticket to have proper language support for generating tagged template literals. I think that indeed makes most sense! Thanks for engaging. |
This is one the only things that makes bucklescript with gatsby less attractive than bucklescript with nextjs. How does typescript deal with this? |
I like to create bindings to Bucklescript for Gatsby.
However it's not possible to output tagged template literals in Bucklescript. Is there a way to extract graphql queries with gatsby without using tagged template literals?
The text was updated successfully, but these errors were encountered: