Replace format-graphql with pretty_graphql for comment-preserving GraphQL formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-03-05 15:53:13 -08:00
parent cfab62707e
commit a0cb7f813f
9 changed files with 113 additions and 344 deletions

View File

@@ -1,6 +1,5 @@
import type { HttpRequest } from '@yaakapp-internal/models';
import { formatSdl } from 'format-graphql';
import { useAtom } from 'jotai';
import { useCallback, useMemo } from 'react';
import { useLocalStorage } from 'react-use';
@@ -16,6 +15,7 @@ import { Editor } from '../core/Editor/LazyEditor';
import { FormattedError } from '../core/FormattedError';
import { Icon } from '../core/Icon';
import { Separator } from '../core/Separator';
import { tryFormatGraphql } from '../../lib/formatters';
import { showGraphQLDocExplorerAtom } from './graphqlAtoms';
type Props = Pick<EditorProps, 'heightMode' | 'className' | 'forceUpdateKey'> & {
@@ -211,7 +211,7 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
language="graphql"
heightMode="auto"
graphQLSchema={schema}
format={formatSdl}
format={tryFormatGraphql}
defaultValue={currentBody.query}
onChange={handleChangeQuery}
placeholder="..."

View File

@@ -20,6 +20,18 @@ export async function tryFormatJson(text: string): Promise<string> {
return text;
}
export async function tryFormatGraphql(text: string): Promise<string> {
if (text === '') return text;
try {
return await invokeCmd<string>('cmd_format_graphql', { text });
} catch (err) {
console.warn('Failed to format GraphQL', err);
}
return text;
}
export async function tryFormatXml(text: string): Promise<string> {
if (text === '') return text;

View File

@@ -17,6 +17,7 @@ type TauriCmd =
| 'cmd_delete_send_history'
| 'cmd_dismiss_notification'
| 'cmd_export_data'
| 'cmd_format_graphql'
| 'cmd_format_json'
| 'cmd_get_http_authentication_config'
| 'cmd_get_http_authentication_summaries'

View File

@@ -1,2 +1 @@
declare module 'format-graphql';
declare module 'vkbeautify';

View File

@@ -47,7 +47,6 @@
"deep-equal": "^2.2.3",
"eventemitter3": "^5.0.1",
"focus-trap-react": "^11.0.4",
"format-graphql": "^1.5.0",
"fuzzbunny": "^1.0.1",
"hexy": "^0.3.5",
"history": "^5.3.0",