mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 09:08:34 +00:00
Make the token optional when client is disabled (#710)
This commit is contained in:
parent
310d738e19
commit
d0357ee93a
3 changed files with 80 additions and 40 deletions
5
.changeset/five-kangaroos-divide.md
Normal file
5
.changeset/five-kangaroos-divide.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': patch
|
||||
---
|
||||
|
||||
Make token optional when Hive is disabled
|
||||
|
|
@ -7,6 +7,9 @@ export interface HiveClient {
|
|||
info(): Promise<void>;
|
||||
reportSchema: SchemaReporter['report'];
|
||||
collectUsage(args: ExecutionArgs): CollectUsageCallback;
|
||||
/**
|
||||
* @deprecated https://github.com/kamilkisiela/graphql-hive/issues/659
|
||||
*/
|
||||
operationsStore: OperationsStore;
|
||||
dispose(): Promise<void>;
|
||||
}
|
||||
|
|
@ -134,45 +137,55 @@ export interface HiveSelfHostingOptions {
|
|||
usageEndpoint?: string;
|
||||
}
|
||||
|
||||
export interface HivePluginOptions {
|
||||
/**
|
||||
* Enable/Disable Hive
|
||||
*
|
||||
* Default: true
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Debugging mode
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
debug?: boolean;
|
||||
/**
|
||||
* Access Token
|
||||
*/
|
||||
token: string;
|
||||
/**
|
||||
* Use when self-hosting GraphQL Hive
|
||||
*/
|
||||
selfHosting?: HiveSelfHostingOptions;
|
||||
agent?: Omit<AgentOptions, 'endpoint' | 'token' | 'enabled' | 'debug'>;
|
||||
/**
|
||||
* Collects schema usage based on operations
|
||||
*
|
||||
* Disabled by default
|
||||
*/
|
||||
usage?: HiveUsagePluginOptions | boolean;
|
||||
/**
|
||||
* Schema reporting
|
||||
*
|
||||
* Disabled by default
|
||||
*/
|
||||
reporting?: HiveReportingPluginOptions | false;
|
||||
/**
|
||||
* Operations Store
|
||||
*/
|
||||
operationsStore?: HiveOperationsStorePluginOptions;
|
||||
}
|
||||
type OptionalWhenFalse<T, KCond extends keyof T, KExcluded extends keyof T> =
|
||||
// untouched by default or when true
|
||||
| T
|
||||
// when false, make KExcluded optional
|
||||
| (Omit<T, KExcluded> & { [P in KCond]: false } & { [P in KExcluded]?: T[KExcluded] });
|
||||
|
||||
export type HivePluginOptions = OptionalWhenFalse<
|
||||
{
|
||||
/**
|
||||
* Enable/Disable Hive
|
||||
*
|
||||
* Default: true
|
||||
*/
|
||||
enabled?: boolean;
|
||||
/**
|
||||
* Debugging mode
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
debug?: boolean;
|
||||
/**
|
||||
* Access Token
|
||||
*/
|
||||
token: string;
|
||||
/**
|
||||
* Use when self-hosting GraphQL Hive
|
||||
*/
|
||||
selfHosting?: HiveSelfHostingOptions;
|
||||
agent?: Omit<AgentOptions, 'endpoint' | 'token' | 'enabled' | 'debug'>;
|
||||
/**
|
||||
* Collects schema usage based on operations
|
||||
*
|
||||
* Disabled by default
|
||||
*/
|
||||
usage?: HiveUsagePluginOptions | boolean;
|
||||
/**
|
||||
* Schema reporting
|
||||
*
|
||||
* Disabled by default
|
||||
*/
|
||||
reporting?: HiveReportingPluginOptions | false;
|
||||
/**
|
||||
* Operations Store
|
||||
*/
|
||||
operationsStore?: HiveOperationsStorePluginOptions;
|
||||
},
|
||||
'enabled',
|
||||
'token'
|
||||
>;
|
||||
|
||||
export type Maybe<T> = null | undefined | T;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,29 @@ test("should not log that it's not enabled", async () => {
|
|||
agent: {
|
||||
logger,
|
||||
},
|
||||
token: '',
|
||||
});
|
||||
|
||||
const result = await hive
|
||||
.info()
|
||||
.then(() => 'OK')
|
||||
.catch(() => 'ERROR');
|
||||
|
||||
expect(logger.info).not.toBeCalled();
|
||||
expect(result).toBe('OK');
|
||||
});
|
||||
|
||||
test('should not throw exception about missing token when disabled', async () => {
|
||||
const logger = {
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
};
|
||||
|
||||
const hive = createHive({
|
||||
enabled: false,
|
||||
debug: false,
|
||||
agent: {
|
||||
logger,
|
||||
},
|
||||
});
|
||||
|
||||
const result = await hive
|
||||
|
|
|
|||
Loading…
Reference in a new issue