2020-09-20 22:30:17 +02:00
|
|
|
import { gql, useQuery } from "@apollo/client";
|
2022-01-28 20:20:15 +01:00
|
|
|
import { Box, Grid, Paper, CircularProgress } from "@mui/material";
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
import ResponseDetail from "./ResponseDetail";
|
|
|
|
import RequestDetail from "./RequestDetail";
|
2022-01-28 20:20:15 +01:00
|
|
|
import Alert from "@mui/lab/Alert";
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
const HTTP_REQUEST_LOG = gql`
|
|
|
|
query HttpRequestLog($id: ID!) {
|
|
|
|
httpRequestLog(id: $id) {
|
|
|
|
id
|
|
|
|
method
|
|
|
|
url
|
2020-09-21 22:27:10 +02:00
|
|
|
proto
|
2020-09-24 00:13:14 +02:00
|
|
|
headers {
|
|
|
|
key
|
|
|
|
value
|
|
|
|
}
|
2020-09-20 22:30:17 +02:00
|
|
|
body
|
|
|
|
response {
|
|
|
|
proto
|
2020-09-24 00:13:14 +02:00
|
|
|
headers {
|
|
|
|
key
|
|
|
|
value
|
|
|
|
}
|
2020-09-20 22:30:17 +02:00
|
|
|
statusCode
|
2020-10-05 18:34:41 +02:00
|
|
|
statusReason
|
2020-09-20 22:30:17 +02:00
|
|
|
body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
interface Props {
|
2022-01-21 11:45:54 +01:00
|
|
|
requestId: string;
|
2020-09-20 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function LogDetail({ requestId: id }: Props): JSX.Element {
|
|
|
|
const { loading, error, data } = useQuery(HTTP_REQUEST_LOG, {
|
|
|
|
variables: { id },
|
|
|
|
});
|
|
|
|
|
2020-09-23 18:10:32 +02:00
|
|
|
if (loading) {
|
|
|
|
return <CircularProgress />;
|
|
|
|
}
|
|
|
|
if (error) {
|
2022-01-28 20:20:15 +01:00
|
|
|
return <Alert severity="error">Error fetching logs details: {error.message}</Alert>;
|
2020-09-23 18:10:32 +02:00
|
|
|
}
|
2020-09-20 22:30:17 +02:00
|
|
|
|
2020-09-23 23:43:20 +02:00
|
|
|
if (!data.httpRequestLog) {
|
|
|
|
return (
|
|
|
|
<Alert severity="warning">
|
|
|
|
Request <strong>{id}</strong> was not found.
|
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-24 00:13:14 +02:00
|
|
|
const { method, url, proto, headers, body, response } = data.httpRequestLog;
|
2020-09-20 22:30:17 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Grid container item spacing={2}>
|
|
|
|
<Grid item xs={6}>
|
2020-09-27 18:59:38 +02:00
|
|
|
<Box component={Paper}>
|
2020-09-24 00:13:14 +02:00
|
|
|
<RequestDetail request={{ method, url, proto, headers, body }} />
|
2020-09-20 22:30:17 +02:00
|
|
|
</Box>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={6}>
|
2020-09-21 21:46:44 +02:00
|
|
|
{response && (
|
2020-09-27 18:59:38 +02:00
|
|
|
<Box component={Paper}>
|
2020-09-21 21:46:44 +02:00
|
|
|
<ResponseDetail response={response} />
|
|
|
|
</Box>
|
|
|
|
)}
|
2020-09-20 22:30:17 +02:00
|
|
|
</Grid>
|
|
|
|
</Grid>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LogDetail;
|