user11569827
user11569827

Reputation: 165

Relay ConnectionHandler.getConnectionID() connection does not exist error

I'm trying to cleanup relay graphql flow in my app. Atm in some places I'm still using fetchKey and record invalidation, which I'd like to change to @appendEdge/@appendNode directives. Unfortunately every time I'm trying to get the proper connection on which I'm going to use them, it ends up with warnings stating:

Warning: [Relay][Mutation] The connection with id 'client:ParentType14nif3uirdfut431431hg2rr:__ParentTypeChildrenList_children_connection' doesn't exist.

I'm using ConnectionHandler.getConnectionID(<id of the parent object of the fragment>, <connection key I've specified>).

Does anyone know what may be the issue here? Also if I understand correctly and if that works my edge is supposed to be added to the store and relay will only determine whether everything is up-to-date without fetching that new edge from the server, right?

Upvotes: 0

Views: 1250

Answers (2)

Adam Jones
Adam Jones

Reputation: 19

Another way to acquire a connection id is to include '__id' in your response data, for example:

const tagQuery = graphql`
  query TagQuery($TagsByKeyInput: TagsByKeyInput!) {
    tagsByKey(input: $TagsByKeyInput) @connection(key: "Component_tags") {
      __id
      edges{
        ...rest
      }
    }
  }
`;

The __id in the return data is the connection id. hope this helps!

Upvotes: 0

Sebastian Cruz
Sebastian Cruz

Reputation: 65

Relay matches connection identity not only by the parent id and connection key but also using the latest arguments ("filters) that connection was called with. By passing filters: [] to the connection you're telling relay that no arguments should be used to determine connection identity. This can work sometimes but if your arguments actually affect the output of your connection this can introduced some unexpected behaviors, such as your connection results not updating when only some argument has changed. Alternatively you can pass the latest arguments you called your connection with to your getConnectionId call. This can be very verbose and difficult to do at times but there's no other work around.

From the docs: https://relay.dev/docs/guided-tour/list-data/updating-connections/#connection-identity-with-filters

Upvotes: 1

Related Questions