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 || []
|
}
|
}
|