-
Notifications
You must be signed in to change notification settings - Fork 223
[Bulk Ops CLI] remove extra newline from bulk mutation variables #6788
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
base: main
Are you sure you want to change the base?
Conversation
|
We detected some changes at Caution DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release. |
| '{"input":{"id":"gid://shopify/Product/1","title":"New Shirt"}}', | ||
| '{"input":{"id":"gid://shopify/Product/2","title":"Cool Pants"}}', | ||
| '{"input":{"id":"gid://shopify/Product/3","title":"Nice Hat"}}', | ||
| '', |
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.
(This empty string right here should've been a smoking gun indicating a bug before, but we all missed it in review!)
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success3684 tests passing in 1431 suites. Report generated by 🧪jest coverage report action from 1ad7094 |
| const {adminSession, variablesJsonl} = options | ||
|
|
||
| const buffer = Buffer.from(variablesJsonl ? `${variablesJsonl}\n` : '', 'utf-8') | ||
| const buffer = Buffer.from(variablesJsonl ?? '', 'utf-8') |
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.
Why did we add an extra ? here?
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.
Good question!! That is the nullish coalescing operator.
Basically, I first removed the \n, and I got this:
variablesJsonl ? variablesJsonl : ''This is a common pattern, and is of course equivalent to:
variablesJsonl || ''?? is an operator that works like ||, except that if the left value is defined-but-falsy (like e.g. ''), || will fall back to the right value, whereas ?? will respect that defined value.
In this case the only falsy value you'll reasonably get here is '', in which case whether we use that or the fallback we'll get an empty string either way. So, ?? and || are going to behave equivalently in all cases here.
I lean towards ?? by default because I don't want to think about JS's weird falsy values unless I have to, so I ended up with:
variablesJsonl ?? ''
WHY are these changes introduced?
Fixes https://github.com/shop/issues-api-foundations/issues/1313.
WHAT is this pull request doing?
Thanks to Rebecca's testing we discovered we're just... appending an extra newline, so if your input line already has one, we end up with an extra line? That's not right, so let's not do it.
I think this was being masked before because we were stripping whitespace, but since we've been changing whitespace handling, this is a real bug now.
How to test your changes?
Create
products.jsonlwith a trailing newline:{ "input": { "title": "Sweet new snowboard 1", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 2", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 3", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 4", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 5", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 6", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 7", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 8", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 9", "productType": "Snowboard", "vendor": "JadedPixel" } } { "input": { "title": "Sweet new snowboard 10", "productType": "Snowboard", "vendor": "JadedPixel" } }Then run this command:
On main: user error on the last line.
On this branch: no error on the last line!