facebook / facebook/relay

[Bug] Queuing resolvers doesn't work with refetchable fragments

Open
#5,000 2 comments 1 reaction 0 assignees View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hey folks,

In our project ([MS Nova repo](https://github.com/microsoft/nova-facade/tree/main/packages/nova-react-test-utils)) we rely heavily on `mock.queueOperationResolver` to prepare the environment for stories/unit tests. Recently, we found that the function doesn't behave as it should for resolving operations, meaning the resolver from queue is not executed at all. Here is a draft PR link which adds a test that fails (#5001), pasting it here for convenience as well:

```
it('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);
});
```

On the branch I added some debug logs and it seems that operation doesn't show up in `pendingOperations` and the resolver is not used at all.

The same test works when one uses `mock.resolve` or `mock.resolveMostRecentOperartion` but would be great if queuing resolvers also worked for refetchable operations.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.