Sub route queries error for react-router-relay

435 views Asked by At

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

1

There are 1 answers

2
Jamie S On

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
      }
    `
  }
});