Skip to content

Commit

Permalink
Add getFields() to RelayModernRecord
Browse files Browse the repository at this point in the history
Reviewed By: captbaritone

Differential Revision: D47799267

fbshipit-source-id: 2dda7056f6aaad8a6ea0ebbf095b838ecca1a2f7
  • Loading branch information
Ryan Holdren authored and facebook-github-bot committed Jul 26, 2023
1 parent 064b999 commit 7ba6387
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/relay-runtime/store/RelayModernRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ function getDataID(record: Record): DataID {
return (record[ID_KEY]: any);
}

/**
* @public
*
* Get the fields of a record.
*/
function getFields(record: Record): Array<string> {
return Object.keys(record);
}

/**
* @public
*
Expand Down Expand Up @@ -501,6 +510,7 @@ module.exports = {
create,
freeze,
getDataID,
getFields,
getInvalidationEpoch,
getLinkedRecordID,
getLinkedRecordIDs,
Expand Down
12 changes: 12 additions & 0 deletions packages/relay-runtime/store/__tests__/RelayModernRecord-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ describe('RelayModernRecord', () => {
});
});

describe('getFields()', () => {
it('returns an array with all the keys', () => {
const record = RelayModernRecord.getFields({
[ID_KEY]: '4',
[TYPENAME_KEY]: 'User',
name: 'Zuck',
pets: {[REFS_KEY]: ['beast']},
});
expect(record).toEqual([ID_KEY, TYPENAME_KEY, 'name', 'pets']);
});
});

describe('getValue()', () => {
let record;

Expand Down

0 comments on commit 7ba6387

Please sign in to comment.