UNPKG

phx-react

Version:

PHX REACT

62 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PHXClientQueryV5 = PHXClientQueryV5; exports.PHXClientMutationV5 = PHXClientMutationV5; const tslib_1 = require("tslib"); const axiosInstance_1 = require("../../../axiosInstance"); const constants_1 = require("../../../utils/constants"); const Sentry = tslib_1.__importStar(require("@sentry/nextjs")); const grpcQueryV5 = async ({ isDelay = true, query, variables, persistedId, hostname, isQuery, schemaGroup, }) => { let queryResult; const startTime = performance.now(); const pathUrl = isQuery ? '/query' : '/mutation'; try { queryResult = await axiosInstance_1.PHXAxiosInstance.post(pathUrl, { source: 'dashboard', query, variables, persisted_id: persistedId, schemaGroup, }, { headers: { hostname, [constants_1.HEADER_KEY_PATH_DASHBOARD]: window.location.pathname, }, }); } catch (error) { Sentry.captureException(error); throw new Error('Error with Axios request: ' + error.message); } const endTime = performance.now(); const duration = endTime - startTime; // Nếu thời gian gọi nhanh quá, delay thêm để tăng trải nghiệm loading không bị giật if (duration < constants_1.requestMaxDuration && isDelay) { console.info('promise delay v3...'); await new Promise((r) => setTimeout(r, 100)); } return queryResult; }; async function PHXClientQueryV5({ query, variables, isDelay = true, persistedId, hostname, schemaGroup, }) { return grpcQueryV5({ query, variables, isDelay, hostname: hostname || window.location.origin, persistedId, isQuery: true, schemaGroup, }); } async function PHXClientMutationV5({ query, variables, isDelay = true, persistedId, hostname, schemaGroup, }) { return grpcQueryV5({ query, variables, isDelay, hostname: hostname || window.location.origin, persistedId, isQuery: false, schemaGroup, }); } //# sourceMappingURL=PHXGrpcClientV5.js.map