Search code examples
relayjsrelayrelaymodern

relay modern run RefetchContainer only manually


I still don't have much experience with relay modern and am trying to implement a search.

For this I use a "RefetchContainer":

export default createRefetchContainer(
    SearchComponent,
    {
    base: graphql`
      fragment SearchComponent_base on Base
      @argumentDefinitions(
        input: {type: "FireSearchInput!" defaultValue: {page: 0,queryString:""}}
        )
            {                
                    search(input: $input){
                    total
                    ...SearchResult_searchResult
                    }
            }
      `
    },
    graphql`
    query SearchComponentRefetchQuery($input: FireSearchInput!) {        
        ...SearchComponent_base @arguments(input: $input)
     }
    `
)

The problem is only that the query is already execute when you start the app, without an input is made.

Is it possible to suppress the automatic query and execute it only with the command this.props.relay.refetch?


Solution

  • the solution is to simply use a QueryRenderer:

    <QueryRenderer
      environment={environment}
      query={graphql`
        query SearchComponent($input: FireSearchInput!) {
            search(input: $input){
                 total
                 ...SearchResult_searchResult
               }
        }
      `}
      variables={{
        input: {///my input}
      }}