<template>
|
<div class="graphql-test">
|
<h2>GraphQL连接测试</h2>
|
|
<div class="test-section">
|
<h3>测试1: 基本连接测试</h3>
|
<button @click="testBasicConnection" :disabled="loading">
|
{{ loading ? '测试中...' : '测试基本连接' }}
|
</button>
|
<div v-if="basicResult" class="result">
|
<h4>结果:</h4>
|
<pre>{{ JSON.stringify(basicResult, null, 2) }}</pre>
|
</div>
|
<div v-if="basicError" class="error">
|
<h4>错误:</h4>
|
<pre>{{ basicError }}</pre>
|
</div>
|
</div>
|
|
<div class="test-section">
|
<h3>测试2: 活动参赛者详情查询</h3>
|
<input v-model="testPlayerId" placeholder="输入参赛者ID" />
|
<button @click="testPlayerDetail" :disabled="loading || !testPlayerId">
|
{{ loading ? '查询中...' : '查询参赛者详情' }}
|
</button>
|
<div v-if="playerResult" class="result">
|
<h4>结果:</h4>
|
<pre>{{ JSON.stringify(playerResult, null, 2) }}</pre>
|
</div>
|
<div v-if="playerError" class="error">
|
<h4>错误:</h4>
|
<pre>{{ playerError }}</pre>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { ref } from 'vue'
|
import { graphqlRequest } from '@/config/api'
|
|
const loading = ref(false)
|
const basicResult = ref(null)
|
const basicError = ref('')
|
const playerResult = ref(null)
|
const playerError = ref('')
|
const testPlayerId = ref('1')
|
|
// 使用统一的GraphQL请求函数
|
|
// 测试基本连接
|
const testBasicConnection = async () => {
|
loading.value = true
|
basicResult.value = null
|
basicError.value = ''
|
|
try {
|
const query = `
|
query {
|
__schema {
|
types {
|
name
|
}
|
}
|
}
|
`
|
|
const result = await graphqlRequest(query)
|
basicResult.value = {
|
message: 'GraphQL连接成功!',
|
typeCount: result.__schema.types.length,
|
sampleTypes: result.__schema.types.slice(0, 5).map((t: any) => t.name)
|
}
|
} catch (error) {
|
basicError.value = error instanceof Error ? error.message : '未知错误'
|
} finally {
|
loading.value = false
|
}
|
}
|
|
// 测试参赛者详情查询
|
const testPlayerDetail = async () => {
|
loading.value = true
|
playerResult.value = null
|
playerError.value = ''
|
|
try {
|
const query = `
|
query ActivityPlayerDetail($id: ID!) {
|
activityPlayerDetail(id: $id) {
|
id
|
playerInfo {
|
id
|
name
|
phone
|
description
|
avatarUrl
|
}
|
regionInfo {
|
id
|
name
|
fullPath
|
}
|
activityName
|
description
|
submissionFiles {
|
id
|
name
|
url
|
fileExt
|
fileSize
|
mediaType
|
}
|
}
|
}
|
`
|
|
const result = await graphqlRequest(query, { id: testPlayerId.value })
|
playerResult.value = result
|
} catch (error) {
|
playerError.value = error instanceof Error ? error.message : '未知错误'
|
} finally {
|
loading.value = false
|
}
|
}
|
</script>
|
|
<style scoped>
|
.graphql-test {
|
padding: 20px;
|
max-width: 800px;
|
margin: 0 auto;
|
}
|
|
.test-section {
|
margin-bottom: 30px;
|
padding: 20px;
|
border: 1px solid #ddd;
|
border-radius: 8px;
|
}
|
|
.test-section h3 {
|
margin-top: 0;
|
color: #333;
|
}
|
|
button {
|
padding: 8px 16px;
|
margin: 10px 5px 10px 0;
|
background-color: #007bff;
|
color: white;
|
border: none;
|
border-radius: 4px;
|
cursor: pointer;
|
}
|
|
button:disabled {
|
background-color: #ccc;
|
cursor: not-allowed;
|
}
|
|
input {
|
padding: 8px;
|
margin: 10px 5px 10px 0;
|
border: 1px solid #ddd;
|
border-radius: 4px;
|
width: 200px;
|
}
|
|
.result {
|
margin-top: 15px;
|
padding: 10px;
|
background-color: #d4edda;
|
border: 1px solid #c3e6cb;
|
border-radius: 4px;
|
}
|
|
.error {
|
margin-top: 15px;
|
padding: 10px;
|
background-color: #f8d7da;
|
border: 1px solid #f5c6cb;
|
border-radius: 4px;
|
}
|
|
pre {
|
white-space: pre-wrap;
|
word-wrap: break-word;
|
font-size: 12px;
|
margin: 5px 0 0 0;
|
}
|
</style>
|