{"version":3,"sources":["webpack:///./app/containers/Graphiql/index.js","webpack:///./node_modules/vscode-languageserver-types/lib/umd sync","webpack:///./app/containers/Graphiql/messages.js","webpack:///./app/containers/Graphiql/styles.css?d261","webpack:///./app/containers/Graphiql/styles.css","webpack:///./app/containers/GraphExplorer/index.js"],"names":["graphQLFetcher","graphQLParams","query","fetch","getGraphEndpoint","method","mode","cache","credentials","headers","Authorization","window","aat","getCurrentOrg","redirect","referrer","body","JSON","stringify","operationName","variables","then","response","json","err","error","Graphiql","props","_graphiql","state","registedResultOnClick","resultViewer","resultComponent","viewer","setState","on","handleResultSelect","pos","getCursor","line","getLine","token","getTokenAt","trim","startsWith","srn","split","replace","endsWith","substring","length","srnUrlLinkParams","getNodeViewPushParams","string","currentLine","includes","metadata","getMetadataAsObject","getMetadataAsList","lines","push","value","endLine","match","undefined","content","join","parse","codeMirrorScroll","scrollTopBefore","_container","querySelector","scrollTop","handleScrollReset","setTimeout","_","isArray","handleSetValueFromObject","allLines","getValue","newLines","lineIndex","newMetadataLines","metdataNestedObject","map","v","i","prepentSpaces","newLine","newValue","setValue","rawLines","addKeys","lineAfter","currentPath","isObject","Object","keys","forEach","key","child","pop","index","name","defaultValue","items","isEmpty","item","getVariable","val","exists","getVariables","explorerIsOpen","savedSearches","search","fromJS","label","get","toJS","queryEditor","queryEditorComponent","editor","currentValue","prettierValue","prettier","format","parser","plugins","graphqlParser","e","console","handlePrettifyQuery","toolbarButton","background","border","marginTop","marginLeft","marginBottom","height","paddingLeft","paddingRight","paddingTop","paddingBottom","cursor","borderRadius","fontFamily","searchName","qs","find","preloadQuery","element","document","getElementsByClassName","el","parentNode","removeChild","this","registerResultOnClick","schema","buildClientSchema","id","className","ref","style","width","position","zIndex","fetcher","defaultQuery","onEditQuery","handleQueryEdit","onEditVariables","handleVariablesEdit","Logo","messages","header","Toolbar","LAYERS","TOOLBAR","isClearable","styles","menuList","provided","fontWeight","fontSize","placeholder","singleValue","onChange","loadSavedSearch","options","getDropdownOptions","title","onClick","handlePrettierClick","handleToggleHistory","handleSetValue","href","pathname","target","rel","React","Component","mapStateToProps","createStructuredSelector","selectGraphQLSchema","withConnect","connect","dispatch","compose","webpackEmptyContext","req","Error","code","resolve","module","exports","defineMessages","defaultMessage","transform","locals","GraphExplorer","fetchGraphQLSchema","sonraiSearchesLoading","location","selectSonraiSearches","selectSonraiSearchesLoading","bindActionCreators"],"mappings":"w1JAiCA,IAAMA,eAAiB,SAAAC,eACrB,IAAMC,MAAQD,cAAcC,MAE5B,OAAOC,MAAM,GAAD,OAAIC,+DAAJ,WAAiC,CAC3CC,OAAQ,OACRC,KAAM,OACNC,MAAO,WACPC,YAAa,cACbC,QAAS,CACP,eAAgB,mBAChBC,cAAe,UAAF,OAAYC,OAAOC,KAChC,yBAA0BC,4DAE5BC,SAAU,SACVC,SAAU,cACVC,KAAMC,KAAKC,UAAU,CACnBhB,MAAO,eAAF,OACCA,MADD,gBAGLiB,cAAelB,cAAckB,eAAiBlB,cAAckB,cAC5DC,UAAWnB,cAAcmB,WAAanB,cAAcmB,cAErDC,MAAK,SAAAC,UACN,IAEE,OADeA,SAASC,OAExB,MAAOC,KACP,MAAO,CACLC,MAAO,wDACPH,SAAUA,e,MAsmBA,KAAC,uDAAD,IAhmBLI,SAAb,2BACE,kBAAYC,OAAO,U,yIAAA,gB,KACjB,K,KAAA,oCAAMA,OAAN,O,0FADiB,uEAuEK,WAItB,GAAI,MAAKC,YAAc,MAAKC,MAAMC,sBAAuB,CACvD,IAAMC,aAAe,MAAKH,UAAUI,gBAAgBC,OACpD,MAAKC,SAAS,CAAEJ,uBAAuB,IACvCC,aAAaI,GAAG,QAAS,MAAKC,oBAC9BL,aAAaI,GAAG,OAAQ,MAAKC,oBAC7BL,aAAaI,GAAG,iBAAkB,MAAKC,wBAhFxB,oEAwFE,SAAAL,cACnB,GAAKA,aAAL,CAGA,IAAMM,IAAMN,aAAaO,YACrBC,KAAOR,aAAaS,QAAQH,IAAIE,MAChCE,MAAQV,aAA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,gBAAqB1J,GAER,oBAAQ,GAAR,CAAgEC,QAAS4H,SAEnF5H,QAAQ0J,SAAQL,OAAOC,QAAUtJ,QAAQ0J,S,mDCjBlCL,OAAOC,QAAU,oBAAQ,GAAR,EAAgE,IAEnF3J,KAAK,CAAC0J,OAAOhI,EAAI,yUAA6U,M,qyFCqCzV,K,yBAAC,EAAD,IAhBAsI,cAAb,2BACE,uBAAYjM,OAAO,iB,8HAAA,qBACjB,+EAAMA,QAEFgD,8CAAE+B,QAAQ/E,MAAMmI,SAClBnI,MAAMkM,qBAJS,M,uCADrB,O,2UAAA,iC,YAAA,e,WAAA,gCAUI,OACGlN,OAAOC,KACPgJ,KAAKjI,MAAMmM,uBACVlE,KAAKjI,MAAMsF,cAAcP,WAC3B/B,8CAAE+B,QAAQkD,KAAKjI,MAAMmI,QAErB,KAIA,KAAC,mDAAD,CACEiE,SAAUnE,KAAKjI,MAAMoM,SACrB9G,cAAe2C,KAAKjI,MAAMsF,qB,4GAtBlC,eAAmCuF,6CAAMC,WA4BnCC,gBAAkBC,gDAAyB,CAC/C1F,cAAe+G,+DACflE,OAAQ8C,+DACRkB,sBAAuBG,iEAWzB,IAAMpB,YAAcC,yDAAQJ,iBAR5B,SAA4BK,UAC1B,OAAOmB,8DACL,CACEL,iFAEFd,aAgBWC,+EAAQH,YAARG,CAAqBY","file":"28.c351a991e6a6f301b1cb.chunk.js","sourcesContent":["/**\n *\n * Graphiql\n *\n */\n\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport ImmutablePropTypes from 'react-immutable-proptypes'\nimport { connect } from 'react-redux'\nimport { compose } from 'redux'\nimport GraphiQL from 'graphiql'\nimport { createStructuredSelector } from 'reselect'\nimport { FormattedMessage } from 'react-intl'\nimport messages from './messages.js'\nimport _ from 'lodash'\nimport qs from 'query-string'\nimport prettier from 'prettier/standalone'\nimport graphqlParser from 'prettier/parser-graphql'\n\nimport LoadingAnim from 'components/LoadingAnim'\nimport { LAYERS } from 'utils/styleUtils'\nimport SelectBar from 'components/SelectBar'\nimport { exists } from 'utils/sonraiUtils'\nimport { getGraphEndpoint } from 'utils/graphDataUtils'\nimport { selectGraphQLSchema } from 'containers/SonraiData/selectors'\nimport { fromJS } from 'immutable'\nimport { buildClientSchema } from 'graphql'\nimport { metdataNestedObject, getNodeViewPushParams } from 'utils/sonraiUtils'\nimport { getCurrentOrg } from 'auth/current-org'\n\nimport './styles.css'\n\nconst graphQLFetcher = graphQLParams => {\n const query = graphQLParams.query\n\n return fetch(`${getGraphEndpoint()}graphql`, {\n method: 'POST',\n mode: 'cors',\n cache: 'no-cache',\n credentials: 'same-origin',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${window.aat}`,\n 'sonraisecurity-com-org': getCurrentOrg(),\n },\n redirect: 'follow',\n referrer: 'no-referrer',\n body: JSON.stringify({\n query: `\n ${query}\n `,\n operationName: graphQLParams.operationName && graphQLParams.operationName,\n variables: graphQLParams.variables && graphQLParams.variables,\n }),\n }).then(response => {\n try {\n const parsed = response.json()\n return parsed\n } catch (err) {\n return {\n error: 'Error fetching response, likely due to search timeout',\n response: response,\n }\n }\n })\n}\n\nexport class Graphiql extends React.Component {\n constructor(props) {\n super(props)\n\n const searchName =\n _.get(this.props, ['location', 'state', 'searchName']) ||\n qs.parse(_.get(this.props, ['location', 'search'], '')).searchName\n const query = this.props.savedSearches.find(\n search => search.get('name') === searchName\n )\n\n const preloadQuery =\n _.get(this.props, ['location', 'state', 'query']) ||\n (query ? query.get('query') : undefined)\n const variables = query ? query.get('variables') : undefined\n const welcomeMessage = ` \n # Welcome to Advanced Search\n #\n # Advanced Search is an in-browser tool for writing, validating, and\n # testing CQL queries.\n #\n # Type queries into this side of the screen, and you will see intelligent\n # typeaheads aware of the current CQL type schema and live syntax and\n # validation errors highlighted within the text.\n #\n # CQL queries typically start with a \"{\" character. Lines that starts\n # with a # are ignored.\n #\n # An example CQL query looks like:\n #\n # {\n # field(arg: \"value\") {\n # subField\n # }\n # }\n #\n # Keyboard shortcuts:\n #\n # Prettify Query: Shift-Ctrl-P (or press the prettify button above)\n #\n # Run Query: Ctrl-Enter (or press the play button above)\n #\n # Auto Complete: Ctrl-Space (or just start typing)\n #\n `\n\n this.state = {\n query: query ? query.toJS().query : preloadQuery || welcomeMessage,\n variables: variables ? this.getVariables(variables.toJS()) : undefined,\n explorerIsOpen: false,\n metadata: null,\n srnUrlLinkParams: null,\n registedResultOnClick: false,\n }\n }\n\n componentWillUnmount() {\n const element = document.getElementsByClassName('CodeMirror-hints')\n if (element['0']) {\n const el = element['0']\n el.parentNode.removeChild(el)\n }\n }\n\n componentDidMount() {\n this.registerResultOnClick()\n }\n\n componentDidUpdate() {\n this.registerResultOnClick()\n }\n\n registerResultOnClick = () => {\n // there can be some special behaviours when the user clicks on result,\n // so we want to make sure we only register the click handler that enables\n // the behaviour one time\n if (this._graphiql && !this.state.registedResultOnClick) {\n const resultViewer = this._graphiql.resultComponent.viewer\n this.setState({ registedResultOnClick: true })\n resultViewer.on('focus', this.handleResultSelect)\n resultViewer.on('blur', this.handleResultSelect)\n resultViewer.on('cursorActivity', this.handleResultSelect)\n }\n }\n\n /**\n * This method will run when the user interacts with the search results, and\n * and set up state to enable the special behaviours\n */\n handleResultSelect = resultViewer => {\n if (!resultViewer) {\n return\n }\n const pos = resultViewer.getCursor()\n let line = resultViewer.getLine(pos.line)\n let token = resultViewer.getTokenAt(pos)\n\n // if the user has selected an SRN, we could show a link for them to nav to\n // it, so this part tries to get the SRN from the line\n if (line.trim().startsWith('\"srn\":')) {\n // line = something like `\"srn\": \"srn:blahblahblah\",`\n let srn = line\n .split(': ')[1] // take the value\n .replace('\"', '') // strip of open quote mark\n .replace('\"', '') // strip off trailing quote mark\n if (srn.endsWith(',')) {\n // strip off trailing comma\n srn = srn.substring(0, srn.length - 1)\n }\n\n // set in state is not the SRN - it is the params to navigate to that\n // node view:\n this.setState({ srnUrlLinkParams: getNodeViewPushParams(srn) })\n } else {\n this.setState({ srnUrlLinkParams: null })\n }\n\n // if the user selects metadata, we could show the metadata as a list or\n // object (toggle between views), so try to get the metadata value\n if (token.string === '\"metadata\"') {\n let currentLine = pos.line\n let line = resultViewer.getLine(currentLine).trim()\n\n // sometimes metadata is null, so just ignore this case\n if (line.includes('null')) {\n this.setState({ metadata: null })\n return\n }\n\n // sometimes the metadata is empty array, so handle this case\n if (line.endsWith(']') || line.endsWith('],')) {\n this.setState({ metadata: [] })\n }\n\n // choose whether the metadata is already being displayed as array\n // or object by it's opening character\n if (line.includes('{')) {\n this.getMetadataAsObject(resultViewer)\n } else {\n this.getMetadataAsList(resultViewer)\n }\n } else {\n // the user did not click on a metadata line in this case:\n this.setState({ metadata: null })\n }\n }\n\n /**\n * The metadata is being displayed as a list of strings - this method gets\n * the list of strings from the result viewer. The strings are one on each\n * line in the result viewer\n */\n getMetadataAsList = resultViewer => {\n const pos = resultViewer.getCursor()\n let currentLine = pos.line\n let line = resultViewer.getLine(currentLine).trim()\n\n // starting after the current line, we will iterate over all the lines in\n // the metadata until we get a close bracket, and put each line in the\n // lines list of lines\n const lines = []\n currentLine++\n line = resultViewer.getLine(currentLine).trim()\n while (line != ']' && line != '],') {\n lines.push(line)\n currentLine += 1\n line = resultViewer.getLine(currentLine).trim()\n }\n this.setState({\n metadata: {\n pos,\n value: lines,\n },\n })\n }\n\n /**\n * The metadata is being displayed as an object, and this method will\n * attempt to get the text for that object.\n */\n getMetadataAsObject = resultViewer => {\n const pos = resultViewer.getCursor()\n let currentLine = pos.line\n let line = resultViewer.getLine(currentLine)\n\n // handle case where metadata is an empty object\n if (line.endsWith('}') || line.endsWith('},')) {\n this.setState({ metadata: {} })\n }\n\n // it tries to find the end of the object by looking at how far indented\n // the start of the object is, and then finding another line with a close\n // brace on it that is also indented that far\n const prepentSpaces = line.match('[ ]+')[0]\n const endLine = prepentSpaces + '}'\n\n // begin keeping track of lines of text that represent our metadata object\n const lines = ['{']\n\n // add lines till we reach the end\n currentLine++\n line = resultViewer.getLine(currentLine)\n while (line != undefined && line !== endLine && line !== endLine + ',') {\n lines.push(line)\n currentLine++\n line = resultViewer.getLine(currentLine)\n }\n lines.push('}') // add close brace\n const content = lines.join('\\n')\n const value = JSON.parse(content)\n this.setState({ metadata: { pos, value } })\n }\n\n /**\n * The user has decided they want to change the view of the metadata, so\n * we will set a new value in the resultViewer with the metadata changed\n */\n handleSetValue = () => {\n // when the value changes in the result viewer, it scrolls to the top,\n // so create a function to call that will reset the scroll to where it\n // was before.\n let codeMirrorScroll, scrollTopBefore\n if (this._container) {\n codeMirrorScroll = this._container.querySelector(\n '.result-window .CodeMirror-scroll'\n )\n scrollTopBefore = -1\n if (codeMirrorScroll) {\n scrollTopBefore = codeMirrorScroll.scrollTop\n }\n }\n\n // we reset the scroll on the next tick of the event loop, to make sure\n // it doesn't reset before the resultViewer scrolls itself to the top\n const handleScrollReset = () => {\n setTimeout(() => {\n if (scrollTopBefore >= 0) {\n codeMirrorScroll.scrollTop = scrollTopBefore\n }\n })\n }\n\n const { pos, value } = this.state.metadata\n if (!_.isArray(value)) {\n // if the metadata is an array now, we set the view to object\n this.handleSetValueFromObject()\n handleScrollReset()\n return\n }\n\n const resultViewer = this._graphiql.resultComponent.viewer\n const currentValue = resultViewer.getValue()\n const allLines = currentValue.split('\\n')\n const newLines = [] // this will contain the new value\n\n // we add the current lines to the new lines until we reach the start of\n // the metadata object\n var lineIndex = 0\n while (lineIndex < pos.line) {\n newLines.push(allLines[lineIndex++])\n }\n\n // we transorm the lines of metadata lines text into the metadata object\n // and then stringify, and then split it by lines\n const newMetadataLines = JSON.stringify(\n metdataNestedObject(\n value.map((v, i) => {\n v = v.replace('\"', '') // replace the open \"\n if (i < value.length) {\n // if we're not on the last line, replace the close \" and the ,\n return v.substring(0, v.length - 2)\n } else {\n // otherwise just replace the close \"\n return v.substring(0, v.length - 1)\n }\n })\n ),\n null,\n 2\n ).split('\\n')\n\n // figure out how far we should indent each line\n const prepentSpaces = allLines[lineIndex].match('[ ]+')[0]\n\n // add all the lines for our metadata object\n for (var i = 0; i < newMetadataLines.length; i++) {\n var newLine = newMetadataLines[i]\n if (i === 0) {\n // if it's the first line, add the object key\n newLine = '\"metadata\": ' + newLine\n }\n newLines.push(prepentSpaces + newLine)\n }\n\n // now move the line index to after the metadata lines in the original\n // plus two extra lines that had the open and close braces on them\n lineIndex += value.length + 2\n\n // if the line after the metadata has a comma on the end, we add that here\n const lineAfter = allLines[lineIndex - 1]\n if (lineAfter.endsWith(',')) {\n newLines[newLines.length - 1] = newLines[newLines.length - 1] + ','\n }\n\n // now add all the rest of the lines from the original value\n while (lineIndex < allLines.length) {\n newLines.push(allLines[lineIndex++])\n }\n\n const newValue = newLines.join('\\n')\n resultViewer.setValue(newValue)\n handleScrollReset()\n }\n\n /**\n * Our metadata is being viewed as an object, but the user wants to transform\n * it back to be viewed as a list - this method does that and sets the value\n * on the result viewer\n */\n handleSetValueFromObject = () => {\n const { pos, value } = this.state.metadata\n\n // first we need to take the object and transorm it into the list of\n // strings which is what this method does:\n const rawLines = [] // this will contain list of strings\n const currentPath = [] // some recursive state used by addKeys\n this.addKeys(currentPath, rawLines, value)\n\n const resultViewer = this._graphiql.resultComponent.viewer\n const currentValue = resultViewer.getValue()\n const allLines = currentValue.split('\\n')\n const newLines = [] // this will hold our new value\n\n // add lines to the value that were before the metadata\n var lineIndex = 0\n while (lineIndex < pos.line) {\n newLines.push(allLines[lineIndex++])\n }\n\n // now add the metadata lines\n const prepentSpaces = allLines[lineIndex].match('[ ]+')[0]\n newLines.push(prepentSpaces + '\"metadata\": [')\n for (var i = 0; i < rawLines.length; i++) {\n var newLine = rawLines[i]\n // make sure we indent enough spaces, and add quotes around the string\n // each line gets a comma after, except for the last line\n newLines.push(\n prepentSpaces + ' ' + `\"${newLine}\"` + (i < rawLines.length ? ',' : '')\n )\n }\n newLines.push(prepentSpaces + ']')\n\n // now find where the end of the metadata object was in the original value\n // and iterate the line index until after it\n let line = allLines[lineIndex++]\n const endLine = prepentSpaces + '}'\n while (line != undefined && line !== endLine && line !== endLine + ',') {\n line = allLines[lineIndex++]\n }\n\n // if there was a comma after the metadata in the original value, add it back\n const lineAfter = allLines[lineIndex - 1]\n if (lineAfter && lineAfter.endsWith(',')) {\n newLines[newLines.length - 1] = newLines[newLines.length - 1] + ','\n }\n\n // now add the rest of the lines after the metadata\n while (lineIndex < allLines.length) {\n newLines.push(allLines[lineIndex++])\n }\n\n const newValue = newLines.join('\\n')\n resultViewer.setValue(newValue)\n }\n\n /**\n * this method is used to tranform the metadata value back into its raw\n * list of strings value\n */\n addKeys = (currentPath, rawLines, value) => {\n // add more keys for eahc value in the object\n if (_.isObject(value)) {\n Object.keys(value).forEach(key => {\n const child = value[key]\n currentPath.push(key)\n this.addKeys(currentPath, rawLines, child)\n currentPath.pop(key)\n })\n return\n }\n\n // add more keys for each thing in the array\n if (_.isArray(value)) {\n value.forEach((child, index) => {\n currentPath.push(index)\n this.addKeys(currentPath, rawLines, child)\n currentPath.pop()\n })\n return\n }\n\n // it's not a collection, so stick the value in our result\n rawLines.push(currentPath.join('.') + ':' + value)\n }\n\n getVariable = ({ name, defaultValue }) => {\n if (typeof defaultValue === 'object') {\n ;`\"${name}\": { \"value\": ${defaultValue.value} }`\n }\n return `\"${name}\": ${defaultValue}`\n }\n\n getVariables = variables => {\n if (variables) {\n const { items } = variables\n if (!_.isEmpty(items)) {\n return `\n{\n ${items.map(item => this.getVariable(item)).join(',\\n ')}\n}\n`\n }\n }\n return ''\n }\n\n loadSavedSearch = val => {\n exists(val)\n ? this.setState({\n query: val.value.query,\n variables: this.getVariables(val.value.variables),\n })\n : this.setState({ query: '', variables: '' })\n }\n\n handleQueryEdit = query => {\n this.setState({ query })\n }\n\n handleVariablesEdit = variables => {\n this.setState({ variables })\n }\n\n handleToggleExplorer = () => {\n this.setState(state => ({ explorerIsOpen: !state.explorerIsOpen }))\n }\n\n getDropdownOptions = () => {\n if (this.props.savedSearches.isEmpty()) {\n return []\n }\n return this.props.savedSearches\n .map(search =>\n fromJS({\n label: search.get('name'),\n value: {\n query: search.get('query'),\n variables: search.get('variables'),\n },\n })\n )\n .toJS()\n }\n\n handlePrettierClick = () => {\n try {\n const queryEditor = this._graphiql.queryEditorComponent.editor\n const currentValue = queryEditor.getValue()\n const prettierValue = prettier.format(currentValue, {\n parser: 'graphql',\n plugins: [graphqlParser],\n })\n queryEditor.setValue(prettierValue)\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\n 'an error occurred prettifying the query using prettier -- fallback to default implementation'\n )\n this._graphiql.handlePrettifyQuery()\n }\n }\n\n styles = {\n toolbarButton: {\n background: '#f0f0f0',\n border: '1px solid #c0c0c0',\n marginTop: '5px',\n marginLeft: '0.5em',\n marginBottom: '5px',\n height: '30px',\n paddingLeft: '1em',\n paddingRight: '1em',\n paddingTop: '0.2em',\n paddingBottom: '0.5em',\n cursor: 'pointer',\n borderRadius: '3px',\n fontFamily: 'Roboto',\n },\n }\n\n render() {\n if (!_.isEmpty(this.props.schema)) {\n const schema = buildClientSchema(this.props.schema)\n return (\n