facebook / facebook/relay

Console error when trying to use directives to add node to connections on unit tests

Open
#3,779 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello, I'm testing a component that has a mutation that results in appending a new node to some connections.

Getting the connections:
```tsx
const switcherConnectionId = ConnectionHandler.getConnectionID(
id,
'ApplicationSwitcherConnection_applications',
);

const applicationsPageConnectionId = ConnectionHandler.getConnectionID(
id,
'ApplicationsPageConnection_applications',
);
```

Adding to the connections the new node:
```graphql
self @prependNode(
connections: $connections,
edgeTypeName: "ApplicationEdge"
) {
```

The test:
```tsx
const environment = createMockEnvironment();

render();

await userEvent.click(screen.getByRole('button', {name: 'submit'}));

const operation = await waitFor(() => environment.mock.getMostRecentOperation());

act(() => {
environment.mock.resolve(operation, MockPayloadGenerator.generate(operation, {
WebApplication() {
return {
slug: 'application',
};
},
}));
});
```

But when I'm running this test I'm getting the following error:
```
console.error
Warning: [Relay][Mutation] The connection with id 'client:id-workspace:__ApplicationSwitcherConnection_applications_connection' doesn't exist.
```

Is there something that I can do to resolve this `console.error`?

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.