Show the streaming response correctly in Flipper

Summary: make Sonar network tab work nicely with GraphQL streaming response

Reviewed By: danielbuechele

Differential Revision: D12841335

fbshipit-source-id: efcae3428c42957cbce27d467180ccbc10dc2ae9
This commit is contained in:
Jiyue Wang
2018-10-31 08:04:24 -07:00
committed by Facebook Github Bot
parent 62b913d844
commit f88aa99d2a

View File

@@ -607,6 +607,43 @@ class GraphQLFormatter {
return <ManagedDataInspector expandRoot={true} data={data} />;
}
};
formatResponse = (request: Request, response: Response) => {
return this.format(
decodeBody(response),
getHeaderValue(response.headers, 'content-type'),
);
};
format = (body: string, contentType: string) => {
if (
contentType.startsWith('application/json') ||
contentType.startsWith('text/javascript') ||
contentType.startsWith('text/html') ||
contentType.startsWith('application/x-fb-flatbuffer')
) {
try {
const data = JSON.parse(body);
return (
<ManagedDataInspector
collapsed={true}
expandRoot={true}
data={data}
/>
);
} catch (SyntaxError) {
// Multiple top level JSON roots, map them one by one
const roots = body.replace(/}{/g, '}\r\n{').split('\n');
return (
<ManagedDataInspector
collapsed={true}
expandRoot={true}
data={roots.map(json => JSON.parse(json))}
/>
);
}
}
};
}
class FormUrlencodedFormatter {