Skip to content

Commit 7528f0a

Browse files
committed
Request & Response in Tracing. Closes #255
1 parent 11b76fc commit 7528f0a

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

packages/graphql-playground/src/components/Playground.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
694694
isActive={index === selectedSessionIndex}
695695
permission={session.permission}
696696
serviceInformation={this.state.serviceInformation}
697-
tracingSupported={this.state.tracingSupported}
697+
tracingSupported={Boolean(this.state.tracingSupported)}
698698
/>
699699
</div>
700700
))}

packages/graphql-playground/src/components/Playground/GraphQLEditor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export interface State {
122122
isWaitingForResponse: boolean
123123
selectedVariableNames: string[]
124124
responseExtensions: any
125+
currentQueryStartTime?: Date
126+
currentQueryEndTime?: Date
125127
}
126128

127129
export interface SimpleProps {
@@ -667,6 +669,9 @@ export class GraphQLEditor extends React.PureComponent<
667669
this.state.responseExtensions &&
668670
this.state.responseExtensions.tracing
669671
}
672+
startTime={this.state.currentQueryStartTime}
673+
endTime={this.state.currentQueryEndTime}
674+
tracingSupported={this.props.tracingSupported}
670675
/>
671676
</div>
672677
</div>
@@ -948,6 +953,7 @@ export class GraphQLEditor extends React.PureComponent<
948953
isWaitingForResponse: true,
949954
responses: [{ date: null, time: new Date() }],
950955
operationName,
956+
currentQueryStartTime: new Date(),
951957
} as State)
952958

953959
// _fetchQuery may return a subscription.
@@ -988,6 +994,7 @@ export class GraphQLEditor extends React.PureComponent<
988994
isWaitingForResponse: false,
989995
responses,
990996
responseExtensions: extensions,
997+
currentQueryEndTime: new Date(),
991998
} as State)
992999
}
9931000
},

packages/graphql-playground/src/components/Playground/ResponseTracing.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface TracingFormat {
2323
export interface Props {
2424
tracing?: TracingFormat
2525
tracingSupported?: boolean
26+
startTime?: Date
27+
endTime?: Date
2628
}
2729

2830
const TracingWrapper = styled.div`
@@ -47,19 +49,47 @@ const TracingRows = styled.div`
4749

4850
export default class ResponseTracing extends React.Component<Props, {}> {
4951
render() {
50-
const { tracing, tracingSupported } = this.props
52+
const { tracing, tracingSupported, startTime, endTime } = this.props
53+
// console.log(this.props)
54+
const requestMs =
55+
tracing && startTime
56+
? Math.abs(new Date(tracing.startTime).getTime() - startTime.getTime())
57+
: 0
58+
const responseMs =
59+
tracing && endTime
60+
? Math.abs(endTime.getTime() - new Date(tracing.endTime).getTime())
61+
: 0
62+
const requestDuration = 1000 * 1000 * requestMs
63+
const maxLeft = tracing
64+
? tracing.execution.resolvers.reduce((max, curr) => {
65+
if (curr.startOffset > max) {
66+
return curr.startOffset
67+
}
68+
return max
69+
}, 0)
70+
: 0
5171
return (
5272
<TracingWrapper>
5373
{tracing ? (
5474
<TracingRows>
75+
<TracingRow
76+
path={['Request']}
77+
startOffset={0}
78+
duration={requestDuration}
79+
/>
5580
{tracing.execution.resolvers.map(res => (
5681
<TracingRow
5782
key={res.path.join('.')}
5883
path={res.path}
59-
startOffset={res.startOffset}
84+
startOffset={res.startOffset + requestDuration}
6085
duration={res.duration}
6186
/>
6287
))}
88+
<TracingRow
89+
path={['Response']}
90+
startOffset={maxLeft + requestDuration}
91+
duration={1000 * 1000 * responseMs}
92+
/>
6393
</TracingRows>
6494
) : tracingSupported ? (
6595
<NotSupported>

0 commit comments

Comments
 (0)