mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
38 lines
761 B
TypeScript
38 lines
761 B
TypeScript
import * as utils from 'dockest/test-helper';
|
|
import axios from 'axios';
|
|
|
|
const usageAddress = utils.getServiceAddress('usage', 3006);
|
|
|
|
export interface CollectedOperation {
|
|
timestamp?: number;
|
|
operation: string;
|
|
operationName?: string;
|
|
fields: string[];
|
|
execution: {
|
|
ok: boolean;
|
|
duration: number;
|
|
errorsTotal: number;
|
|
};
|
|
metadata?: {
|
|
client?: {
|
|
name?: string;
|
|
version?: string;
|
|
};
|
|
};
|
|
}
|
|
|
|
export async function collect(params: {
|
|
operations: CollectedOperation[];
|
|
token: string;
|
|
}) {
|
|
const res = await axios.post(`http://${usageAddress}`, params.operations, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-API-Token': params.token,
|
|
},
|
|
});
|
|
|
|
return {
|
|
status: res.status,
|
|
};
|
|
}
|