Skip to content

repro for #5000 #5001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

'use strict';
import type {RelayMockEnvironment} from '../../../relay-test-utils/RelayModernMockEnvironment';

Check failure on line 13 in packages/react-relay/relay-hooks/__tests__/useRefetchableFragmentNode-test.js

View workflow job for this annotation

GitHub Actions / JS Lint

Requires should be sorted alphabetically
import type {
useRefetchableFragmentNodeTest1FragmentRefetchQuery$data,
useRefetchableFragmentNodeTest1FragmentRefetchQuery$variables,
Expand Down Expand Up @@ -38,6 +38,7 @@
import type {OperationDescriptor, Variables} from 'relay-runtime';
import type {Query} from 'relay-runtime/util/RelayRuntimeTypes';

const {MockPayloadGenerator} = require('relay-test-utils');
const RelayEnvironmentProvider = require('../RelayEnvironmentProvider');
const useRefetchableFragmentInternal = require('../useRefetchableFragmentInternal');
const invariant = require('invariant');
Expand Down Expand Up @@ -822,6 +823,64 @@
expect(isOperationRetained(refetchQuery)).toBe(true);
});

it.only('refetches new variables correctly when refetching same id and queued resolver', () => {
const renderer = renderFragment();
const initialUser = {
id: '1',
name: 'Alice',
profile_picture: null,
...createFragmentRef('1', query),
};
expectFragmentResults([{data: initialUser}]);

// Mock network response upfront
environment.mock.queueOperationResolver(operation =>
MockPayloadGenerator.generate(operation, {
Node: () => ({
__typename: 'User',
id: '1',
name: 'Alice',
profile_picture: {
uri: 'scale32',
},
username: 'useralice',
}),
}),
);

TestRenderer.act(() => {
refetch({scale: 32});
});

// Assert that fragment is refetching with the right variables and
// suspends upon refetch
const refetchVariables = {
id: '1',
scale: 32,
};
refetchQuery = createOperationDescriptor(
gqlRefetchQuery,
refetchVariables,
{force: true},
);
expectFragmentIsRefetching(renderer, {
refetchVariables,
refetchQuery,
});

// Assert fragment is rendered with new data
const refetchedUser = {
id: '1',
name: 'Alice',
profile_picture: {
uri: 'scale32',
},
...createFragmentRef('1', refetchQuery),
};
expectFragmentResults([{data: refetchedUser}]);
expect(isOperationRetained(refetchQuery)).toBe(true);
});

it('with correct id from refetchable fragment when using nested fragment', () => {
// Populate store with data for query using nested fragment
TestRenderer.act(() => {
Expand Down
12 changes: 12 additions & 0 deletions packages/relay-test-utils/RelayModernMockEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@
const {id, text} = request;
const cacheID = id ?? text;

console.log('DEBUG: MockEnvironment.execute', {

Check warning on line 217 in packages/relay-test-utils/RelayModernMockEnvironment.js

View workflow job for this annotation

GitHub Actions / JS Lint

Unexpected console statement
request,
variables,
pendingOperations,
});

let cachedPayload = null;
if (
(cacheConfig?.force == null || cacheConfig?.force === false) &&
Expand All @@ -232,6 +238,12 @@
areEqual(op.request.variables, variables),
);

console.log('DEBUG: MockEnvironment.execute', {

Check warning on line 241 in packages/relay-test-utils/RelayModernMockEnvironment.js

View workflow job for this annotation

GitHub Actions / JS Lint

Unexpected console statement
currentOperation,
pendingOperations,
resolversQueueLength: resolversQueue.length,
});

// Handle network responses added by
if (currentOperation != null && resolversQueue.length > 0) {
const currentResolver = resolversQueue[0];
Expand Down
Loading