Show server execution time in network plugin
Summary: the simpliest approach to render this metadata for debugging purpose Reviewed By: bcuccioli Differential Revision: D14974129 fbshipit-source-id: d816d1ef8dcd1bc333c4d0cdf70d6d9fb925bc03
This commit is contained in:
committed by
Facebook Github Bot
parent
6f8d6ddd85
commit
614f48dda3
@@ -643,6 +643,30 @@ class GraphQLBatchFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GraphQLFormatter {
|
class GraphQLFormatter {
|
||||||
|
parsedServerTimeForFirstFlush = (data: any) => {
|
||||||
|
const firstResponse =
|
||||||
|
Array.isArray(data) && data.length > 0 ? data[0] : data;
|
||||||
|
if (!firstResponse) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const extensions = firstResponse['extensions'];
|
||||||
|
if (!extensions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const serverMetadata = extensions['server_metadata'];
|
||||||
|
if (!serverMetadata) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const requestStartMs = serverMetadata['request_start_time_ms'];
|
||||||
|
const timeAtFlushMs = serverMetadata['time_at_flush_ms'];
|
||||||
|
return (
|
||||||
|
<WrappingText>
|
||||||
|
{'Server wall time for initial response (ms): ' +
|
||||||
|
(timeAtFlushMs - requestStartMs)}
|
||||||
|
</WrappingText>
|
||||||
|
);
|
||||||
|
};
|
||||||
formatRequest = (request: Request) => {
|
formatRequest = (request: Request) => {
|
||||||
if (request.url.indexOf('graphql') > 0) {
|
if (request.url.indexOf('graphql') > 0) {
|
||||||
const data = querystring.parse(decodeBody(request));
|
const data = querystring.parse(decodeBody(request));
|
||||||
@@ -674,21 +698,30 @@ class GraphQLFormatter {
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(body);
|
const data = JSON.parse(body);
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
|
{this.parsedServerTimeForFirstFlush(data)}
|
||||||
<ManagedDataInspector
|
<ManagedDataInspector
|
||||||
collapsed={true}
|
collapsed={true}
|
||||||
expandRoot={true}
|
expandRoot={true}
|
||||||
data={data}
|
data={data}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
} catch (SyntaxError) {
|
} catch (SyntaxError) {
|
||||||
// Multiple top level JSON roots, map them one by one
|
// Multiple top level JSON roots, map them one by one
|
||||||
const roots = body.replace(/}{/g, '}\r\n{').split('\n');
|
const parsedResponses = body
|
||||||
|
.replace(/}{/g, '}\r\n{')
|
||||||
|
.split('\n')
|
||||||
|
.map(json => JSON.parse(json));
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
|
{this.parsedServerTimeForFirstFlush(parsedResponses)}
|
||||||
<ManagedDataInspector
|
<ManagedDataInspector
|
||||||
collapsed={true}
|
collapsed={true}
|
||||||
expandRoot={true}
|
expandRoot={true}
|
||||||
data={roots.map(json => JSON.parse(json))}
|
data={parsedResponses}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user