relay icon indicating copy to clipboard operation
relay copied to clipboard

relay-runtime 15.0.0 ConnectionHandler.getConnection() is undefined

Open shangwangzhang opened this issue 4 months ago • 2 comments

Here is my example query:

const viewerData = useLazyLoadQuery(graphql`
    query RecentSearchesQuery($filterOption: SavedSearchesWith) {
      viewer {
        ...RecentSearches_viewer @arguments(with: $filterOption)
      }
    }`,
    { filterOption },
    queryOptions,
  );

I'm passing filterOption to RecentSearchesQuery. here is fragment RecentSearches_viewer

const savedSearchesData = useFragment(graphql`
    fragment RecentSearches_viewer on Viewer
    @argumentDefinitions(
      first: {type: "Int", defaultValue: 10}
      with: {type: "SavedSearchesWith"}
    )
    {
      savedSearches(first: $first, with: $with)
      @connection(key: "RecentSearches_viewer__savedSearches") {
        edges {
          node {
            id
            query
          }
        }
      }
    }`,
    viewer
  );

when I'm going to update the store in the updater of mutation, I'm getting an error:

const savedSearchesConnection = ConnectionHandler.getConnection(
  viewer,
  'RecentSearches_viewer__savedSearches',
);

savedSearchesConnection is undefined. but when I didn't pass argument to RecentSearchesQuery, I don't get any error How can I resolve this issue?

shangwangzhang avatar Feb 02 '24 19:02 shangwangzhang