Skip to content

Commit

Permalink
fix: json column key start with an underscore is missing (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
n3n authored Jul 27, 2022
1 parent 182aa3e commit b757809
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/getResponseParser/sanitizeResource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,29 @@ describe('sanitizeResource', () => {
'1': { name: 'brand', value: null },
});
});

it('Should skip key with two underscores', () => {
expect(
sanitizeResource([
{
name: 'vendor',
value: 'Test Vendor',
metadata: {
_key: 'value',
fields: [{ _type: 'string', name: 'title' }],
},
__typename: 'name',
},
])
).toEqual({
'0': {
name: 'vendor',
value: 'Test Vendor',
metadata: {
_key: 'value',
fields: [{ _type: 'string', name: 'title' }],
},
},
});
});
});
3 changes: 2 additions & 1 deletion src/getResponseParser/sanitizeResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const sanitizeResource = (data: any = {}): object => {
const result = Object.keys(data).reduce((acc, key) => {
if (key.startsWith('_')) {
// intend to remove the following reserved names https://spec.graphql.org/draft/#sec-Names.Reserved-Names
if (key.startsWith('__')) {
return acc;
}

Expand Down

0 comments on commit b757809

Please sign in to comment.