/** * GraphQL 编辑器:Query / Variables / Headers / Auth + 响应。 */ import type { GraphqlApiNode, GraphqlRequestData, KVRow } from "../../core/index"; import { useState } from "react"; import { sendGraphqlRequest } from "../../send"; import { useWorkspace } from "../../workspaceStore"; import { KVEditor, cx } from "../common"; import { Icon } from "../icons"; import { UrlPathInput } from "../UrlPathInput"; import { AuthEditor } from "./HttpEditor"; import { ResponsePanel } from "./ResponsePanel"; const TABS = ["Query", "Variables", "Headers", "Auth"] as const; type Tab = (typeof TABS)[number]; export function GraphqlEditor({ node }: { node: GraphqlApiNode }) { const data = node.data; const update = useWorkspace((s) => s.updateRequestData); const runtime = useWorkspace((s) => s.runtime[node.id]); const [tab, setTab] = useState("Query"); const patch = (p: Partial) => update(node.id, p); const variablesValid = (() => { try { JSON.parse(data.variables || "{}"); return true; } catch { return false; } })(); return (
POST GraphQL patch({ url: v })} onKeyDown={(e) => e.key === "Enter" && sendGraphqlRequest(node)} />
{TABS.map((t) => ( ))}
{tab === "Query" && (