2.0.0-rc.1 & ^1.3 useFragment does not work with @relay(plural: true)
See original GitHub issueuseFragment seem to have issues processing an array of fragments passed down from useQuery, when the fragment passed to useFragment uses @relay(plural: true).
I receive: RelayModernGraphQLTag: Expected a fragment, got {} Error.
Same query & fragment work well with the react-relay hocs.
Example:
// fragment usage
type Props = {
items: ItemList_items$ref,
};
const ItemList: React.FC<Props> = props => {
const items: ItemList_items = useFragment(
graphql`
fragment ItemList_items on Item @relay(plural: true) {
# ...
}
`,
props.items
);
};
// query usage
const ItemListPage: React.FC<Props> = () => {
const {props, error} = useQuery<ItemListQuery>(
graphql`
query ItemListQuery {
items {
...ItemList_items
}
}
`, {}
);
// ... checks, etc.
return <ItemList items={props.items} />
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
GraphQL Directives | Relay
Relay uses directives to add additional information to GraphQL documents, which are used by the Relay compiler to generate the appropriate ...
Read more >How to get RelayJS to understand that a response from ...
You probably want a @relay(plural: true) directive on your cards query fragment. There is an example of a plural field in action in...
Read more >Relay directives | Martin Zlámal
The Relay compiler interprets the @alias directive, and generates types indicating that the fragment key, or inline fragment data, will be attached to...
Read more >relay-hooks from relay-tools - Coder Social
Use Relay as React hooks from Coder Social. ... relay-hooks v2.0.0 ... 2.0.0-rc.1 & ^1.3 useFragment does not work with @relay(plural: true).
Read more >React to Relay: local state management, part 3 - babangsund
Nothing is saved, until you press save. You cannot press save, unless all inputs are in a valid. The schema we will be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@morrys I guess the
createFragmentContainerworked with older style of import from older babel-relay-plugin. I upgraded the plugin and now alsouseFragmentworks! 😃.Thanks!
My hands now not on code (no access to it from home ^^), I will try it out tomorrow. Thanks!