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:
Bartek Bułat
2020-03-07 02:52:52 +01:00
committed by GitHub
parent 9fe45a8ebb
commit 64b6825e53
2 changed files with 20 additions and 9 deletions

View File

@@ -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}>

View File

@@ -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}