phx-react
Version:
PHX REACT
74 lines • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PHXGrpcQueryAllSchoolV6 = void 0;
exports.PHXClientQueryV6 = PHXClientQueryV6;
exports.PHXClientMutationV6 = PHXClientMutationV6;
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 grpcQueryV6 = async ({ isDelay = true, query, variables, persistedId, isQuery, schemaGroup, hostname, }) => {
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 && { hostname }), // hostname use to query all school
[constants_1.HEADER_KEY_PATH_DASHBOARD]: window.location.pathname,
...(!hostname && { [constants_1.HEADER_KEY_REQUIRED_SCHOOL_ID]: true }),
},
});
}
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 v6...');
await new Promise((r) => setTimeout(r, 100));
}
return queryResult;
};
async function PHXClientQueryV6({ query, variables, isDelay = true, persistedId, schemaGroup }) {
return grpcQueryV6({
query,
variables,
isDelay,
persistedId,
isQuery: true,
schemaGroup,
});
}
async function PHXClientMutationV6({ query, variables, isDelay = true, persistedId, schemaGroup }) {
return grpcQueryV6({
query,
variables,
isDelay,
persistedId,
isQuery: false,
schemaGroup,
});
}
const PHXGrpcQueryAllSchoolV6 = async ({ isDelay = true, query, variables, persistedId, schemaGroup, }) => {
return grpcQueryV6({
query,
variables,
isDelay,
hostname: constants_1.GRPC_HOSTNAME_QUERY_ALL_SCHOOL,
persistedId,
isQuery: true,
schemaGroup,
});
};
exports.PHXGrpcQueryAllSchoolV6 = PHXGrpcQueryAllSchoolV6;
//# sourceMappingURL=PHXGrpcClientV6.js.map