Use X-HTTP-Method-Override UI to show GraphQL as well (Closes #1780)

This commit is contained in:
Gregory Schier 2019-12-04 13:45:09 -05:00
parent 1e3da598cd
commit d330bb5c70
4 changed files with 19 additions and 10 deletions

View File

@ -118,7 +118,7 @@ export function removeVowels(str: string): string {
} }
export function formatMethodName(method: string): string { export function formatMethodName(method: string): string {
let methodName = method; let methodName = method || '';
if (method === METHOD_DELETE || method === METHOD_OPTIONS) { if (method === METHOD_DELETE || method === METHOD_OPTIONS) {
methodName = method.slice(0, 3); methodName = method.slice(0, 3);
} else if (method.length > 4) { } else if (method.length > 4) {

View File

@ -11,6 +11,7 @@ import MethodTag from '../tags/method-tag';
import * as models from '../../../models'; import * as models from '../../../models';
import { showModal } from '../modals/index'; import { showModal } from '../modals/index';
import RequestSettingsModal from '../modals/request-settings-modal'; import RequestSettingsModal from '../modals/request-settings-modal';
import { CONTENT_TYPE_GRAPHQL } from '../../../common/constants';
@autobind @autobind
class SidebarRequestRow extends PureComponent { class SidebarRequestRow extends PureComponent {
@ -60,12 +61,20 @@ class SidebarRequestRow extends PureComponent {
} }
_getMethodOverrideHeaderValue() { _getMethodOverrideHeaderValue() {
let header = this.props.request.headers.find( const { request } = this.props;
h => h.name.toLowerCase() === 'x-http-method-override',
); const header = request.headers.find(h => h.name.toLowerCase() === 'x-http-method-override');
if (!header || header.disabled) header = null;
else header = header.value; if (header) {
return header; return header.value;
}
// If no override, use GraphQL as override if it's a gql request
if (request.body && request.body.mimeType === CONTENT_TYPE_GRAPHQL) {
return 'GQL';
}
return null;
} }
setDragDirection(dragDirection) { setDragDirection(dragDirection) {

View File

@ -1,18 +1,17 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { HTTP_METHODS } from '../../../common/constants';
import * as util from '../../../common/misc'; import * as util from '../../../common/misc';
class MethodTag extends PureComponent { class MethodTag extends PureComponent {
render() { render() {
const { method, override, fullNames } = this.props; const { method, override, fullNames } = this.props;
let methodName = method; let methodName = method;
let overrideName = override; let overrideName = override;
if (!HTTP_METHODS.includes(override)) overrideName = null;
if (!fullNames) { if (!fullNames) {
methodName = util.formatMethodName(method); methodName = util.formatMethodName(method);
if (overrideName) overrideName = util.formatMethodName(override); overrideName = override ? util.formatMethodName(override) : override;
} }
return ( return (

View File

@ -75,6 +75,7 @@
} }
.surprise, .surprise,
.http-method-GQL,
.http-method-GET { .http-method-GET {
color: var(--color-surprise) !important; color: var(--color-surprise) !important;
} }