Skip to content

Commit

Permalink
wip: large payload performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed May 24, 2018
1 parent 53f8658 commit 8391a8a
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/graphql-playground-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"apollo-link-ws": "1.0.4",
"calculate-size": "^1.1.1",
"classnames": "^2.2.5",
"codemirror": "^5.36.0",
"codemirror": "^5.38.0",
"codemirror-graphql": "timsuchanek/codemirror-graphql#details-fix",
"copy-to-clipboard": "^3.0.8",
"cuid": "^1.3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class CodeGenerationPopupCode extends React.Component<
options={{
height: 'auto',
mode: 'shell',
viewportMargin: Infinity,
theme: codeTheme,
}}
/>
Expand All @@ -70,7 +69,6 @@ class CodeGenerationPopupCode extends React.Component<
value={code}
options={{
height: 'auto',
viewportMargin: Infinity,
mode,
theme: codeTheme,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
})
this.backoff.start()
},
300,
600,
{ trailing: true }, // important to not miss the last call
) as any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export class ResultViewer extends React.Component<Props, {}> {
private viewer: any

componentDidMount() {
// Lazily require to ensure requiring GraphiQL outside of a Browser context
// does not produce an error.
const CodeMirror = require('codemirror')
require('codemirror/addon/fold/foldgutter')
require('codemirror/addon/fold/brace-fold')
Expand Down Expand Up @@ -96,7 +94,6 @@ export class ResultViewer extends React.Component<Props, {}> {
.result-codemirror :global(.CodeMirror) {
@p: .bbox, .pl38;
background: none;
position: relative !important;
}
`}</style>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export interface ReduxProps {
responses: List<ResponseRecord>
}

const defaultResponseRecord = new ResponseRecord({
date: '',
time: new Date(),
resultID: 'default-id',
})

const Results: React.SFC<Props & ReduxProps> = ({ setRef, responses }) => {
const response1 = responses.get(0) || defaultResponseRecord
return (
<div
className={cn('result-window', {
Expand Down Expand Up @@ -61,27 +68,37 @@ const Results: React.SFC<Props & ReduxProps> = ({ setRef, responses }) => {
position: relative;
}
`}</style>
{responses.map(response => (
<Response
key={
responses.size === 1
? 'first'
: response.resultID || String(response.time)
}
>
{responses.size <= 1 ? (
<Response key={'first'}>
{responses.size > 1 &&
response.time && (
response1.time && (
<div className="subscription-time">
<div className="subscription-time-text">
{ageOfDate(response.time)}
{ageOfDate(response1.time)}
</div>
</div>
)}
<div className="result-viewer-wrapper">
<ResultViewer value={response.date} />
<ResultViewer value={response1.date} />
</div>
</Response>
))}
) : (
responses.map(response => (
<Response key={response.resultID || String(response.time)}>
{responses.size > 1 &&
response.time && (
<div className="subscription-time">
<div className="subscription-time-text">
{ageOfDate(response.time)}
</div>
</div>
)}
<div className="result-viewer-wrapper">
<ResultViewer value={response.date} />
</div>
</Response>
))
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderedMap } from 'immutable'
import { OrderedMap, List } from 'immutable'
import { handleActions } from 'redux-actions'
import * as cuid from 'cuid'
import { SessionStateProps } from '../sessions/reducers'
Expand All @@ -13,11 +13,12 @@ export default handleActions(
state.setIn([sessionId, 'starred'], !state.getIn([sessionId, 'starred'])),
ADD_HISTORY_ITEM: (state, { payload: { session } }) => {
const id = cuid()
return state.set(
return state.slice(-40).set(
id,
session.merge({
id,
date: new Date(),
responses: List(),
}),
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function serializeState(store) {
localStorage.setItem('graphql-playground', JSON.stringify(state))
}
},
300,
1000,
{ trailing: true },
) as any
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function* runQuerySaga(action) {
yield put(setSubscriptionActive(isSubscription(operation)))
yield put(startQuery())
let headers = parseHeaders(session.headers)
if (session.tracingSupported) {
if (session.tracingSupported && session.responseTracingOpen) {
headers = set(headers, 'X-Apollo-Tracing', '1')
}
const { link, subscriptionClient } = linkCreator({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export class Session extends Record(getDefaultSession('')) {
const override: any = {
queryRunning: false,
subscriptionActive: false,
responseExtensions: {},
}
// dont serialize very big responses as the localStorage size is limited
if (
obj.responses &&
obj.responses.size > 0 &&
(obj.responses.size > 20 || obj.responses.get(0).date.length > 20000)
(obj.responses.size > 20 || obj.responses.get(0).date.length > 2000)
) {
override.responses = List()
}
Expand Down Expand Up @@ -195,7 +196,6 @@ const reducer = handleActions(
START_QUERY: state => {
return state
.setIn(['sessions', getSelectedSessionId(state), 'queryRunning'], true)
.setIn(['sessions', getSelectedSessionId(state), 'responses'], List())
.setIn(
['sessions', getSelectedSessionId(state), 'responseExtensions'],
undefined,
Expand Down
26 changes: 26 additions & 0 deletions packages/graphql-playground-react/src/styles/graphiql_dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,29 @@ li.CodeMirror-hint-active {
max-width: 50vw;
margin-right: 10px;
}

/** NEW STYLES - @huv1k please merge into the dynamic styles branch **/

.graphiql-container .resultWrap .result-window {
overflow: visible;
max-height: none !important;
}

.graphiql-container .resultWrap .result-window > div {
display: flex;
flex: 1;
height: 100%;
}

.graphiql-container .resultWrap .result-viewer-wrapper,
.graphiql-container .resultWrap .result-viewer-wrapper .result-codemirror {
position: relative;
display: flex;
flex: 1;
height: 100%;
}

.graphiql-container .resultWrap .CodeMirror {
height: 100%;
position: absolute !important;
}
13 changes: 13 additions & 0 deletions packages/graphql-playground-react/src/utils/performance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let last: number | null = null
// tslint:disable
export function log(...messages) {
if (messages.length === 0) {
last = null
}
if (last) {
console.log(...messages, `${performance.now() - last}ms`)
} else {
console.log(...messages)
}
last = performance.now()
}
6 changes: 3 additions & 3 deletions packages/graphql-playground-react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,9 @@ codemirror@^5.18.2, codemirror@^5.26.0:
version "5.33.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.33.0.tgz#462ad9a6fe8d38b541a9536a3997e1ef93b40c6a"

codemirror@^5.36.0:
version "5.36.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.36.0.tgz#1172ad9dc298056c06e0b34e5ccd23825ca15b40"
codemirror@^5.38.0:
version "5.38.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.38.0.tgz#26a9551446e51dbdde36aabe60f72469724fd332"

collection-visit@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit 8391a8a

Please sign in to comment.