From 7ed84c08488284612db5217a5a3588bc68f36d94 Mon Sep 17 00:00:00 2001 From: ele Date: Fri, 10 Jan 2020 17:01:27 +0200 Subject: [PATCH 1/2] adds documentation for union type --- .../graph-ql-explorer-type.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 f092555d97..846066d4b3 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 @@ -29,6 +29,33 @@ class GraphQLExplorerType extends React.PureComponent { return ; } + renderTypesMaybe() { + const { type, onNavigateType } = this.props; + + if ( + Object.prototype.toString.call(type) !== '[object GraphQLUnionType]' && + Object.prototype.toString.call(type.getTypes) !== '[object Function]' + ) { + return null; + } + // $FlowFixMe + const types = type.getTypes(); + return ( + +

Possible Types

+
    + {Object.keys(types).map(key => { + return ( +
  • + +
  • + ); + })} +
+
+ ); + } + renderFieldsMaybe() { const { type, onNavigateType } = this.props; if (typeof type.getFields !== 'function') { @@ -92,6 +119,7 @@ class GraphQLExplorerType extends React.PureComponent { return (
{this.renderDescription()} + {this.renderTypesMaybe()} {this.renderFieldsMaybe()}
); From 35a3a1eab2cf4a533b0d87b77e1244cf54040e4e Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 10 Feb 2020 13:13:19 -0500 Subject: [PATCH 2/2] Fix lint errors --- .../graph-ql-explorer-type.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 846066d4b3..c202e87311 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,6 +4,7 @@ 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'; type Props = { @@ -32,25 +33,26 @@ class GraphQLExplorerType extends React.PureComponent { renderTypesMaybe() { const { type, onNavigateType } = this.props; - if ( - Object.prototype.toString.call(type) !== '[object GraphQLUnionType]' && - Object.prototype.toString.call(type.getTypes) !== '[object Function]' - ) { + if (typeof type.getTypes !== 'function') { return null; } - // $FlowFixMe - const types = type.getTypes(); + + if (!(type instanceof GraphQLUnionType)) { + return null; + } + + const types = (type: Object).getTypes(); + + console.log('UNION TYPE? ', types); return (

Possible Types

    - {Object.keys(types).map(key => { - return ( -
  • - -
  • - ); - })} + {types.map(type => ( +
  • + +
  • + ))}
);