Skip to content

Commit 114ed35

Browse files
committed
Fix operation selection. Closes #609
1 parent 66b6dcc commit 114ed35

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import {
2121
getOperations,
2222
getSelectedSessionIdFromRoot,
2323
} from '../../state/sessions/selectors'
24+
import { List } from 'immutable'
2425

2526
export interface ReduxProps {
2627
runQuery: (operationName?: string) => void
2728
stopQuery: (sessionId: string) => void
2829
queryRunning: boolean
29-
operations: any[]
30+
operations: List<any>
3031
sessionId: string
3132
}
3233

@@ -59,7 +60,7 @@ class ExecuteButton extends React.Component<
5960
render() {
6061
const { operations } = this.props
6162
const optionsOpen = this.state.optionsOpen
62-
const hasOptions = operations && operations.length > 1
63+
const hasOptions = operations && operations.size > 1
6364

6465
let options: any = null
6566
if (hasOptions && optionsOpen) {
@@ -158,21 +159,23 @@ class ExecuteButton extends React.Component<
158159
} else {
159160
document.removeEventListener('mouseup', onMouseUp)
160161
onMouseUp = null
161-
const isOptionsMenuClicked =
162-
// tslint:disable-next-line
163-
downTarget.parentNode.compareDocumentPosition(upEvent.target) &
164-
Node.DOCUMENT_POSITION_CONTAINED_BY
165-
if (!isOptionsMenuClicked) {
166-
// menu calls setState if it was clicked
167-
this.setState({ optionsOpen: false } as State)
168-
}
169-
if (firstTime) {
170-
this.onOptionSelected(
171-
this.props.operations.find(
172-
op => op.name.value === upEvent.target.textContent,
173-
) || this.props.operations[0],
174-
)
175-
firstTime = false
162+
if (downTarget.parentNode) {
163+
const isOptionsMenuClicked =
164+
// tslint:disable-next-line
165+
downTarget.parentNode.compareDocumentPosition(upEvent.target) &
166+
Node.DOCUMENT_POSITION_CONTAINED_BY
167+
if (!isOptionsMenuClicked) {
168+
// menu calls setState if it was clicked
169+
this.setState({ optionsOpen: false } as State)
170+
}
171+
if (firstTime) {
172+
this.onOptionSelected(
173+
this.props.operations.find(
174+
op => op.name.value === upEvent.target.textContent,
175+
) || this.props.operations[0],
176+
)
177+
firstTime = false
178+
}
176179
}
177180
}
178181
}

packages/graphql-playground-react/src/state/sessions/fetchingSagas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const subscriptions = {}
9999

100100
function* runQuerySaga(action) {
101101
// run the query
102-
const { operationName } = action
102+
const { operationName } = action.payload
103103
const selectedWorkspaceId = yield select(getSelectedWorkspaceId)
104104
const session: Session = yield select(getSelectedSession)
105105
const request = {

packages/graphql-playground-react/src/state/sessions/sagas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ function* runQueryAtPosition(action) {
8080
const session: Session = yield select(getSelectedSession)
8181
if (session.operations) {
8282
let operationName
83-
for (const operation of session.operations as any) {
83+
session.operations.forEach((operation: any) => {
8484
if (operation.loc.start <= position && operation.loc.end >= position) {
8585
operationName = operation.name && operation.name.value
8686
}
87-
}
87+
})
8888
if (operationName) {
8989
yield put(runQuery(operationName))
9090
} else {

0 commit comments

Comments
 (0)