6

My application looks something like what's included in the snippets below.

(I've left out a lot of the implementation details in the hopes that the code below is sufficient to get my question across).

SampleApp.js

const SampleAppQuery = graphql`
  list SampleAppQuery {
    ...ItemComponent_item
  }
`

function SampleApp() {
  return (
    <QueryRenderer
      environment={environment}
      query={SampleAppQuery}
      render={(error, props) => {
        if (props) {
          return <AppRefetchContainer list={props} />
        }
      }}
    />
  )
}

AppRefetchContainer.js

class AppRefetchContainer extends Component {
  render() {
    <div>
      <HeaderComponent refetchList={this._refetchList} />
      {list.map(item => <ItemComponent item={item} />)}
    </div>
  }

  _refetchList(params) {
    this.props.relay.refetch(params)
  }
}

export default createRefetchContainer(
  AppRefetchContainer,
  graphql`
    fragment AppRefetchContainer_list on Item {
      ...ItemComponent_item
    }
  `,
  graphql`
    query AppRefetchContainerQuery($sortBy: String!)
    list SampleAppQuery(sortBy: $sortBy) {
      ...ItemComponent_item
    }
  `
)

The initial application load is just fine. Clicking on one of the headers should trigger a refetch so that the list data can be sorted on the passed inparams. When I trigger a refetch, the server responds with the correct data, however, the component does not rerender.

I suspect that my issue is with the way I've defined the fragments here. The console error I get on initial page load is:

RelayModernSelector: Expected object to contain data for fragment
`AppRefetchContainer_list`, got `{"list":[{"__fragments":
{"ItemComponent_item":{}},"__id":"[some_valid_id]","__fragmentOwner":null},{...

Question(s):

  1. I'm not entirely sure how to interpret that error. Is it the reason why I'm unable to rerender the UI?

  2. I know this approach may not be ideal, but how do I refetch from a component that isn't necessarily a fragment of the query?

Happy to provide any clarification or missing context :)

0 Answers0