diff --git a/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js b/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js index a7978ebd77..91fea01344 100644 --- a/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js +++ b/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js @@ -6,6 +6,9 @@ import { updateRequestGraphqlVariables } from 'providers/ReduxStore/slices/colle import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import { useTheme } from 'providers/Theme'; import StyledWrapper from './StyledWrapper'; +import { format, applyEdits } from 'jsonc-parser'; +import { IconWand } from '@tabler/icons'; +import toast from 'react-hot-toast'; const GraphQLVariables = ({ variables, item, collection }) => { const dispatch = useDispatch(); @@ -13,6 +16,25 @@ const GraphQLVariables = ({ variables, item, collection }) => { const { displayedTheme } = useTheme(); const preferences = useSelector((state) => state.app.preferences); + const onPrettify = () => { + if (!variables) return; + try { + const edits = format(variables, undefined, { tabSize: 2, insertSpaces: true }); + const prettyVariables = applyEdits(variables, edits); + dispatch( + updateRequestGraphqlVariables({ + variables: prettyVariables, + itemUid: item.uid, + collectionUid: collection.uid + }) + ); + toast.success('Variables prettified'); + } catch (error) { + console.error(error); + toast.error('Error occurred while prettifying GraphQL variables'); + } + }; + const onEdit = (value) => { dispatch( updateRequestGraphqlVariables({ @@ -27,12 +49,20 @@ const GraphQLVariables = ({ variables, item, collection }) => { const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); return ( - + +