-
Notifications
You must be signed in to change notification settings - Fork 85
/
envelop.ts
35 lines (31 loc) · 962 Bytes
/
envelop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { Plugin } from '@envelop/types';
import type { HiveClient, HivePluginOptions } from './internal/types.js';
import { createHive } from './client.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);
},
};
},
};
}