From 004c401f231d264b239b1d35f18fd71c6de416a9 Mon Sep 17 00:00:00 2001 From: Adam Weeden Date: Wed, 26 Jan 2022 23:34:57 -0500 Subject: [PATCH] [E4E-0]: Make debug optional (happy @gsimionato-daitan ?) --- lib/types/restSchema/index.ts | 1 + lib/useRestQuery/index.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/types/restSchema/index.ts b/lib/types/restSchema/index.ts index c3b0158..d6bca2c 100644 --- a/lib/types/restSchema/index.ts +++ b/lib/types/restSchema/index.ts @@ -35,6 +35,7 @@ export type Input = T | (T & { input?: Record }) | { input: T export interface IEndpointOptions { endpoint: IRestEndpoint; + debug?: boolean; } export type NamedGQLResult = { diff --git a/lib/useRestQuery/index.ts b/lib/useRestQuery/index.ts index d85ae81..f0dde0e 100644 --- a/lib/useRestQuery/index.ts +++ b/lib/useRestQuery/index.ts @@ -128,8 +128,10 @@ export function useRestMutation< directives.push(dummyDirectives[0]); } - // eslint-disable-next-line no-console - console.debug('useRestMutation', { mutation: print(mutation), options }); + if (options.debug) { + // eslint-disable-next-line no-console + console.debug('useRestMutation', { mutation: print(mutation), options }); + } // eslint-disable-next-line react-hooks/rules-of-hooks return useMutation, Input, TContext, TCache>( mutation, @@ -200,8 +202,10 @@ export function useRestQuery( directives.push(dummyDirectives[0]); } - // eslint-disable-next-line no-console, sort-keys - console.debug('useRestQuery', { query: print(query), options }); + if (options.debug) { + // eslint-disable-next-line no-console, sort-keys + console.debug('useRestQuery', { query: print(query), options }); + } // eslint-disable-next-line react-hooks/rules-of-hooks return useQuery, WithHeaders>>( query, @@ -265,9 +269,10 @@ export function useRestClientQuery( directives.push(dummyDirectives[0]); } - // eslint-disable-next-line no-console, sort-keys - console.debug('useRestClientQuery', { query: print(options.query), options }); - + if (options.debug) { + // eslint-disable-next-line no-console, sort-keys + console.debug('useRestClientQuery', { query: print(options.query), options }); + } return options.client.query, TVariables>(options); }