Skip to content

Commit

Permalink
Fix regerssion in commitPayload on @defer
Browse files Browse the repository at this point in the history
Reviewed By: jstejada

Differential Revision: D19530111

fbshipit-source-id: 474df5156d500f3bca74d9ae3528b2263ed0c306
  • Loading branch information
tyao1 authored and facebook-github-bot committed Jan 23, 2020
1 parent e4bbc7d commit f2118d5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/relay-runtime/store/RelayModernEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class RelayModernEnvironment implements IEnvironment {
sink,
source: RelayObservable.from({
data: payload,
extensions: {is_final: true},
}),
store: this._store,
updater: null,
Expand Down
13 changes: 7 additions & 6 deletions packages/relay-runtime/store/RelayModernQueryExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,13 @@ class Executor {
this._processIncrementalPlaceholder(payload, incrementalPlaceholder);
});

if (this._state === 'loading_final') {
// The query has defer/stream selections that are enabled, but the
// server indicated that this is a "final" payload: no incremental
// payloads will be delivered. If it's not a client payload, warn that
// the query was (likely) executed on the server in non-streaming mode,
// with incremental delivery disabled.
if (this._isClientPayload || this._state === 'loading_final') {
// The query has defer/stream selections that are enabled, but either
// the server indicated that this is a "final" payload: no incremental
// payloads will be delivered, then warn that the query was (likely)
// executed on the server in non-streaming mode, with incremental
// delivery disabled; or this is a client payload, and there will be
// no incremental payload.
warning(
this._isClientPayload,
'RelayModernEnvironment: Operation `%s` contains @defer/@stream ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,88 @@ describe('commitPayload()', () => {
'ActorQuery',
);
});

it('applies payload on @defer fragments in a query with modules', () => {
const id = '4';
const query = generateAndCompile(`
query ActorQuery {
me {
name
nameRenderer {
...MarkdownUserNameRenderer_name
@module(name: "MarkdownUserNameRenderer.react")
}
...UserFragment @defer
}
}
fragment MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {
__typename
markdown
}
fragment UserFragment on User {
username
}
`);

environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store,
operationLoader: {
get: () => {
return query.MarkdownUserNameRenderer_name;
},
load: jest.fn(),
},
});

operation = createOperationDescriptor(query.ActorQuery, {});

const selector = createReaderSelector(
query.UserFragment,
id,
{},
operation.request,
);

const queryCallback = jest.fn();
const fragmentCallback = jest.fn();
const querySnapshot = environment.lookup(operation.fragment);
const fragmentSnapshot = environment.lookup(selector);
environment.subscribe(querySnapshot, queryCallback);
environment.subscribe(fragmentSnapshot, fragmentCallback);
expect(queryCallback.mock.calls.length).toBe(0);
expect(fragmentCallback.mock.calls.length).toBe(0);
environment.commitPayload(operation, {
me: {
id,
__typename: 'User',
nameRenderer: {
__typename: 'MarkdownUserNameRenderer',
__module_component_ActorQuery: 'MarkdownUserNameRenderer.react',
__module_operation_ActorQuery:
'MarkdownUserNameRenderer_name$normalization.graphql',
markdown: 'markdown payload',
},
name: 'Zuck',
username: 'Zucc',
},
});
expect(queryCallback.mock.calls.length).toBe(1);
expect(fragmentCallback.mock.calls.length).toBe(2);
expect(fragmentCallback.mock.calls[0][0].data).toEqual({
username: undefined,
});
expect(fragmentCallback.mock.calls[1][0].data).toEqual({
username: 'Zucc',
});
expect(warning).toBeCalledWith(
true,
expect.stringContaining(
'RelayModernEnvironment: Operation `%s` contains @defer/@stream directives',
),
'ActorQuery',
);
});
});

0 comments on commit f2118d5

Please sign in to comment.