Skip to content

Commit

Permalink
Re-resolve fragments when their calls change
Browse files Browse the repository at this point in the history
Summary: Given a fragment with a range whose call is `first(1)` one moment, and `first(2)` the next, make sure that `GraphQLStoreQueryResolver::resolve()` re-resolves it.

Fixes #120.
Closes #146

Reviewed By: @josephsavona

Differential Revision: D2372922
  • Loading branch information
steveluscher committed Aug 27, 2015
1 parent ca28440 commit 72528e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/legacy/store/GraphQLStoreQueryResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ class GraphQLStoreSingleQueryResolver {
prevID != null &&
getCanonicalID(prevID) === getCanonicalID(nextID)
) {
if (this._hasDataChanged || !nextFragment.isEquivalent(prevFragment)) {
// same ID but the data, route and/or variables have changed
if (
prevID !== nextID ||
this._hasDataChanged ||
!nextFragment.isEquivalent(prevFragment)
) {
// same canonical ID,
// but the data, call(s), route, and/or variables have changed
[nextResult, subscribedIDs] = resolveFragment(nextFragment, nextID);
nextResult = recycleNodesInto(prevResult, nextResult);
} else {
Expand Down
25 changes: 25 additions & 0 deletions src/legacy/store/__tests__/GraphQLStoreQueryResolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ describe('GraphQLStoreQueryResolver', () => {
expect(resolvedB).toBe(mockResultB);
});

it('should re-resolve pointers whose calls differ', () => {
var fragmentPointerA = new GraphQLFragmentPointer(
'client:123_first(10)',
mockQueryFragment
);
var fragmentPointerB = new GraphQLFragmentPointer(
'client:123_first(20)',
mockQueryFragment
);

var resolver = new GraphQLStoreQueryResolver(
fragmentPointerA,
mockCallback
);

require('GraphQLStoreRangeUtils').getCanonicalClientID =
// The canonical ID of a range customarily excludes the calls
jest.genMockFunction().mockReturnValue('client:123');

resolver.resolve(fragmentPointerA);
resolver.resolve(fragmentPointerB);

expect(readRelayQueryData.mock.calls.length).toBe(2);
});

it('should invoke the callback when change events fire', () => {
var fragmentPointer = new GraphQLFragmentPointer(
'1038750002',
Expand Down

0 comments on commit 72528e3

Please sign in to comment.