mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
fix: hide missing token warning when disabled (#260)
Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com>
This commit is contained in:
parent
3f1b6edc97
commit
c0e08216b0
5 changed files with 61 additions and 2 deletions
5
.changeset/funny-mice-hunt.md
Normal file
5
.changeset/funny-mice-hunt.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': patch
|
||||
---
|
||||
|
||||
fix: enabled false will log in debug that hive is disabled
|
||||
|
|
@ -4,10 +4,15 @@ import type { HivePluginOptions, HiveClient } from './internal/types';
|
|||
import { createUsage } from './internal/usage';
|
||||
import { createReporting } from './internal/reporting';
|
||||
import { createOperationsStore } from './internal/operations-store';
|
||||
import { logIf } from './internal/utils';
|
||||
|
||||
export function createHive(options: HivePluginOptions): HiveClient {
|
||||
const logger = options?.agent?.logger ?? console;
|
||||
|
||||
if (!options.enabled) {
|
||||
logIf(options.debug === true, '[hive] is not enabled.', logger.info);
|
||||
}
|
||||
|
||||
if (!options.token && options.enabled) {
|
||||
options.enabled = false;
|
||||
logger.info('[hive] Missing token, disabling.');
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export interface SchemaReporter {
|
|||
}
|
||||
|
||||
export function createReporting(pluginOptions: HivePluginOptions): SchemaReporter {
|
||||
if (!pluginOptions.reporting) {
|
||||
if (!pluginOptions.reporting || pluginOptions.enabled === false) {
|
||||
return {
|
||||
report() {},
|
||||
async dispose() {},
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ interface UsageCollector {
|
|||
}
|
||||
|
||||
export function createUsage(pluginOptions: HivePluginOptions): UsageCollector {
|
||||
if (!pluginOptions.usage) {
|
||||
if (!pluginOptions.usage || pluginOptions.enabled === false) {
|
||||
return {
|
||||
collect() {
|
||||
return () => {};
|
||||
|
|
|
|||
49
packages/libraries/client/tests/enabled.spec.ts
Normal file
49
packages/libraries/client/tests/enabled.spec.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { createHive } from '../src/client';
|
||||
|
||||
test("should log that it's not enabled", async () => {
|
||||
const logger = {
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
};
|
||||
|
||||
const hive = createHive({
|
||||
enabled: false,
|
||||
debug: true,
|
||||
agent: {
|
||||
logger,
|
||||
},
|
||||
token: '',
|
||||
});
|
||||
|
||||
const result = await hive
|
||||
.info()
|
||||
.then(() => 'OK')
|
||||
.catch(() => 'ERROR');
|
||||
|
||||
expect(logger.info).toHaveBeenCalledWith(expect.stringContaining(`[hive] is not enabled.`));
|
||||
expect(result).toBe('OK');
|
||||
});
|
||||
|
||||
test("should not log that it's not enabled", async () => {
|
||||
const logger = {
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
};
|
||||
|
||||
const hive = createHive({
|
||||
enabled: false,
|
||||
debug: false,
|
||||
agent: {
|
||||
logger,
|
||||
},
|
||||
token: '',
|
||||
});
|
||||
|
||||
const result = await hive
|
||||
.info()
|
||||
.then(() => 'OK')
|
||||
.catch(() => 'ERROR');
|
||||
|
||||
expect(logger.info).not.toBeCalled();
|
||||
expect(result).toBe('OK');
|
||||
});
|
||||
Loading…
Reference in a new issue