Fix GraphQL schema getting nuked on codemirror language refresh

This commit is contained in:
Gregory Schier
2025-07-21 14:17:36 -07:00
parent 7eb3f123c6
commit c609d0ff0c
4 changed files with 23 additions and 16 deletions

View File

@@ -1,10 +1,9 @@
import type { EditorView } from '@codemirror/view';
import type { HttpRequest } from '@yaakapp-internal/models';
import { updateSchema } from 'cm6-graphql';
import { formatSdl } from 'format-graphql';
import { useAtom } from 'jotai';
import { useEffect, useMemo, useRef } from 'react';
import { useMemo, useRef } from 'react';
import { useLocalStorage } from 'react-use';
import { useIntrospectGraphQL } from '../../hooks/useIntrospectGraphQL';
import { useStateWithDeps } from '../../hooks/useStateWithDeps';
@@ -63,12 +62,6 @@ export function GraphQLEditor({ request, onChange, baseRequest, ...extraEditorPr
onChange(newBody);
};
// Refetch the schema when the URL changes
useEffect(() => {
if (editorViewRef.current == null) return;
updateSchema(editorViewRef.current, schema ?? undefined);
}, [schema]);
const actions = useMemo<EditorProps['actions']>(
() => [
<div key="actions" className="flex flex-row !opacity-100 !shadow">
@@ -201,6 +194,7 @@ export function GraphQLEditor({ request, onChange, baseRequest, ...extraEditorPr
<Editor
language="graphql"
heightMode="auto"
graphQLSchema={schema}
format={formatSdl}
defaultValue={currentBody.query}
onChange={handleChangeQuery}