T.T
T.T7mo ago

Accessing QueryFunctionContext within server queries

Hello, I know that the field 'direction' is a new addition within react query v5 as part of the QueryFunctionContext object https://tanstack.com/query/v5/docs/react/guides/query-functions#queryfunctioncontext and that work on compatibility with this version is happening in the 'next' release of TRPC. However, this is a more general question about accessing data within the QueryFunctionContext when utilising TRPC, despite my examples including the new field. If I were not to be using TRPC I would have access to that object as an argument in my query function and I would construct my URL with that data included. Obviously the benefits of TRPC include the automatic generation of my query function to a corresponding server procedure, however this process does not provide me access to the fields of the context on the server. Is there a good way to pass this field to my server procedures so that I could determine how to adapt my database queries for cursor based pagination? The motivating example would be: I have a cursor which is either the first Id of my nodes or the last Id of my nodes (relay pagination specification). I would then like to know if I should paginate backwards with the ID or forward. This field on the QueryFunctionContect would allow me to determine that. There are a few 'hacky' solutions I could think of such as storing the direction manually in a ref when pressing a button which then calls the fetchNextPage or fetchPreviousPage functions and with this pass the value in the ref as an input to my infiniteQuery but I'd like to avoid these if there are any good approaches already provided in the library. Thanks for your time and hard work on the library!
Query Functions | TanStack Query Docs
A query function can be literally any function that returns a promise. The promise that is returned should either resolve the data or throw an error. All of the following are valid query function configurations:
0 Replies
No replies yetBe the first to reply to this messageJoin