lrj
昨天 9f8395fab13ca4b230a0f7d62636e209745c91d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Dashboard API
const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql';
 
// GraphQL 查询语句
const GET_DASHBOARD_STATS_QUERY = `
  query GetDashboardStats {
    dashboardStats {
      activeActivities
      totalPlayers
      pendingReviews
      totalJudges
    }
  }
`;
 
// 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;
};