| 892 | if (!backend && !cypherQuery) return; |
| 893 | |
| 894 | const fetchData = async () => { |
| 895 | setLoading(true); |
| 896 | setError(null); |
| 897 | try { |
| 898 | const url = new URL("/api/graph", backend || window.location.origin); |
| 899 | if (repoPath) url.searchParams.append("repo_path", repoPath); |
| 900 | if (cypherQuery) url.searchParams.append("cypher_query", cypherQuery); |
| 901 | |
| 902 | const response = await fetch(url.toString()); |
| 903 | if (!response.ok) { |
| 904 | const errData = await response.json().catch(() => ({})); |
| 905 | throw new Error(errData.detail || `Server error (${response.status})`); |
| 906 | } |
| 907 | |
| 908 | const data = await response.json(); |
| 909 | setGraphData(data); |
| 910 | } catch (err: any) { |
| 911 | console.error("Fetch Error:", err); |
| 912 | setError(err.message); |
| 913 | toast.error("Failed to connect to local index: " + err.message); |
| 914 | } finally { |
| 915 | setLoading(false); |
| 916 | } |
| 917 | }; |
| 918 | |
| 919 | fetchData(); |
| 920 | }, [backend, repoPath, cypherQuery]); |