Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include tRPC client 'loggerLink' for dev debugging #296

Closed
t3dotgg opened this issue Aug 9, 2022 · 8 comments
Closed

Include tRPC client 'loggerLink' for dev debugging #296

t3dotgg opened this issue Aug 9, 2022 · 8 comments
Labels
📌 area: t3-app Relates to the generated T3 App 🔰 good first issue Good for newcomers 🌟 enhancement New feature or request 👨‍👦‍👦free for all Anyone is free to take on this issue and file a PR

Comments

@t3dotgg
Copy link
Member

t3dotgg commented Aug 9, 2022

tRPC has an awesome logger client built in for React Query that is a lifesaver

image

Adding the following to the _app.tsx trpc config will add them in dev

{
...
      links: [
        loggerLink({
          enabled: (opts) =>
            process.env.NODE_ENV === "development" ||
            (opts.direction === "down" && opts.result instanceof Error),
        }),
      ],
 }
@t3dotgg
Copy link
Member Author

t3dotgg commented Aug 9, 2022

Wait this appears to be broken now rip :(

@nexxeln
Copy link
Member

nexxeln commented Aug 9, 2022

lol, do we still want this then?

@c-ehrlich
Copy link
Member

if its possible to get it working in both tRPC v9 and v10 (or only v10 i guess), i think it would be a good thing to add. those console outputs are nice to have by default.

@t3dotgg
Copy link
Member Author

t3dotgg commented Aug 10, 2022

If we can get it working I definitely want it in dev mode

@henriqgoncalvs
Copy link
Contributor

Well, it worked here. But I had to use the httpBatchLink as well. With only the loggerLink I was getting a TypeError: link is not a function. Tested in other projects with trpc in version 9.26.2 and got the same error.

That log really helps in development, and I also find the httpBatchLink a good thing to add to trpc config. What do you think @theobr , do you still think it's useful to add the loggerLink and the httpBatchLink?

const links = [
      loggerLink({
        enabled: (opts) =>
          process.env.NODE_ENV === 'development' ||
          (opts.direction === 'down' && opts.result instanceof Error),
      }),
      httpBatchLink({
        maxBatchSize: 10,
        url,
      }),
    ];

return {
      url,
      transformer: superjson,
      links,
      /**
       * @link https://react-query.tanstack.com/reference/QueryClient
       */
      // queryClientConfig: { defaultOptions: { queries: { staleTime: 60 } } },
    };

image

@juliusmarminge juliusmarminge added 🌟 enhancement New feature or request 🔰 good first issue Good for newcomers 👨‍👦‍👦free for all Anyone is free to take on this issue and file a PR labels Aug 11, 2022
@Gejsi Gejsi mentioned this issue Aug 12, 2022
6 tasks
@juliusmarminge juliusmarminge added the 📌 area: t3-app Relates to the generated T3 App label Aug 13, 2022
@t3dotgg
Copy link
Member Author

t3dotgg commented Aug 20, 2022

@hnqg sorry just saw this now - yeah would be nice to add this I think

@juliusmarminge
Copy link
Member

juliusmarminge commented Aug 25, 2022

tRPC already batches requests by default so adding an explicit httpBatchLink seems scary (in the way we prescribe a default for how big your batches should be) unless it's really needed?

EDIT: Turns out it is needed, but we don't need to pass an explicit maxBatchSize

@kaminskypavel
Copy link

TIL that links order matters. here's the correct order

        links: [
            loggerLink({
                enabled: (opts) =>
                    isDevelopment() ||
                    (opts.direction === "down" && opts.result instanceof Error),
            }),

            httpBatchLink({
                url,
                headers: {
                    Authorization: `Bearer ${token}`
                }
            }),
        ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📌 area: t3-app Relates to the generated T3 App 🔰 good first issue Good for newcomers 🌟 enhancement New feature or request 👨‍👦‍👦free for all Anyone is free to take on this issue and file a PR
Projects
None yet
Development

No branches or pull requests

6 participants