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 {
let methodName = method;
let methodName = method || '';
if (method === METHOD_DELETE || method === METHOD_OPTIONS) {
methodName = method.slice(0, 3);
} else if (method.length > 4) {

View File

@ -11,6 +11,7 @@ import MethodTag from '../tags/method-tag';
import * as models from '../../../models';
import { showModal } from '../modals/index';
import RequestSettingsModal from '../modals/request-settings-modal';
import { CONTENT_TYPE_GRAPHQL } from '../../../common/constants';
@autobind
class SidebarRequestRow extends PureComponent {
@ -60,12 +61,20 @@ class SidebarRequestRow extends PureComponent {
}
_getMethodOverrideHeaderValue() {
let header = this.props.request.headers.find(
h => h.name.toLowerCase() === 'x-http-method-override',
);
if (!header || header.disabled) header = null;
else header = header.value;
return header;
const { request } = this.props;
const header = request.headers.find(h => h.name.toLowerCase() === 'x-http-method-override');
if (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) {

View File

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

View File

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