-
Notifications
You must be signed in to change notification settings - Fork 1
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
Broken number interpolation #4
Comments
Thanks for the report! Haven't had a project with this GraphQL version so haven't noticed it. I'll have a look when I can. |
I still see the issue in v1.3.2… |
I think it's a problem when the arguments are on new lines: const ONE = 1
const query = /* GraphQL */ `
{
a(
a: ${ONE}
b: true
)
}
` |
That's odd as I've literally used your test case in the unit tests: const ONE = 1;
const TWO = 2;
const queryWithSpace = /* GraphQL */ `{
a(b: ${ONE} c: true)
}`;
const queryWithComma = /* GraphQL */ `{
a(b: ${ONE}, c: true)
}`;
const queryWithTrailingVariable = /* GraphQL */ `{
a(b: ${ONE} c: ${TWO})
}`; Is converted to: "use strict";
const ONE = 1;
const TWO = 2;
const queryWithSpace = `{a(b:${ONE} c:true)}`;
const queryWithComma = `{a(b:${ONE},c:true)}`;
const queryWithTrailingVariable = `{a(b:${ONE} c:${TWO})}`; I'll add another test with newlines |
Just checked and that also works: const queryWithNewlines = /* GraphQL */ `{
a(
b: ${ONE}
c: true
)
}`; Is converted to: const queryWithNewlines = `{a(b:${ONE} c:true)}`; Edit: See this commit |
Here is the source: Here is the result: fragment userArtworkConnection on UserArtworkConnection{page(cursor:$cursorArtwork limit:8ascending:false){hasNextPage cursorLast edges{node{id title price{format asCurrency{format(locale:"en-US")}}sold image{srcWebp:url(width:250height:250devicePixelRatio:3format:WEBP resourceHints:{preload:true})srcFallback:url(width:250height:250devicePixelRatio:3format:JPG)}}}}}fragment userGalleryConnection on UserGalleryConnection{page(cursor:$cursorGallery limit:8ascending:false){hasNextPage cursorLast edges{node{id name location{map(width:250height:150zoom:14pitch:55style:"mapbox/streets-v11" resourceHints:{preload:true})}}}}}query($userId:ID!,$cursorArtwork:ID,$cursorGallery:ID){user:node(id:$userId){... on User{name description{html(topHeadingLevel:2)}country{name emoji}region{name}gravatar(size:450,resourceHints:{preload:true})dateRegistered{relative}isAuthenticatedUser artworks{count ...userArtworkConnection}galleries{count ...userGalleryConnection}}}} |
It's working now! It was probably just some tooling aggressively caching Babel config or something. Pretty strange. |
I can only see the first part of that but const query = /* GraphQL */ `
fragment a on b {
page(
c: $var
d: ${ONE}
e: false
) {
hasNextPage
}
}
`; Is converted to: const query = `fragment a on b{page(c:$var d:${ONE} e:false){hasNextPage}}`; Are you sure you've upgraded correctly? |
Oh *pfew! Was starting to doubt myself 😄 Thanks again for the report! |
This input:
Incorrectly results in this output:
Which results in a query with invalid syntax:
This went unnoticed in my project for some time. GraphQL.js v15 no longer tolerates numbers being followed immediately with letters, and now the compressed queries are being rejected as having syntax errors:
I mistakenly thought at first this was a
graphql-query-compress
issue (rse/graphql-query-compress#14); but it turns out to definitely be an issue with this babel plugin.The text was updated successfully, but these errors were encountered: