Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit ad56417

Browse files
antonk52facebook-github-bot
authored andcommitted
RequestAlert
Summary: Let's infer what type of payload we are looking at and suggest better plugins we can Differential Revision: D65296211 fbshipit-source-id: 7699160987b0f77de77cc7b19328750fdf724f22
1 parent 06d60d0 commit ad56417

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

desktop/plugins/public/network/RequestDetails.tsx

+20-12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {ProtobufDefinitionsRepository} from './ProtobufDefinitionsRepository';
3636
import {KeyValueItem, KeyValueTable} from './KeyValueTable';
3737
import {CopyOutlined} from '@ant-design/icons';
3838
import {stringify} from 'lossless-json';
39+
import {RequestAlert} from './fb-stubs/RequestAlert';
3940

4041
const {Text} = Typography;
4142

@@ -75,6 +76,8 @@ export default class RequestDetails extends Component<RequestDetailsProps> {
7576

7677
return (
7778
<>
79+
<RequestAlert request={request} />
80+
7881
<Panel key="request" title={'Request'}>
7982
<KeyValueTable items={this.urlColumns(url)} />
8083
</Panel>
@@ -553,7 +556,7 @@ class GraphQLBatchFormatter {
553556
}
554557
}
555558

556-
class GraphQLFormatter {
559+
export class GraphQLFormatter {
557560
parsedServerTimeForFirstFlush(data: any) {
558561
const firstResponse =
559562
Array.isArray(data) && data.length > 0 ? data[0] : data;
@@ -579,19 +582,24 @@ class GraphQLFormatter {
579582
</Text>
580583
);
581584
}
585+
static requestToObject(request: RequestWithData) {
586+
const decoded = request.requestData;
587+
if (!decoded) {
588+
return undefined;
589+
}
590+
const data = queryToObj(bodyAsString(decoded));
591+
if (typeof data.variables === 'string') {
592+
data.variables = JSON.parse(data.variables);
593+
}
594+
if (typeof data.query_params === 'string') {
595+
data.query_params = JSON.parse(data.query_params);
596+
}
597+
598+
return data;
599+
}
582600
formatRequest(request: RequestWithData) {
583601
if (request.url.indexOf('graphql') > 0) {
584-
const decoded = request.requestData;
585-
if (!decoded) {
586-
return undefined;
587-
}
588-
const data = queryToObj(bodyAsString(decoded));
589-
if (typeof data.variables === 'string') {
590-
data.variables = JSON.parse(data.variables);
591-
}
592-
if (typeof data.query_params === 'string') {
593-
data.query_params = JSON.parse(data.query_params);
594-
}
602+
const data = GraphQLFormatter.requestToObject(request);
595603
return <DataInspector expandRoot data={data} />;
596604
}
597605
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
import {RequestWithData} from '../types';
11+
12+
export const RequestAlert = (_props: {request: RequestWithData}) => {
13+
return null;
14+
};

desktop/plugins/public/network/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
437437

438438
return {
439439
db,
440+
client,
440441
columns,
441442
routes,
442443
nextRouteId,

0 commit comments

Comments
 (0)