mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-24 16:51:06 -04:00
Add documentation for interfaces (#1984)
Add list of implementations to Interface documentation and list of implemented interfaces to Object documentation.
This commit is contained in:
@@ -4,13 +4,14 @@ 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 } from 'graphql';
|
||||
import type { GraphQLType, GraphQLField } from 'graphql';
|
||||
import { GraphQLUnionType, GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
|
||||
import type { GraphQLType, GraphQLField, GraphQLSchema } from 'graphql';
|
||||
|
||||
type Props = {
|
||||
onNavigateType: (type: Object) => void,
|
||||
onNavigateField: (field: Object) => void,
|
||||
type: GraphQLType,
|
||||
schema: GraphQLSchema | null,
|
||||
};
|
||||
|
||||
@autobind
|
||||
@@ -31,22 +32,31 @@ class GraphQLExplorerType extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
renderTypesMaybe() {
|
||||
const { type, onNavigateType } = this.props;
|
||||
const { schema, type, onNavigateType } = this.props;
|
||||
|
||||
if (typeof type.getTypes !== 'function') {
|
||||
if (schema === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(type instanceof GraphQLUnionType)) {
|
||||
let title = 'Types';
|
||||
let types = [];
|
||||
|
||||
if (type instanceof GraphQLUnionType) {
|
||||
title = 'Possible Types';
|
||||
types = schema.getPossibleTypes(type);
|
||||
} else if (type instanceof GraphQLInterfaceType) {
|
||||
title = 'Implementations';
|
||||
types = schema.getPossibleTypes(type);
|
||||
} else if (type instanceof GraphQLObjectType) {
|
||||
title = 'Implements';
|
||||
types = type.getInterfaces();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
const types = (type: Object).getTypes();
|
||||
|
||||
console.log('UNION TYPE? ', types);
|
||||
return (
|
||||
<React.Fragment>
|
||||
<h2 className="graphql-explorer__subheading">Possible Types</h2>
|
||||
<h2 className="graphql-explorer__subheading">{title}</h2>
|
||||
<ul className="graphql-explorer__defs">
|
||||
{types.map(type => (
|
||||
<li key={type.name}>
|
||||
|
||||
@@ -168,6 +168,7 @@ class GraphQLExplorer extends React.PureComponent<Props, State> {
|
||||
} else if (currentType) {
|
||||
child = (
|
||||
<GraphQLExplorerType
|
||||
schema={schema}
|
||||
type={currentType}
|
||||
onNavigateType={this._handleNavigateType}
|
||||
onNavigateField={this._handleNavigateField}
|
||||
|
||||
Reference in New Issue
Block a user