From 64b6825e53a2ec69e1858fb14f256ebef1b637bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Bu=C5=82at?= Date: Sat, 7 Mar 2020 02:52:52 +0100 Subject: [PATCH] Add documentation for interfaces (#1984) Add list of implementations to Interface documentation and list of implemented interfaces to Object documentation. --- .../graph-ql-explorer-type.js | 28 +++++++++++++------ .../graph-ql-explorer/graph-ql-explorer.js | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer-type.js b/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer-type.js index c202e87311..a66b920b71 100644 --- a/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer-type.js +++ b/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer-type.js @@ -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 { } 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 ( -

Possible Types

+

{title}

    {types.map(type => (
  • diff --git a/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer.js b/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer.js index e11fd3dc5c..2ca192b4a9 100644 --- a/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer.js +++ b/packages/insomnia-app/app/ui/components/graph-ql-explorer/graph-ql-explorer.js @@ -168,6 +168,7 @@ class GraphQLExplorer extends React.PureComponent { } else if (currentType) { child = (