You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am considering approaches for integrating WPGraphQL on a search page powered by Elasticsearch where results will be ordered by relevance. I'd love to use cursor pagination, but I'm running into a wall and I could use some advice on the best way to approach it.
The issue that's most impactful is that WPGraphQL uses only the object's ID to generate a cursor, and that isn't customizable. This sets an expectation that an object (post, in my case) can independently provide relevant cursor information to navigate a list of nodes. In my use case, that doesn't work; my nodes are ordered by relevance, and a single post doesn't know its location in a set of search results. I do have the data that would allow me to paginate results using a cursor, though. I know the score of each search result and I could generate cursors based on the score, and use that to get the next set of results.
The best idea I've come up with is that I should create a new connection with my own custom extension of PostObjectConnectionResolver. With my own resolver, I think I should be able to replace the cursor with my own values. Is that the recommended approach, or am I missing a better option? I was hoping to be able to use the existing connections since I have Elasticsearch seamlessly integrated with WordPress otherwise. If I could seamlessly integrate this too, I could create a WPGraphQL extension that wouldn't require a developer to modify their search query, it would Just Work.
Not coincidentally, this may be relevant to #1818.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am considering approaches for integrating WPGraphQL on a search page powered by Elasticsearch where results will be ordered by relevance. I'd love to use cursor pagination, but I'm running into a wall and I could use some advice on the best way to approach it.
The issue that's most impactful is that WPGraphQL uses only the object's ID to generate a cursor, and that isn't customizable. This sets an expectation that an object (post, in my case) can independently provide relevant cursor information to navigate a list of nodes. In my use case, that doesn't work; my nodes are ordered by relevance, and a single post doesn't know its location in a set of search results. I do have the data that would allow me to paginate results using a cursor, though. I know the score of each search result and I could generate cursors based on the score, and use that to get the next set of results.
The best idea I've come up with is that I should create a new connection with my own custom extension of
PostObjectConnectionResolver
. With my own resolver, I think I should be able to replace the cursor with my own values. Is that the recommended approach, or am I missing a better option? I was hoping to be able to use the existing connections since I have Elasticsearch seamlessly integrated with WordPress otherwise. If I could seamlessly integrate this too, I could create a WPGraphQL extension that wouldn't require a developer to modify their search query, it would Just Work.Not coincidentally, this may be relevant to #1818.
Beta Was this translation helpful? Give feedback.
All reactions