Skip to content

Commit 00aabd0

Browse files
monicatangfacebook-github-bot
authored andcommitted
Fix client->client nullable model issue for PluralConcrete object output types
Reviewed By: captbaritone Differential Revision: D51870132 fbshipit-source-id: ffa35fb3c16128651457e638cc754c929f074d22
1 parent 97145fd commit 00aabd0

File tree

4 files changed

+497
-1
lines changed

4 files changed

+497
-1
lines changed

packages/react-relay/__tests__/RelayResolverNullableModelClientEdge-test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,34 @@ const {
2929
RelayFeatureFlags,
3030
graphql,
3131
} = require('relay-runtime');
32+
const {
33+
addTodo,
34+
} = require('relay-runtime/store/__tests__/resolvers/ExampleTodoStore');
3235
const LiveResolverStore = require('relay-runtime/store/experimental-live-resolvers/LiveResolverStore');
3336
const {createMockEnvironment} = require('relay-test-utils');
3437

38+
/**
39+
* CLIENT EDGE TO PLURAL LIVE STRONG CLIENT OBJECT
40+
*/
41+
42+
/**
43+
* @RelayResolver Query.edge_to_plural_live_objects_some_exist: [TodoModel]
44+
*/
45+
export function edge_to_plural_live_objects_some_exist(): $ReadOnlyArray<{
46+
id: DataID,
47+
}> {
48+
return [{id: 'todo-1'}, {id: 'THERE_IS_NO_TODO_WITH_THIS_ID'}];
49+
}
50+
51+
/**
52+
* @RelayResolver Query.edge_to_plural_live_objects_none_exist: [TodoModel]
53+
*/
54+
export function edge_to_plural_live_objects_none_exist(): $ReadOnlyArray<{
55+
id: DataID,
56+
}> {
57+
return [{id: 'NO_TODO_1'}, {id: 'NO_TODO_2'}];
58+
}
59+
3560
/**
3661
* CLIENT EDGE TO LIVE STRONG CLIENT OBJECT
3762
*/
@@ -158,6 +183,73 @@ describe.each([
158183
beforeEach(() => {
159184
environment = createEnvironment();
160185
});
186+
test('client edge to plural IDs, none have corresponding live object', () => {
187+
function TodoNullComponent() {
188+
const data = useClientQuery(
189+
graphql`
190+
query RelayResolverNullableModelClientEdgeTest_PluralLiveModelNoneExist_Query {
191+
edge_to_plural_live_objects_none_exist {
192+
id
193+
description
194+
}
195+
}
196+
`,
197+
{},
198+
);
199+
200+
invariant(data != null, 'Query response should be nonnull');
201+
expect(data.edge_to_plural_live_objects_none_exist).toHaveLength(2);
202+
return data.edge_to_plural_live_objects_none_exist
203+
?.map(item =>
204+
item
205+
? `${item.id ?? 'unknown'} - ${item.description ?? 'unknown'}`
206+
: 'unknown',
207+
)
208+
.join(',');
209+
}
210+
211+
const renderer = TestRenderer.create(
212+
<EnvironmentWrapper environment={environment}>
213+
<TodoNullComponent />
214+
</EnvironmentWrapper>,
215+
);
216+
expect(renderer.toJSON()).toEqual('unknown,unknown');
217+
});
218+
219+
test('client edge to plural IDs, some with no corresponding live object', () => {
220+
function TodoNullComponent() {
221+
const data = useClientQuery(
222+
graphql`
223+
query RelayResolverNullableModelClientEdgeTest_PluralLiveModel_Query {
224+
edge_to_plural_live_objects_some_exist {
225+
id
226+
description
227+
}
228+
}
229+
`,
230+
{},
231+
);
232+
233+
invariant(data != null, 'Query response should be nonnull');
234+
expect(data.edge_to_plural_live_objects_some_exist).toHaveLength(2);
235+
return data.edge_to_plural_live_objects_some_exist
236+
?.map(item =>
237+
item
238+
? `${item.id ?? 'unknown'} - ${item.description ?? 'unknown'}`
239+
: 'unknown',
240+
)
241+
.join(',');
242+
}
243+
244+
addTodo('Test todo');
245+
const renderer = TestRenderer.create(
246+
<EnvironmentWrapper environment={environment}>
247+
<TodoNullComponent />
248+
</EnvironmentWrapper>,
249+
);
250+
expect(renderer.toJSON()).toEqual('todo-1 - Test todo,unknown');
251+
});
252+
161253
test('client edge to ID with no corresponding live object', () => {
162254
function TodoNullComponent() {
163255
const data = useClientQuery(

packages/react-relay/__tests__/__generated__/RelayResolverNullableModelClientEdgeTest_PluralLiveModelNoneExist_Query.graphql.js

Lines changed: 198 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)