| | |
| | | // Dashboard API |
| | | const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql'; |
| | | import { graphqlRequest } from '../config/api' |
| | | |
| | | // GraphQL 查询语句 |
| | | const GET_DASHBOARD_STATS_QUERY = ` |
| | |
| | | |
| | | // API 函数 |
| | | export const getDashboardStats = async () => { |
| | | const response = await fetch(GRAPHQL_ENDPOINT, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | body: JSON.stringify({ |
| | | query: GET_DASHBOARD_STATS_QUERY |
| | | }) |
| | | }); |
| | | |
| | | const result = await response.json(); |
| | | if (result.errors) { |
| | | throw new Error(result.errors[0].message); |
| | | } |
| | | return result.data.dashboardStats; |
| | | const data = await graphqlRequest(GET_DASHBOARD_STATS_QUERY); |
| | | return data.dashboardStats; |
| | | }; |