-
I am in the process of replacing Apollo Client with react-query and graphql-request in my project because I prefer react-query and I am already using it for non-graphql requests. Previously, with Apollo, I was able to set up Links and Contexts that acted like middlewares. This allowed me to start a timer on outgoing requests by storing the value of performance.now() in the request's context. When the response came back, I was able to compute the query execution time and log it in Elastic Search along with other useful information about the query. I am trying to do the same with react-query and graphql-request, but I am struggling to find the right approach. I tried storing the start timestamp in the query's context (using meta) within the query function, but then I was unable to find meta in the return value of the hook. My plan was to use this along with dataUpdatedAt to compute the request duration. Do you have any ideas on how I could achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
you can measure time right in the queryFn - before and after you fire the request, or directly on your "api layer". |
Beta Was this translation helpful? Give feedback.
I don't have any "api layer" here cause I'm requesting my GraphqlQL endpoint directly. Just to clarify, your other option would be to do something like this ?
I guess it could work, but doesn't it mean I'd have to handle error cases myself with try / catch ?