lrj
1 天以前 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<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>