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_ACTIVITY_PLAYER_DETAIL = `
|
query GetActivityPlayerDetail($id: ID!) {
|
activityPlayerDetail(id: $id) {
|
id
|
playerInfo {
|
id
|
name
|
phone
|
description
|
avatarUrl
|
}
|
activityName
|
description
|
submissionFiles {
|
id
|
name
|
url
|
fileExt
|
fileSize
|
mediaType
|
}
|
ratingForm {
|
schemeId
|
schemeName
|
items {
|
id
|
name
|
maxScore
|
orderNo
|
}
|
totalMaxScore
|
}
|
}
|
}
|
`
|
|
/**
|
* 获取比赛报名详情(用于评分)
|
*/
|
export function getActivityPlayerDetail(id) {
|
return graphqlRequest(GET_ACTIVITY_PLAYER_DETAIL, { id })
|
}
|
|
const SAVE_ACTIVITY_PLAYER_RATING = `
|
mutation SaveActivityPlayerRating($input: ActivityPlayerRatingInput!) {
|
saveActivityPlayerRating(input: $input)
|
}
|
`
|
|
/**
|
* 保存比赛报名评分
|
*/
|
export function saveActivityPlayerRating(input) {
|
return graphqlRequest(SAVE_ACTIVITY_PLAYER_RATING, { input })
|
}
|