Skip to content

Commit

Permalink
[E4E-0]: Make debug optional (happy @gsimionato-daitan ?)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCleric committed Jan 27, 2022
1 parent 13ff258 commit 004c401
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/types/restSchema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type Input<T> = T | (T & { input?: Record<string, never> }) | { input: T

export interface IEndpointOptions<T, U> {
endpoint: IRestEndpoint<T, U>;
debug?: boolean;
}

export type NamedGQLResult<Name extends string, TData = unknown> = {
Expand Down
19 changes: 12 additions & 7 deletions lib/useRestQuery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NamedGQLResult<TName, TData>, Input<TVariables>, TContext, TCache>(
mutation,
Expand Down Expand Up @@ -200,8 +202,10 @@ export function useRestQuery<TName extends string, TData, TVariables>(
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<NamedGQLResult<TName, TData>, WithHeaders<Input<TVariables>>>(
query,
Expand Down Expand Up @@ -265,9 +269,10 @@ export function useRestClientQuery<TName extends string, TData, TVariables>(
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<NamedGQLResult<TName, TData>, TVariables>(options);
}

Expand Down

1 comment on commit 004c401

@gsimionato-daitan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES.

Please sign in to comment.