mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
console: allow users to execute read only SQL queries
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8057 Co-authored-by: Sooraj <8408875+soorajshankar@users.noreply.github.com> GitOrigin-RevId: 3685e43e52ce3c7e29b8afef52169720e26bb67c
This commit is contained in:
parent
72e319e486
commit
68e8091fda
@ -7,10 +7,6 @@ import { ConsoleScope } from '../../Main/ConsoleNotification';
|
||||
import { BaseTableColumn } from '../../../dataSources/types';
|
||||
import { sqlEscapeText } from '../../../dataSources/services/postgresql/sqlUtils';
|
||||
import { FixMe } from '../../../types';
|
||||
import {
|
||||
checkFeatureSupport,
|
||||
READ_ONLY_RUN_SQL_QUERIES,
|
||||
} from '../../../helpers/versionUtils';
|
||||
|
||||
export type OrderByType = 'asc' | 'desc';
|
||||
export type OrderByNulls = 'first' | 'last';
|
||||
@ -45,7 +41,7 @@ export const getRunSqlQuery = (
|
||||
source,
|
||||
sql: terminateSql(sql),
|
||||
cascade,
|
||||
read_only: read_only && !!checkFeatureSupport(READ_ONLY_RUN_SQL_QUERIES),
|
||||
read_only: read_only,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -37,6 +37,7 @@ import { exportMetadata } from '../../../../metadata/actions';
|
||||
const MAKING_REQUEST = 'RawSQL/MAKING_REQUEST';
|
||||
const SET_SQL = 'RawSQL/SET_SQL';
|
||||
const SET_CASCADE_CHECKED = 'RawSQL/SET_CASCADE_CHECKED';
|
||||
const SET_READ_ONLY_CHECKED = 'RawSQL/SET_READ_ONLY_CHECKED';
|
||||
const SET_MIGRATION_CHECKED = 'RawSQL/SET_MIGRATION_CHECKED';
|
||||
const SET_TRACK_TABLE_CHECKED = 'RawSQL/SET_TRACK_TABLE_CHECKED';
|
||||
const REQUEST_SUCCESS = 'RawSQL/REQUEST_SUCCESS';
|
||||
@ -124,8 +125,8 @@ const executeSQL =
|
||||
(dispatch, getState) => {
|
||||
dispatch({ type: MAKING_REQUEST });
|
||||
dispatch(showSuccessNotification('Executing the Query...'));
|
||||
|
||||
const { isTableTrackChecked, isCascadeChecked, sql } = getState().rawSQL;
|
||||
const { isTableTrackChecked, isCascadeChecked, isReadOnlyChecked, sql } =
|
||||
getState().rawSQL;
|
||||
const { migrationMode, readOnlyMode } = getState().main;
|
||||
|
||||
const isStatementTimeout = statementTimeout && !isMigration;
|
||||
@ -139,14 +140,20 @@ const executeSQL =
|
||||
dataSource.getStatementTimeoutSql(statementTimeout),
|
||||
source,
|
||||
false,
|
||||
readOnlyMode,
|
||||
isReadOnlyChecked || readOnlyMode,
|
||||
driver
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
schemaChangesUp.push(
|
||||
getRunSqlQuery(sql, source, isCascadeChecked, readOnlyMode, driver)
|
||||
getRunSqlQuery(
|
||||
sql,
|
||||
source,
|
||||
isCascadeChecked,
|
||||
isReadOnlyChecked || readOnlyMode,
|
||||
driver
|
||||
)
|
||||
);
|
||||
|
||||
const schemaChangesDown = getDownQueryComments(schemaChangesUp, source);
|
||||
@ -238,6 +245,8 @@ const rawSQLReducer = (state = defaultState, action) => {
|
||||
return { ...state, isMigrationChecked: action.data };
|
||||
case SET_CASCADE_CHECKED:
|
||||
return { ...state, isCascadeChecked: action.data };
|
||||
case SET_READ_ONLY_CHECKED:
|
||||
return { ...state, isReadOnlyChecked: action.data };
|
||||
case SET_TRACK_TABLE_CHECKED:
|
||||
return {
|
||||
...state,
|
||||
@ -293,6 +302,7 @@ export {
|
||||
executeSQL,
|
||||
SET_SQL,
|
||||
SET_CASCADE_CHECKED,
|
||||
SET_READ_ONLY_CHECKED,
|
||||
SET_MIGRATION_CHECKED,
|
||||
SET_TRACK_TABLE_CHECKED,
|
||||
modalOpen,
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
executeSQL,
|
||||
SET_SQL,
|
||||
SET_CASCADE_CHECKED,
|
||||
SET_READ_ONLY_CHECKED,
|
||||
SET_MIGRATION_CHECKED,
|
||||
SET_TRACK_TABLE_CHECKED,
|
||||
} from './Actions';
|
||||
@ -67,6 +68,7 @@ const checkChangeLang = (sql, selectedDriver) => {
|
||||
* @property {boolean} lastSuccess
|
||||
* @property {boolean} isModalOpen
|
||||
* @property {boolean} isCascadeChecked
|
||||
* @property {boolean} isReadOnlyChecked
|
||||
* @property {boolean} isMigrationChecked
|
||||
* @property {boolean} isTableTrackChecked
|
||||
* @property {boolean} migrationMode
|
||||
@ -85,6 +87,7 @@ const RawSQL = ({
|
||||
lastSuccess,
|
||||
isModalOpen,
|
||||
isCascadeChecked,
|
||||
isReadOnlyChecked,
|
||||
isMigrationChecked,
|
||||
isTableTrackChecked,
|
||||
migrationMode,
|
||||
@ -351,6 +354,33 @@ const RawSQL = ({
|
||||
);
|
||||
};
|
||||
|
||||
const getReadOnlySection = () => {
|
||||
return (
|
||||
<div className={styles.add_mar_top_small}>
|
||||
<label>
|
||||
<input
|
||||
checked={isReadOnlyChecked}
|
||||
className={`${styles.add_mar_right_small} ${styles.cursorPointer} legacy-input-fix`}
|
||||
id="read-only-checkbox"
|
||||
type="checkbox"
|
||||
onChange={() => {
|
||||
dispatch({
|
||||
type: SET_READ_ONLY_CHECKED,
|
||||
data: !isReadOnlyChecked,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
Read only
|
||||
</label>
|
||||
<Tooltip
|
||||
message={
|
||||
'When set to true, the request will be run in READ ONLY transaction access mode which means only select queries will be successful. This flag ensures that the GraphQL schema is not modified and is hence highly performant.'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const getTrackThisSection = () => {
|
||||
const dispatchTrackThis = () => {
|
||||
dispatch({
|
||||
@ -515,6 +545,7 @@ const RawSQL = ({
|
||||
? getTrackThisSection()
|
||||
: null}
|
||||
{getMetadataCascadeSection()}
|
||||
{getReadOnlySection()}
|
||||
{getMigrationSection()}
|
||||
</>
|
||||
)}
|
||||
|
@ -8,6 +8,7 @@ const defaultState = {
|
||||
resultHeaders: [],
|
||||
isModalOpen: false,
|
||||
isCascadeChecked: false,
|
||||
isReadOnlyChecked: false,
|
||||
isMigrationChecked: false,
|
||||
isTableTrackChecked: false,
|
||||
showTrackTable: false,
|
||||
|
Loading…
Reference in New Issue
Block a user