Skip to content

Commit

Permalink
Document current behavior of server edges returning null
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D52264620

fbshipit-source-id: cdc72b3144d447a057ee5a994a00fbfd7f7f7c6a
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jan 9, 2024
1 parent 361d0b3 commit 8ef4b47
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/react-relay/__tests__/ClientEdges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ describe('ClientEdges', () => {
expect(renderer?.toJSON()).toBe('Alice');
});

it('should fetch and render `null` for client-edge query that returns `null`.', () => {
// The Relay store does not have a concept of _records_ being null. This means that when a Node
// query returns null, we can't actally write to the store "The record with this ID is null".
// Instead, we just write that `node(id: 4): null` into the root record in the store.
//
// This is a general limitiaton of node fetches in Relay today.
it('should fetch and render `undefined` for client-edge to server query that returns `null`.', () => {
function TestComponent() {
return (
<RelayEnvironmentProvider environment={environment}>
Expand All @@ -161,6 +166,9 @@ describe('ClientEdges', () => {
`,
variables,
);
if (data.me?.client_node === undefined) {
return 'client_node is undefined';
}
return data.me?.client_node?.name ?? 'MISSING';
}

Expand Down Expand Up @@ -192,7 +200,8 @@ describe('ClientEdges', () => {
networkSink.complete();
jest.runAllImmediates();
});
expect(renderer?.toJSON()).toBe('MISSING');
expect(renderer?.toJSON()).toBe('client_node is undefined');
expect(fetchFn.mock.calls.length).toBe(1);
});

it('should throw for missing client-edge field data marked with @required', () => {
Expand Down

0 comments on commit 8ef4b47

Please sign in to comment.