3

Part of my route is set up like so:

<Route path=":widgetId" component={Widget} queries={{
    viewer: () => Relay.QL`query { viewer }`,
    widget: () => Relay.QL`query { widget(widgetId: $widgetId) }`
}}>
    <Route
        path="details"
        component={Details}
        queries={{ widget: () => Relay.QL`query { widget(widgetId: $widgetId) }` }}
    />
</Route>

However, I get the following error:

Error:  Invariant Violation: Relay(Details).getFragment(): `viewer` is not a valid fragment name. Available fragments names: `widget``.

Is the queries for route :widgetId valid? If I remove viewer from the top level route, everything works.

EDIT: here is the Details Fragment:

export default Relay.createContainer(Details, {
    fragments: {
        widget: () => Relay.QL`
            fragment on Widget {
                id,
            }
        `
    }
});

Edit: here are the Widget Fragments:

export default Relay.createContainer(Details, {
    fragments: {
        widget: () => Relay.QL`
            fragment on Widget {
                id,
            }
        `
        viewer: () => Relay.QL`
            fragment on Viewer {
                id,
            }
        `
    }
});

Note: I am using isomorphic-relay-router

jouerai
  • 135
  • 8
  • Have you defined fragment `viewer` in your `Widget` Relay container? – Ahmad Ferdous Jun 06 '16 at 18:57
  • @AhmadFerdous yes, the fragment viewer is in my Widget Relay container. If I take out the Route with path 'details' I don't get thrown the error. So I believe the error is coming from how queries are set up? – jouerai Jun 06 '16 at 19:14
  • `Invariant Violation: Relay(Details).getFragment()` <== looks like the problem is with the `Details` component. Can you add `fragments` of Relay container `Details`? – Ahmad Ferdous Jun 06 '16 at 22:59
  • @AhmadFerdous i have added the details fragment – jouerai Jun 07 '16 at 00:46
  • Did you have any luck in the end? I'm running into a nearly identical problem with react-router-relay. – Tim Hope Dec 07 '16 at 02:55

1 Answers1

0

It looks like you need to add a viewer fragment to your Widget class, i.e.:

export default Relay.createContainer(Widget, {
  fragments: {
    widget: () => Relay.QL`
      fragment on Widget {
        id,
      }
    `,
    viewer: () => Relay.QL`
      fragment on ObjectType {
        fields
      }
    `
  }
});
Jamie S
  • 76
  • 7
  • Hey @Jamie S, if you check out the comments above, you can see that I do have the viewer fragment in my widget class. The error also points at saying that `viewer` is not a valid fragment name in the Detail class – jouerai Jun 08 '16 at 22:05
  • I made a mistake in my answer which I noticed is also in your updated question. Not sure if it's a copy paste error but in the Widget code you using the Details class. Otherwise I can't see an issue within the code you've posted. It's pretty much identical to how I set up my routes with react-router-relay – Jamie S Jun 09 '16 at 10:52