Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relay-runtime 15.0.0 ConnectionHandler.getConnection() is undefined #4611

Open
shangwangzhang opened this issue Feb 2, 2024 · 2 comments
Open

Comments

@shangwangzhang
Copy link

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?

@DevYuns
Copy link

DevYuns commented Feb 5, 2024

@shangwangzhang Does your code run correctly on other versions?

@shangwangzhang
Copy link
Author

no, it doesn't work at all.

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

when passing with option in RecentSearches_viewer, I'm getting undefined. if there is parameter. it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants