diff --git a/src/app/services/actions/query-action-creator-util.ts b/src/app/services/actions/query-action-creator-util.ts index e87f17890..807d1dcd5 100644 --- a/src/app/services/actions/query-action-creator-util.ts +++ b/src/app/services/actions/query-action-creator-util.ts @@ -70,7 +70,8 @@ export function createAnonymousRequest(query: IQuery, proxyUrl: string, queryRun const options: IRequestOptions = { method: query.selectedVerb, - headers + headers, + body: query.sampleBody ? JSON.stringify(query.sampleBody) : undefined }; return { graphUrl, options }; } diff --git a/src/app/views/query-runner/query-input/QueryInput.tsx b/src/app/views/query-runner/query-input/QueryInput.tsx index c46556536..ad6818ed3 100644 --- a/src/app/views/query-runner/query-input/QueryInput.tsx +++ b/src/app/views/query-runner/query-input/QueryInput.tsx @@ -10,6 +10,7 @@ import { getStyleFor } from '../../../utils/http-methods.utils'; import { parseSampleUrl } from '../../../utils/sample-url-generation'; import { translateMessage } from '../../../utils/translate-messages'; import SubmitButton from '../../../views/common/submit-button/SubmitButton'; +import { shouldRunQuery } from '../../sidebar/sample-queries/sample-query-utils'; import { queryRunnerStyles } from '../QueryRunner.styles'; import { AutoComplete } from './auto-complete'; import { ShareButton } from './share-query'; @@ -36,7 +37,10 @@ const QueryInput = (props: IQueryInputProps) => { const authenticated = !!authToken.token; const { mobileScreen } = sidebarProperties; - const showError = !authenticated && sampleQuery.selectedVerb !== 'GET'; + const showError = !shouldRunQuery({ + method: sampleQuery.selectedVerb, authenticated, + url: sampleQuery.sampleUrl + }); const { queryButtonStyles, verbSelector, shareQueryButtonStyles } = queryRunnerStyles(); verbSelector.title = { ...verbSelector.title, diff --git a/src/app/views/sidebar/sample-queries/SampleQueries.tsx b/src/app/views/sidebar/sample-queries/SampleQueries.tsx index 3906e5c1d..dd7a24daf 100644 --- a/src/app/views/sidebar/sample-queries/SampleQueries.tsx +++ b/src/app/views/sidebar/sample-queries/SampleQueries.tsx @@ -25,7 +25,7 @@ import { classNames } from '../../classnames'; import { NoResultsFound } from '../sidebar-utils/SearchResult'; import { sidebarStyles } from '../Sidebar.styles'; import { - isJsonString, performSearch, trackDocumentLinkClickedEvent, + isJsonString, performSearch, shouldRunQuery, trackDocumentLinkClickedEvent, trackSampleQueryClickEvent } from './sample-query-utils'; @@ -167,7 +167,7 @@ const UnstyledSampleQueries = (sampleProps?: ISampleQueriesProps): JSX.Element = onRender: (item: ISampleQuery) => { const signInText = translateMessage('Sign In to try this sample'); - if (item.method === 'GET' || tokenPresent) { + if (shouldRunQuery({ method: item.method, authenticated: tokenPresent, url: item.requestUrl })) { return
; } @@ -270,7 +270,8 @@ const UnstyledSampleQueries = (sampleProps?: ISampleQueriesProps): JSX.Element = } if (props) { - if (!tokenPresent && props.item.method !== 'GET') { + const query: ISampleQuery = props.item!; + if (!shouldRunQuery({ method: query.method, authenticated: tokenPresent, url: query.requestUrl })) { selectionDisabled = true; } return ( @@ -280,7 +281,6 @@ const UnstyledSampleQueries = (sampleProps?: ISampleQueriesProps): JSX.Element = styles={customStyles} onClick={() => { if (!selectionDisabled) { - const query: ISampleQuery = props.item!; querySelected(query); } setSelectedQuery(props.item) diff --git a/src/app/views/sidebar/sample-queries/sample-query-utils.ts b/src/app/views/sidebar/sample-queries/sample-query-utils.ts index f3fc31fde..f1c45c2fe 100644 --- a/src/app/views/sidebar/sample-queries/sample-query-utils.ts +++ b/src/app/views/sidebar/sample-queries/sample-query-utils.ts @@ -4,7 +4,7 @@ import { GRAPH_URL } from '../../../services/graph-constants'; import { validateExternalLink } from '../../../utils/external-link-validation'; import { sanitizeQueryUrl } from '../../../utils/query-url-sanitization'; -export function isJsonString(str: string): boolean { +function isJsonString(str: string): boolean { try { JSON.parse(str); return true; @@ -13,7 +13,7 @@ export function isJsonString(str: string): boolean { } } -export function performSearch(queries: ISampleQuery[], value: string): ISampleQuery[] { +function performSearch(queries: ISampleQuery[], value: string): ISampleQuery[] { const keyword = value.toLowerCase(); return queries.filter((sample: any) => { const name = sample.humanName.toLowerCase(); @@ -22,7 +22,7 @@ export function performSearch(queries: ISampleQuery[], value: string): ISampleQu }); } -export const trackSampleQueryClickEvent = (query: ISampleQuery) => { +const trackSampleQueryClickEvent = (query: ISampleQuery) => { const sanitizedUrl = sanitizeQueryUrl(GRAPH_URL + query.requestUrl); telemetry.trackEvent( eventTypes.LISTITEM_CLICK_EVENT, @@ -35,7 +35,7 @@ export const trackSampleQueryClickEvent = (query: ISampleQuery) => { }); } -export const trackDocumentLinkClickedEvent = async (item: ISampleQuery): Promise