From 8a117415b7def9437f09ae54424f3d18fd87873f Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 31 Mar 2023 16:02:09 -0700 Subject: [PATCH] Better schema fetching --- src-web/components/GraphQLEditor.tsx | 8 ++++++-- src-web/lib/sendEphemeralRequest.ts | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src-web/components/GraphQLEditor.tsx b/src-web/components/GraphQLEditor.tsx index ded05629..5b7a1840 100644 --- a/src-web/components/GraphQLEditor.tsx +++ b/src-web/components/GraphQLEditor.tsx @@ -60,12 +60,13 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi const editorViewRef = useRef(null); useEffect(() => { + let unmounted = false; const body = JSON.stringify({ query: getIntrospectionQuery(), operationName: 'IntrospectionQuery', }); - const req: HttpRequest = { ...baseRequest, body, id: '' }; - sendEphemeralRequest(req).then((response) => { + sendEphemeralRequest({ ...baseRequest, body }).then((response) => { + if (unmounted) return; try { if (editorViewRef.current) { const { data } = JSON.parse(response.body); @@ -77,6 +78,9 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi return; } }); + return () => { + unmounted = true; + }; }, [baseRequest.url]); return ( diff --git a/src-web/lib/sendEphemeralRequest.ts b/src-web/lib/sendEphemeralRequest.ts index 555fb55f..946bc121 100644 --- a/src-web/lib/sendEphemeralRequest.ts +++ b/src-web/lib/sendEphemeralRequest.ts @@ -2,5 +2,7 @@ import { invoke } from '@tauri-apps/api'; import type { HttpRequest, HttpResponse } from './models'; export function sendEphemeralRequest(request: HttpRequest): Promise { - return invoke('send_ephemeral_request', { request }); + // Ensure it's not associated with an ID + const newRequest = { ...request, id: '' }; + return invoke('send_ephemeral_request', { request: newRequest }); }