mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
console: add response_transform in update_action api call
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6223 Co-authored-by: Daniele Cammareri <5709409+dancamma@users.noreply.github.com> GitOrigin-RevId: 6687188c3fe1dc025273aa8f3bb0bac20b605a7d
This commit is contained in:
parent
8fb1c1f344
commit
bb5c1ad4d0
@ -159,6 +159,12 @@ export type RequestTransformState = {
|
||||
templatingEngine: RequestTransformTemplateEngine;
|
||||
};
|
||||
|
||||
export type ResponseTransformState = {
|
||||
version: 1 | 2;
|
||||
requestBody: RequestTransformStateBody;
|
||||
templatingEngine: RequestTransformTemplateEngine;
|
||||
};
|
||||
|
||||
export type RequestTransformStateBody = Omit<
|
||||
RequestTransformBody,
|
||||
'form_template'
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
RequestTransform,
|
||||
RequestTransformBody,
|
||||
RequestTransformMethod,
|
||||
ResponseTranform,
|
||||
} from '@/metadata/types';
|
||||
import { getLSItem, setLSItem, LS_KEYS } from '@/utils/localStorage';
|
||||
import {
|
||||
@ -10,6 +11,7 @@ import {
|
||||
KeyValuePair,
|
||||
RequestTransformState,
|
||||
RequestTransformStateBody,
|
||||
ResponseTransformState,
|
||||
} from './stateDefaults';
|
||||
import { isEmpty, isJsonString } from '../utils/jsUtils';
|
||||
import { Nullable } from '../utils/tsUtils';
|
||||
@ -174,6 +176,14 @@ export const getRequestTransformObject = (
|
||||
return obj;
|
||||
};
|
||||
|
||||
export const getResponseTransformObject = (
|
||||
transformState: ResponseTransformState
|
||||
): ResponseTranform => ({
|
||||
version: 2,
|
||||
body: getTransformBodyServer(transformState.requestBody),
|
||||
template_engine: transformState.templatingEngine,
|
||||
});
|
||||
|
||||
const getErrorFromCode = (data: Record<string, any>) => {
|
||||
const errorCode = data.code ? data.code : '';
|
||||
const errorMsg = data.error ? data.error : '';
|
||||
|
@ -37,7 +37,8 @@ export const generateActionDefinition = (
|
||||
forwardClientHeaders,
|
||||
timeout,
|
||||
},
|
||||
requestTransform
|
||||
requestTransform,
|
||||
responseTransform
|
||||
) => {
|
||||
return {
|
||||
arguments: filterNameLessTypeLess(args),
|
||||
@ -49,6 +50,7 @@ export const generateActionDefinition = (
|
||||
forward_client_headers: forwardClientHeaders,
|
||||
timeout,
|
||||
request_transform: requestTransform ?? null,
|
||||
response_transform: responseTransform ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@ const state = {
|
||||
forwardClientHeaders: false,
|
||||
timeout: '',
|
||||
comment: '',
|
||||
response_transfrom: {},
|
||||
};
|
||||
|
||||
export default state;
|
||||
|
@ -36,6 +36,7 @@ export const getModifyState = (currentAction, allTypes) => {
|
||||
forwardClientHeaders: actionDef.forward_client_headers,
|
||||
timeout: actionDef?.timeout ?? '',
|
||||
comment: currentAction.comment,
|
||||
response_transfrom: actionDef?.response_transfrom ?? {},
|
||||
};
|
||||
return modifyState;
|
||||
};
|
||||
|
@ -59,7 +59,10 @@ import {
|
||||
persistDerivedAction,
|
||||
updatePersistedDerivation,
|
||||
} from './utils';
|
||||
import { getRequestTransformObject } from '../../Common/ConfigureTransformation/utils';
|
||||
import {
|
||||
getRequestTransformObject,
|
||||
getResponseTransformObject,
|
||||
} from '../../Common/ConfigureTransformation/utils';
|
||||
|
||||
export const createAction = transformState => (dispatch, getState) => {
|
||||
const { add: rawState } = getState().actions;
|
||||
@ -238,7 +241,7 @@ export const saveAction =
|
||||
};
|
||||
|
||||
const requestTransform = getRequestTransformObject(transformState);
|
||||
|
||||
const responseTransform = getResponseTransformObject(transformState);
|
||||
const validationError = getStateValidationError(state);
|
||||
|
||||
if (validationError) {
|
||||
@ -267,18 +270,11 @@ export const saveAction =
|
||||
|
||||
const dropCurrentActionQuery = generateDropActionQuery(currentAction.name);
|
||||
|
||||
const updateCurrentActionQuery = requestTransform
|
||||
? getUpdateActionQuery(
|
||||
generateActionDefinition(state, requestTransform),
|
||||
currentAction.name,
|
||||
actionComment
|
||||
)
|
||||
: getUpdateActionQuery(
|
||||
generateActionDefinition(state),
|
||||
const updateCurrentActionQuery = getUpdateActionQuery(
|
||||
generateActionDefinition(state, requestTransform, responseTransform),
|
||||
currentAction.name,
|
||||
actionComment
|
||||
);
|
||||
|
||||
const rollbackActionQuery = getUpdateActionQuery(
|
||||
currentAction.definition,
|
||||
currentAction.name,
|
||||
|
@ -933,6 +933,11 @@ export type RequestTransformBody = {
|
||||
form_template?: Record<string, string>;
|
||||
};
|
||||
|
||||
export type ResponseTransformBody = {
|
||||
action: RequestTransformBodyActions;
|
||||
template?: string;
|
||||
};
|
||||
|
||||
export type RequestTransformHeaders = {
|
||||
add_headers?: Record<string, string>;
|
||||
remove_headers?: string[];
|
||||
@ -964,6 +969,12 @@ interface RequestTransformV2 extends RequestTransformFields {
|
||||
|
||||
export type RequestTransform = RequestTransformV1 | RequestTransformV2;
|
||||
|
||||
export type ResponseTranform = {
|
||||
version: 2;
|
||||
body?: ResponseTransformBody;
|
||||
template_engine?: Nullable<RequestTransformTemplateEngine>;
|
||||
};
|
||||
|
||||
/**
|
||||
* https://hasura.io/docs/latest/graphql/core/api-reference/schema-metadata-api/actions.html#actiondefinition
|
||||
*/
|
||||
@ -976,6 +987,7 @@ export interface ActionDefinition {
|
||||
handler: WebhookURL;
|
||||
type?: 'mutation' | 'query';
|
||||
transform?: RequestTransform;
|
||||
responseTransform?: ResponseTranform;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user