diff --git a/packages/bruno-app/src/components/RequestPane/RequestBody/RequestBodyMode/index.js b/packages/bruno-app/src/components/RequestPane/RequestBody/RequestBodyMode/index.js index 65e34f437..0cf638f28 100644 --- a/packages/bruno-app/src/components/RequestPane/RequestBody/RequestBodyMode/index.js +++ b/packages/bruno-app/src/components/RequestPane/RequestBody/RequestBodyMode/index.js @@ -73,6 +73,15 @@ const RequestBodyMode = ({ item, collection }) => { > XML +
{ + dropdownTippyRef.current.hide(); + onModeChange('sparql'); + }} + > + SPARQL +
{ diff --git a/packages/bruno-app/src/components/RequestPane/RequestBody/index.js b/packages/bruno-app/src/components/RequestPane/RequestBody/index.js index 7ac178f79..c69a6b0ca 100644 --- a/packages/bruno-app/src/components/RequestPane/RequestBody/index.js +++ b/packages/bruno-app/src/components/RequestPane/RequestBody/index.js @@ -28,17 +28,19 @@ const RequestBody = ({ item, collection }) => { const onRun = () => dispatch(sendRequest(item, collection.uid)); const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); - if (['json', 'xml', 'text'].includes(bodyMode)) { + if (['json', 'xml', 'text', 'sparql'].includes(bodyMode)) { let codeMirrorMode = { json: 'application/ld+json', text: 'application/text', - xml: 'application/xml' + xml: 'application/xml', + sparql: 'application/sparql-query' }; let bodyContent = { json: body.json, text: body.text, - xml: body.xml + xml: body.xml, + sparql: body.sparql }; return ( diff --git a/packages/bruno-app/src/pageComponents/Index/index.js b/packages/bruno-app/src/pageComponents/Index/index.js index 234ee0f9a..9f4de2434 100644 --- a/packages/bruno-app/src/pageComponents/Index/index.js +++ b/packages/bruno-app/src/pageComponents/Index/index.js @@ -14,6 +14,7 @@ const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODE if (!SERVER_RENDERED) { require('codemirror/mode/javascript/javascript'); require('codemirror/mode/xml/xml'); + require('codemirror/mode/sparql/sparql'); require('codemirror/addon/comment/comment'); require('codemirror/addon/dialog/dialog'); require('codemirror/addon/edit/closebrackets'); diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 111f26d3e..97d61476c 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -602,6 +602,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => { json: null, text: null, xml: null, + sparql: null, multipartForm: null, formUrlEncoded: null } diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index e31b53355..56a11dd0a 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -692,6 +692,10 @@ export const collectionsSlice = createSlice({ item.draft.request.body.xml = action.payload.content; break; } + case 'sparql': { + item.draft.request.body.sparql = action.payload.content; + break; + } case 'formUrlEncoded': { item.draft.request.body.formUrlEncoded = action.payload.content; break; diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 9eb6c0d1f..5998fd9b7 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -284,6 +284,7 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {} text: si.draft.request.body.text, xml: si.draft.request.body.xml, graphql: si.draft.request.body.graphql, + sparql: si.draft.request.body.sparql, formUrlEncoded: copyFormUrlEncodedParams(si.draft.request.body.formUrlEncoded), multipartForm: copyMultipartFormParams(si.draft.request.body.multipartForm) }, @@ -316,6 +317,7 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {} text: si.request.body.text, xml: si.request.body.xml, graphql: si.request.body.graphql, + sparql: si.request.body.sparql, formUrlEncoded: copyFormUrlEncodedParams(si.request.body.formUrlEncoded), multipartForm: copyMultipartFormParams(si.request.body.multipartForm) }, @@ -459,6 +461,10 @@ export const humanizeRequestBodyMode = (mode) => { label = 'XML'; break; } + case 'sparql': { + label = 'SPARQL'; + break; + } case 'formUrlEncoded': { label = 'Form URL Encoded'; break; diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js index 576c58c24..b8b23e8fb 100644 --- a/packages/bruno-lang/v2/src/bruToJson.js +++ b/packages/bruno-lang/v2/src/bruToJson.js @@ -24,7 +24,7 @@ const { outdentString } = require('../../v1/src/utils'); const grammar = ohm.grammar(`Bru { BruFile = (meta | http | query | headers | auths | bodies | varsandassert | script | tests | docs)* auths = authbasic | authbearer - bodies = bodyjson | bodytext | bodyxml | bodygraphql | bodygraphqlvars | bodyforms | body + bodies = bodyjson | bodytext | bodyxml | bodysparql | bodygraphql | bodygraphqlvars | bodyforms | body bodyforms = bodyformurlencoded | bodymultipart nl = "\\r"? "\\n" @@ -83,6 +83,7 @@ const grammar = ohm.grammar(`Bru { bodyjson = "body:json" st* "{" nl* textblock tagend bodytext = "body:text" st* "{" nl* textblock tagend bodyxml = "body:xml" st* "{" nl* textblock tagend + bodysparql = "body:sparql" st* "{" nl* textblock tagend bodygraphql = "body:graphql" st* "{" nl* textblock tagend bodygraphqlvars = "body:graphql:vars" st* "{" nl* textblock tagend @@ -366,6 +367,13 @@ const sem = grammar.createSemantics().addAttribute('ast', { } }; }, + bodysparql(_1, _2, _3, _4, textblock, _5) { + return { + body: { + sparql: outdentString(textblock.sourceString) + } + }; + }, bodygraphql(_1, _2, _3, _4, textblock, _5) { return { body: { diff --git a/packages/bruno-lang/v2/src/jsonToBru.js b/packages/bruno-lang/v2/src/jsonToBru.js index 8ef44d7ad..d1f174579 100644 --- a/packages/bruno-lang/v2/src/jsonToBru.js +++ b/packages/bruno-lang/v2/src/jsonToBru.js @@ -125,6 +125,14 @@ ${indentString(body.text)} ${indentString(body.xml)} } +`; + } + + if (body && body.sparql && body.sparql.length) { + bru += `body:sparql { +${indentString(body.sparql)} +} + `; } diff --git a/packages/bruno-lang/v2/tests/fixtures/request.bru b/packages/bruno-lang/v2/tests/fixtures/request.bru index c4ae4b058..af556f3e8 100644 --- a/packages/bruno-lang/v2/tests/fixtures/request.bru +++ b/packages/bruno-lang/v2/tests/fixtures/request.bru @@ -48,6 +48,13 @@ body:xml { } +body:sparql { + SELECT * WHERE { + ?subject ?predicate ?object . + } + LIMIT 10 +} + body:form-urlencoded { apikey: secret numbers: +91998877665 diff --git a/packages/bruno-lang/v2/tests/fixtures/request.json b/packages/bruno-lang/v2/tests/fixtures/request.json index 7a00f5bb3..e8b3d8cd4 100644 --- a/packages/bruno-lang/v2/tests/fixtures/request.json +++ b/packages/bruno-lang/v2/tests/fixtures/request.json @@ -57,6 +57,7 @@ "json": "{\n \"hello\": \"world\"\n}", "text": "This is a text body", "xml": "\n John\n 30\n", + "sparql": "SELECT * WHERE {\n ?subject ?predicate ?object .\n}\nLIMIT 10", "graphql": { "query": "{\n launchesPast {\n launch_site {\n site_name\n }\n launch_success\n }\n}", "variables": "{\n \"limit\": 5\n}" diff --git a/packages/bruno-schema/src/collections/index.js b/packages/bruno-schema/src/collections/index.js index 337f0147b..b73364b7d 100644 --- a/packages/bruno-schema/src/collections/index.js +++ b/packages/bruno-schema/src/collections/index.js @@ -57,11 +57,12 @@ const graphqlBodySchema = Yup.object({ const requestBodySchema = Yup.object({ mode: Yup.string() - .oneOf(['none', 'json', 'text', 'xml', 'formUrlEncoded', 'multipartForm', 'graphql']) + .oneOf(['none', 'json', 'text', 'xml', 'formUrlEncoded', 'multipartForm', 'graphql', 'sparql']) .required('mode is required'), json: Yup.string().nullable(), text: Yup.string().nullable(), xml: Yup.string().nullable(), + sparql: Yup.string().nullable(), formUrlEncoded: Yup.array().of(keyValueSchema).nullable(), multipartForm: Yup.array().of(keyValueSchema).nullable(), graphql: graphqlBodySchema.nullable()