const axios = require('axios'); // 配置 const GRAPHQL_URL = 'http://localhost:8080/api/graphql'; // 查询媒体记录的GraphQL查询 const MEDIAS_BY_TARGET_QUERY = ` query MediasByTarget($targetType: Int!, $targetId: ID!) { mediasByTarget(targetType: $targetType, targetId: $targetId) { id name path fileExt mediaType fullUrl } } `; async function testMediaQuery() { console.log('🔍 测试媒体查询接口...\n'); // 测试查询选手头像媒体记录 (targetType: 1, targetId: 42) console.log('1. 查询选手头像媒体记录 (targetType: 1, targetId: 42)...'); try { const response = await axios.post(GRAPHQL_URL, { query: MEDIAS_BY_TARGET_QUERY, variables: { targetType: 1, targetId: "42" } }); console.log('选手头像媒体记录:', JSON.stringify(response.data, null, 2)); } catch (error) { console.error('查询选手头像媒体记录失败:', error.response?.data || error.message); } console.log('\n2. 查询活动报名附件媒体记录 (targetType: 2, targetId: 32)...'); try { const response = await axios.post(GRAPHQL_URL, { query: MEDIAS_BY_TARGET_QUERY, variables: { targetType: 2, targetId: "32" } }); console.log('活动报名附件媒体记录:', JSON.stringify(response.data, null, 2)); } catch (error) { console.error('查询活动报名附件媒体记录失败:', error.response?.data || error.message); } } testMediaQuery().catch(console.error);