From d86549f4920b463cf6bfaf01534f03c77bdf3c29 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 21 Mar 2025 07:28:08 -0700 Subject: [PATCH] Always show GQL schema dropdown. Fixes https://feedback.yaak.app/p/unable-to-disable-graphql-automatic-introspection --- src-web/components/GraphQLEditor.tsx | 82 +++++++++++++++------------ src-web/components/core/Dropdown.tsx | 10 +++- src-web/hooks/useIntrospectGraphQL.ts | 3 +- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/src-web/components/GraphQLEditor.tsx b/src-web/components/GraphQLEditor.tsx index fd34b55c..aac0b28c 100644 --- a/src-web/components/GraphQLEditor.tsx +++ b/src-web/components/GraphQLEditor.tsx @@ -7,6 +7,7 @@ import { useEffect, useMemo, useRef, useState } from 'react'; import { useLocalStorage } from 'react-use'; import { useIntrospectGraphQL } from '../hooks/useIntrospectGraphQL'; import { showDialog } from '../lib/dialog'; +import { Banner } from './core/Banner'; import { Button } from './core/Button'; import { Dropdown } from './core/Dropdown'; import type { EditorProps } from './core/Editor/Editor'; @@ -64,9 +65,50 @@ export function GraphQLEditor({ request, onChange, baseRequest, ...extraEditorPr const actions = useMemo( () => [
- {schema === undefined ? null /* Initializing */ : !error ? ( + {schema === undefined ? null /* Initializing */ : ( +

Schema introspection failed

+ +
+ + ), + }); + }} + > + View Error + + + ), + type: 'content', + }, { label: 'Refetch', leftSlot: , @@ -105,44 +147,12 @@ export function GraphQLEditor({ request, onChange, baseRequest, ...extraEditorPr variant="border" title="Refetch Schema" isLoading={isLoading} - color={isLoading || schema ? 'default' : 'warning'} + color={error ? 'danger' : 'default'} + forDropdown > - {isLoading ? 'Introspecting' : schema ? 'Schema' : 'No Schema'} + {error ? 'Introspection Failed' : schema ? 'Schema' : 'No Schema'} - ) : ( - - - - ), - }); - }} - > - Introspection Failed - )} , ], diff --git a/src-web/components/core/Dropdown.tsx b/src-web/components/core/Dropdown.tsx index 0c4f20dd..97f6349a 100644 --- a/src-web/components/core/Dropdown.tsx +++ b/src-web/components/core/Dropdown.tsx @@ -558,7 +558,15 @@ const Menu = forwardRef + // eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events +
{ + // Ensure the dropdown is closed when anything in the content is clicked + onClose(); + }} + > {item.label}
); diff --git a/src-web/hooks/useIntrospectGraphQL.ts b/src-web/hooks/useIntrospectGraphQL.ts index 58814e40..02f97bc3 100644 --- a/src-web/hooks/useIntrospectGraphQL.ts +++ b/src-web/hooks/useIntrospectGraphQL.ts @@ -51,7 +51,7 @@ export function useIntrospectGraphQL( const bodyText = await getResponseBodyText(response); if (response.status < 200 || response.status >= 300) { - return setError(`Request failed with status ${response.status}.\n\n${bodyText}`); + return setError(`Request failed with status ${response.status}.\nThe response body is:\n\n${bodyText}`); } if (bodyText === null) { @@ -80,6 +80,7 @@ export function useIntrospectGraphQL( }, [request.id, request.url, request.method, activeEnvironment?.id]); const clear = useCallback(async () => { + setError(''); await setIntrospection(null); }, [setIntrospection]);