lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
const GRAPHQL_ENDPOINT = '/api/graphql'
 
async function graphqlRequest(query, variables = {}) {
  const response = await fetch(GRAPHQL_ENDPOINT, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ query, variables })
  })
  if (!response.ok) {
    const text = await response.text()
    throw new Error(`HTTP ${response.status}: ${text}`)
  }
  const result = await response.json()
  if (result.errors) throw new Error(result.errors.map(e => e.message).join('\\n'))
  return result.data
}
 
const GET_APPLICATIONS = `
  query GetApplications($name: String, $page: Int, $size: Int) {
    activityPlayerApplications(name: $name, page: $page, size: $size) {
      id playerName activityName phone applyTime state
    }
  }
`
 
export const PlayerApi = {
  getApplications: async (name, page, size) => {
    const data = await graphqlRequest(GET_APPLICATIONS, { name, page, size })
    return data.activityPlayerApplications || []
  }
}