From 8683a41405ba1cad38628441091e88dd33fedd66 Mon Sep 17 00:00:00 2001 From: Zolwiastyl <45352717+Zolwiastyl@users.noreply.github.com> Date: Wed, 10 May 2023 10:03:58 +0200 Subject: [PATCH] feat: add all schema types in classic schema documentation (#3077) --- .changeset/afraid-papayas-confess.md | 5 ++++ .../components/schema-documentation.tsx | 26 +++++++++++++++++++ .../src/explorer/components/section.tsx | 4 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .changeset/afraid-papayas-confess.md diff --git a/.changeset/afraid-papayas-confess.md b/.changeset/afraid-papayas-confess.md new file mode 100644 index 00000000000..7c73bf4a6d6 --- /dev/null +++ b/.changeset/afraid-papayas-confess.md @@ -0,0 +1,5 @@ +--- +'@graphiql/react': patch +--- + +show all schema types in explorer diff --git a/packages/graphiql-react/src/explorer/components/schema-documentation.tsx b/packages/graphiql-react/src/explorer/components/schema-documentation.tsx index 481dc87cf67..f4eced066fc 100644 --- a/packages/graphiql-react/src/explorer/components/schema-documentation.tsx +++ b/packages/graphiql-react/src/explorer/components/schema-documentation.tsx @@ -17,6 +17,12 @@ export function SchemaDocumentation(props: SchemaDocumentationProps) { const queryType = props.schema.getQueryType(); const mutationType = props.schema.getMutationType?.(); const subscriptionType = props.schema.getSubscriptionType?.(); + const typeMap = props.schema.getTypeMap(); + const ignoreTypesInAllSchema = [ + queryType?.name, + mutationType?.name, + subscriptionType?.name, + ]; return ( <> @@ -49,6 +55,26 @@ export function SchemaDocumentation(props: SchemaDocumentationProps) { )} + + {typeMap && ( + + {Object.values(typeMap).map(type => { + if ( + ignoreTypesInAllSchema.includes(type.name) || + type.name.startsWith('__') + ) { + return null; + } + + return ( + + + + ); + })} + + )} + > ); } diff --git a/packages/graphiql-react/src/explorer/components/section.tsx b/packages/graphiql-react/src/explorer/components/section.tsx index 4071889a2a1..4204d528f6f 100644 --- a/packages/graphiql-react/src/explorer/components/section.tsx +++ b/packages/graphiql-react/src/explorer/components/section.tsx @@ -33,7 +33,8 @@ type ExplorerSectionProps = { | 'Possible Types' | 'Enum Values' | 'Deprecated Enum Values' - | 'Directives'; + | 'Directives' + | 'All Schema Types'; }; export function ExplorerSection(props: ExplorerSectionProps) { @@ -64,4 +65,5 @@ const TYPE_TO_ICON: Record = { 'Possible Types': TypeIcon, 'Root Types': RootTypeIcon, Type: TypeIcon, + 'All Schema Types': TypeIcon, };