mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
35 lines
962 B
TypeScript
35 lines
962 B
TypeScript
import type { Plugin } from '@envelop/types';
|
|
import { createHive } from './client.js';
|
|
import type { HiveClient, HivePluginOptions } from './internal/types.js';
|
|
import { isHiveClient } from './internal/utils.js';
|
|
|
|
export function useHive(clientOrOptions: HiveClient): Plugin;
|
|
export function useHive(clientOrOptions: HivePluginOptions): Plugin;
|
|
export function useHive(clientOrOptions: HiveClient | HivePluginOptions): Plugin {
|
|
const hive = isHiveClient(clientOrOptions)
|
|
? clientOrOptions
|
|
: createHive({
|
|
...clientOrOptions,
|
|
agent: {
|
|
name: 'hive-client-envelop',
|
|
...(clientOrOptions.agent ?? {}),
|
|
},
|
|
});
|
|
|
|
void hive.info();
|
|
|
|
return {
|
|
onSchemaChange({ schema }) {
|
|
hive.reportSchema({ schema });
|
|
},
|
|
onExecute({ args }) {
|
|
const complete = hive.collectUsage(args);
|
|
|
|
return {
|
|
onExecuteDone({ result }) {
|
|
complete(result);
|
|
},
|
|
};
|
|
},
|
|
};
|
|
}
|