question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2.0.0-rc.1 & ^1.3 useFragment does not work with @relay(plural: true)

See original GitHub issue

useFragment 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:closed
  • Created 4 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
akommcommented, Oct 29, 2019

@morrys I guess the createFragmentContainer worked with older style of import from older babel-relay-plugin. I upgraded the plugin and now also useFragment works! 😃.

Thanks!

1reaction
akommcommented, Oct 28, 2019

My hands now not on code (no access to it from home ^^), I will try it out tomorrow. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found