-
Notifications
You must be signed in to change notification settings - Fork 16
Ensure that arrays are properly supported #29
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
Ensure that arrays are properly supported #29
Conversation
|
||
// Extract the position | ||
if (Array.isArray(element)) { | ||
element = element[index!] || null; |
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.
What is the !
for?
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.
aaah https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator, learned something new! Thanks!
if (response === null || typeof response !== 'object') return response; | ||
|
||
// Extract the key | ||
let element = response[key]; |
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.
getting a linting error here, this should be const
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.
right can you fix it since the PR is merge?
|
||
return newResults; | ||
return curResults.reduce( | ||
(reducedResults, _, index) => callback(reducedResults, curPathElm, index), |
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.
right, I see what you're doing here. We don't have enough info to rewrite child array just on the parent object and the key. I think this is the best fix we can do while keeping the style as close to the current style as possible. 👍
@@ -3,7 +3,7 @@ import ScalarFieldToObjectFieldRewriter from '../../src/rewriters/ScalarFieldToO | |||
import { gqlFmt } from '../testUtils'; | |||
|
|||
describe('Rewrite scalar field to be a nested object with a single scalar field', () => { | |||
it('rewrites a scalar field to be an objet field with 1 scalar subfield', () => { | |||
it('rewrites a scalar field to be an object field with 1 scalar subfield', () => { |
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.
😅 thanks for fixing!
🎉 This PR is included in version 3.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@chanind I would change the message in the release to explain the bug for future reference. |
crap, I thought that semantic-release would have done that automatically. Let me see if I can change it after the fact... |
👍 OK should be fixed! |
The latest release broke the output for arrays (basically all arrays got mapped to an array of arrays). I started by fixing that and then I realized it would require a large rewrite to really support arrays properly. So this doesn't introduce a breaking change per the interface, but it does break the contract of
rewriteResponse
. I added test cases so this cannot happen again.