mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
parent
2f8b0b6602
commit
51610ac6bc
@ -3,12 +3,19 @@ import * as React from 'react';
|
||||
import type { GraphQLField, GraphQLType } from 'graphql';
|
||||
import GraphQLExplorerTypeLink from './graph-ql-explorer-type-link';
|
||||
import MarkdownPreview from '../markdown-preview';
|
||||
import { astFromValue, print } from 'graphql';
|
||||
|
||||
type Props = {
|
||||
onNavigateType: (type: GraphQLType) => void,
|
||||
field: GraphQLField<any, any>,
|
||||
};
|
||||
|
||||
const printDefault = ast => {
|
||||
if (!ast) {
|
||||
return '';
|
||||
}
|
||||
return print(ast);
|
||||
};
|
||||
class GraphQLExplorerField extends React.PureComponent<Props> {
|
||||
renderDescription() {
|
||||
const { field } = this.props;
|
||||
@ -36,13 +43,20 @@ class GraphQLExplorerField extends React.PureComponent<Props> {
|
||||
<React.Fragment>
|
||||
<h2 className="graphql-explorer__subheading">Arguments</h2>
|
||||
<ul className="graphql-explorer__defs">
|
||||
{field.args.map(a => (
|
||||
<li key={a.name}>
|
||||
<span className="info">{a.name}</span>:{' '}
|
||||
<GraphQLExplorerTypeLink onNavigate={onNavigateType} type={a.type} />
|
||||
{a.description && <MarkdownPreview markdown={a.description} />}
|
||||
</li>
|
||||
))}
|
||||
{field.args.map(a => {
|
||||
let defaultValue = '';
|
||||
if ('defaultValue' in a && a.defaultValue !== undefined) {
|
||||
defaultValue = <span> = {printDefault(astFromValue(a.defaultValue, a.type))}</span>;
|
||||
}
|
||||
return (
|
||||
<li key={a.name}>
|
||||
<span className="info">{a.name}</span>:{' '}
|
||||
<GraphQLExplorerTypeLink onNavigate={onNavigateType} type={a.type} />
|
||||
{defaultValue}
|
||||
{a.description && <MarkdownPreview markdown={a.description} />}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</React.Fragment>
|
||||
);
|
||||
|
@ -4,7 +4,13 @@ import GraphQLExplorerTypeLink from './graph-ql-explorer-type-link';
|
||||
import autobind from 'autobind-decorator';
|
||||
import MarkdownPreview from '../markdown-preview';
|
||||
import GraphQLExplorerFieldLink from './graph-ql-explorer-field-link';
|
||||
import { GraphQLUnionType, GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
|
||||
import {
|
||||
GraphQLUnionType,
|
||||
GraphQLInterfaceType,
|
||||
GraphQLObjectType,
|
||||
astFromValue,
|
||||
print,
|
||||
} from 'graphql';
|
||||
import type { GraphQLType, GraphQLField, GraphQLSchema } from 'graphql';
|
||||
|
||||
type Props = {
|
||||
@ -14,6 +20,12 @@ type Props = {
|
||||
schema: GraphQLSchema | null,
|
||||
};
|
||||
|
||||
const printDefault = ast => {
|
||||
if (!ast) {
|
||||
return '';
|
||||
}
|
||||
return print(ast);
|
||||
};
|
||||
@autobind
|
||||
class GraphQLExplorerType extends React.PureComponent<Props> {
|
||||
_handleNavigateType(type: Object) {
|
||||
@ -109,11 +121,17 @@ class GraphQLExplorerType extends React.PureComponent<Props> {
|
||||
<GraphQLExplorerTypeLink onNavigate={this._handleNavigateType} type={field.type} />
|
||||
);
|
||||
|
||||
let defaultValue = '';
|
||||
if ('defaultValue' in field && field.defaultValue !== undefined) {
|
||||
defaultValue = (
|
||||
<span> = {printDefault(astFromValue(field.defaultValue, field.type))}</span>
|
||||
);
|
||||
}
|
||||
const description = field.description;
|
||||
return (
|
||||
<li key={key}>
|
||||
{fieldLink}
|
||||
{argLinks}: {typeLink}
|
||||
{argLinks}: {typeLink} {defaultValue}
|
||||
{description && (
|
||||
<div className="graphql-explorer__defs__description">
|
||||
<MarkdownPreview markdown={description} />
|
||||
|
Loading…
Reference in New Issue
Block a user