Better schema fetching

This commit is contained in:
Gregory Schier
2023-03-31 16:02:09 -07:00
parent d36623ebc9
commit 8a117415b7
2 changed files with 9 additions and 3 deletions

View File

@@ -60,12 +60,13 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi
const editorViewRef = useRef<EditorView>(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 (

View File

@@ -2,5 +2,7 @@ import { invoke } from '@tauri-apps/api';
import type { HttpRequest, HttpResponse } from './models';
export function sendEphemeralRequest(request: HttpRequest): Promise<HttpResponse> {
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 });
}