facebook / facebook/relay

Spread fragment through Connection

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

Description

# Bug
```
Invariant Violation: RelayConnectionTransform: Expected field `projects: ProjectNodeConnection` to have a edges selection in document `MenuQuery`
```
Relay compiler should notice that the fragment will spread with edges in the projects field, and pass without errors.

# Code
Query:
```
query MenuQuery($unitId: ID!) {
unit(id: $unitId) {
id
projects(first: 10) @connection(key: "Unit_projects") {
...MenuProjectList_list
}
}
}
```
fragment:
```
fragment MenuProjectList_list on ProjectNodeConnection {
edges {
node {
...MenuProjectItem_item
}
}
}
```

# Solution ?
I've tried many variations (trying to set the `@connection` within the fragment, trying to spread directly in unit instead of projects, etc. Nothing worked.

I use `@connection` a lot in order to update my lists after mutations. I'm unable to use fragments though, any suggestion to get fragments and @connection to play nicely until this relay-compiler bug gets fixed ? I will bypass my MenuProjectList component and directly call MenuProjectItem from my MenuQuery for now, but it lacks consistency with my other queries without `@connection`

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.