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 { BaseTableColumn } from '../../../dataSources/types';
|
||||||
import { sqlEscapeText } from '../../../dataSources/services/postgresql/sqlUtils';
|
import { sqlEscapeText } from '../../../dataSources/services/postgresql/sqlUtils';
|
||||||
import { FixMe } from '../../../types';
|
import { FixMe } from '../../../types';
|
||||||
import {
|
|
||||||
checkFeatureSupport,
|
|
||||||
READ_ONLY_RUN_SQL_QUERIES,
|
|
||||||
} from '../../../helpers/versionUtils';
|
|
||||||
|
|
||||||
export type OrderByType = 'asc' | 'desc';
|
export type OrderByType = 'asc' | 'desc';
|
||||||
export type OrderByNulls = 'first' | 'last';
|
export type OrderByNulls = 'first' | 'last';
|
||||||
@ -45,7 +41,7 @@ export const getRunSqlQuery = (
|
|||||||
source,
|
source,
|
||||||
sql: terminateSql(sql),
|
sql: terminateSql(sql),
|
||||||
cascade,
|
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 MAKING_REQUEST = 'RawSQL/MAKING_REQUEST';
|
||||||
const SET_SQL = 'RawSQL/SET_SQL';
|
const SET_SQL = 'RawSQL/SET_SQL';
|
||||||
const SET_CASCADE_CHECKED = 'RawSQL/SET_CASCADE_CHECKED';
|
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_MIGRATION_CHECKED = 'RawSQL/SET_MIGRATION_CHECKED';
|
||||||
const SET_TRACK_TABLE_CHECKED = 'RawSQL/SET_TRACK_TABLE_CHECKED';
|
const SET_TRACK_TABLE_CHECKED = 'RawSQL/SET_TRACK_TABLE_CHECKED';
|
||||||
const REQUEST_SUCCESS = 'RawSQL/REQUEST_SUCCESS';
|
const REQUEST_SUCCESS = 'RawSQL/REQUEST_SUCCESS';
|
||||||
@ -124,8 +125,8 @@ const executeSQL =
|
|||||||
(dispatch, getState) => {
|
(dispatch, getState) => {
|
||||||
dispatch({ type: MAKING_REQUEST });
|
dispatch({ type: MAKING_REQUEST });
|
||||||
dispatch(showSuccessNotification('Executing the Query...'));
|
dispatch(showSuccessNotification('Executing the Query...'));
|
||||||
|
const { isTableTrackChecked, isCascadeChecked, isReadOnlyChecked, sql } =
|
||||||
const { isTableTrackChecked, isCascadeChecked, sql } = getState().rawSQL;
|
getState().rawSQL;
|
||||||
const { migrationMode, readOnlyMode } = getState().main;
|
const { migrationMode, readOnlyMode } = getState().main;
|
||||||
|
|
||||||
const isStatementTimeout = statementTimeout && !isMigration;
|
const isStatementTimeout = statementTimeout && !isMigration;
|
||||||
@ -139,14 +140,20 @@ const executeSQL =
|
|||||||
dataSource.getStatementTimeoutSql(statementTimeout),
|
dataSource.getStatementTimeoutSql(statementTimeout),
|
||||||
source,
|
source,
|
||||||
false,
|
false,
|
||||||
readOnlyMode,
|
isReadOnlyChecked || readOnlyMode,
|
||||||
driver
|
driver
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
schemaChangesUp.push(
|
schemaChangesUp.push(
|
||||||
getRunSqlQuery(sql, source, isCascadeChecked, readOnlyMode, driver)
|
getRunSqlQuery(
|
||||||
|
sql,
|
||||||
|
source,
|
||||||
|
isCascadeChecked,
|
||||||
|
isReadOnlyChecked || readOnlyMode,
|
||||||
|
driver
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const schemaChangesDown = getDownQueryComments(schemaChangesUp, source);
|
const schemaChangesDown = getDownQueryComments(schemaChangesUp, source);
|
||||||
@ -238,6 +245,8 @@ const rawSQLReducer = (state = defaultState, action) => {
|
|||||||
return { ...state, isMigrationChecked: action.data };
|
return { ...state, isMigrationChecked: action.data };
|
||||||
case SET_CASCADE_CHECKED:
|
case SET_CASCADE_CHECKED:
|
||||||
return { ...state, isCascadeChecked: action.data };
|
return { ...state, isCascadeChecked: action.data };
|
||||||
|
case SET_READ_ONLY_CHECKED:
|
||||||
|
return { ...state, isReadOnlyChecked: action.data };
|
||||||
case SET_TRACK_TABLE_CHECKED:
|
case SET_TRACK_TABLE_CHECKED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@ -293,6 +302,7 @@ export {
|
|||||||
executeSQL,
|
executeSQL,
|
||||||
SET_SQL,
|
SET_SQL,
|
||||||
SET_CASCADE_CHECKED,
|
SET_CASCADE_CHECKED,
|
||||||
|
SET_READ_ONLY_CHECKED,
|
||||||
SET_MIGRATION_CHECKED,
|
SET_MIGRATION_CHECKED,
|
||||||
SET_TRACK_TABLE_CHECKED,
|
SET_TRACK_TABLE_CHECKED,
|
||||||
modalOpen,
|
modalOpen,
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
executeSQL,
|
executeSQL,
|
||||||
SET_SQL,
|
SET_SQL,
|
||||||
SET_CASCADE_CHECKED,
|
SET_CASCADE_CHECKED,
|
||||||
|
SET_READ_ONLY_CHECKED,
|
||||||
SET_MIGRATION_CHECKED,
|
SET_MIGRATION_CHECKED,
|
||||||
SET_TRACK_TABLE_CHECKED,
|
SET_TRACK_TABLE_CHECKED,
|
||||||
} from './Actions';
|
} from './Actions';
|
||||||
@ -67,6 +68,7 @@ const checkChangeLang = (sql, selectedDriver) => {
|
|||||||
* @property {boolean} lastSuccess
|
* @property {boolean} lastSuccess
|
||||||
* @property {boolean} isModalOpen
|
* @property {boolean} isModalOpen
|
||||||
* @property {boolean} isCascadeChecked
|
* @property {boolean} isCascadeChecked
|
||||||
|
* @property {boolean} isReadOnlyChecked
|
||||||
* @property {boolean} isMigrationChecked
|
* @property {boolean} isMigrationChecked
|
||||||
* @property {boolean} isTableTrackChecked
|
* @property {boolean} isTableTrackChecked
|
||||||
* @property {boolean} migrationMode
|
* @property {boolean} migrationMode
|
||||||
@ -85,6 +87,7 @@ const RawSQL = ({
|
|||||||
lastSuccess,
|
lastSuccess,
|
||||||
isModalOpen,
|
isModalOpen,
|
||||||
isCascadeChecked,
|
isCascadeChecked,
|
||||||
|
isReadOnlyChecked,
|
||||||
isMigrationChecked,
|
isMigrationChecked,
|
||||||
isTableTrackChecked,
|
isTableTrackChecked,
|
||||||
migrationMode,
|
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 getTrackThisSection = () => {
|
||||||
const dispatchTrackThis = () => {
|
const dispatchTrackThis = () => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -515,6 +545,7 @@ const RawSQL = ({
|
|||||||
? getTrackThisSection()
|
? getTrackThisSection()
|
||||||
: null}
|
: null}
|
||||||
{getMetadataCascadeSection()}
|
{getMetadataCascadeSection()}
|
||||||
|
{getReadOnlySection()}
|
||||||
{getMigrationSection()}
|
{getMigrationSection()}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -8,6 +8,7 @@ const defaultState = {
|
|||||||
resultHeaders: [],
|
resultHeaders: [],
|
||||||
isModalOpen: false,
|
isModalOpen: false,
|
||||||
isCascadeChecked: false,
|
isCascadeChecked: false,
|
||||||
|
isReadOnlyChecked: false,
|
||||||
isMigrationChecked: false,
|
isMigrationChecked: false,
|
||||||
isTableTrackChecked: false,
|
isTableTrackChecked: false,
|
||||||
showTrackTable: false,
|
showTrackTable: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user