()
| 6 | import './execute.css'; |
| 7 | |
| 8 | export function ExecuteButton() { |
| 9 | const { queryEditor, setOperationName } = useEditorContext({ |
| 10 | nonNull: true, |
| 11 | caller: ExecuteButton, |
| 12 | }); |
| 13 | const { isFetching, isSubscribed, operationName, run, stop } = |
| 14 | useExecutionContext({ |
| 15 | nonNull: true, |
| 16 | caller: ExecuteButton, |
| 17 | }); |
| 18 | |
| 19 | const operations = queryEditor?.operations || []; |
| 20 | const hasOptions = operations.length > 1 && typeof operationName !== 'string'; |
| 21 | const isRunning = isFetching || isSubscribed; |
| 22 | |
| 23 | const label = `${isRunning ? 'Stop' : 'Execute'} query (Ctrl-Enter)`; |
| 24 | const buttonProps = { |
| 25 | type: 'button' as const, |
| 26 | className: 'graphiql-execute-button', |
| 27 | children: isRunning ? <StopIcon /> : <PlayIcon />, |
| 28 | 'aria-label': label, |
| 29 | }; |
| 30 | |
| 31 | return hasOptions && !isRunning ? ( |
| 32 | <DropdownMenu> |
| 33 | <Tooltip label={label}> |
| 34 | <DropdownMenu.Button {...buttonProps} /> |
| 35 | </Tooltip> |
| 36 | |
| 37 | <DropdownMenu.Content> |
| 38 | {operations.map((operation, i) => { |
| 39 | const opName = operation.name |
| 40 | ? operation.name.value |
| 41 | : `<Unnamed ${operation.operation}>`; |
| 42 | return ( |
| 43 | <DropdownMenu.Item |
| 44 | key={`${opName}-${i}`} |
| 45 | onSelect={() => { |
| 46 | const selectedOperationName = operation.name?.value; |
| 47 | if ( |
| 48 | queryEditor && |
| 49 | selectedOperationName && |
| 50 | selectedOperationName !== queryEditor.operationName |
| 51 | ) { |
| 52 | setOperationName(selectedOperationName); |
| 53 | } |
| 54 | run(); |
| 55 | }} |
| 56 | > |
| 57 | {opName} |
| 58 | </DropdownMenu.Item> |
| 59 | ); |
| 60 | })} |
| 61 | </DropdownMenu.Content> |
| 62 | </DropdownMenu> |
| 63 | ) : ( |
| 64 | <Tooltip label={label}> |
| 65 | <button |
nothing calls this directly
no test coverage detected