reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.71k stars 1.17k forks source link

[graphql-request-base-query] There aren't ability to get "extensions" inside query/queryFn/onQueryStarted #4022

Open rewweRrr opened 9 months ago

rewweRrr commented 9 months ago

Problem: Ability to get response information (GraphQLClientResponse) has only in middleware layer. Solution: Provide more information into meta

new GraphQLClient(url, {
    responseMiddleware: response => {
        console.log(response);
    }
});

Current code: https://github.com/reduxjs/redux-toolkit/blob/0d1f7101e83865714cb512c850bc53ffaee2d5e5/packages/rtk-query-graphql-request-base-query/src/index.ts#L42-L49

Suggestion:

            const { query } = resolveRequestDocument(document);

            const response = await client.rawRequest({
                query,
                variables,
                signal,
                requestHeaders: preparedHeaders
            });

            return {
                data: response.data,
                meta: {
                    baseQueryMeta: { response } // smth like this...
                }
            };
rewweRrr commented 9 months ago

@phryneas , can I count on such changes?

phryneas commented 9 months ago

I'll look into it at some point (that's why I assigned it to myself), but right now I'm extremely tight with time and this one will require testing with all supported graphql-request versions, so it's quite time intensive. So, probably,if it works in all versions, but no guarantee on a timeline.