Codex Assistant
17 小时以前 58d9f460b2f8c34430285115e2557d18333c5cab
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
// 测试实际的用户数据结构
const fetch = require('node-fetch');
 
async function testUserData() {
  console.log('=== 测试实际用户数据结构 ===');
  
  try {
    // 使用现有的有效token
    const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItODMzNDg4IiwicGhvbmUiOiJvZ3h4QTEtS3JTVlRkcUk5VDF1YUIxQlF3UEdVIiwiaWF0IjoxNzU5ODM5NDQ1LCJleHAiOjE3NTk5MjU4NDV9.Xoq2S-zQzI3GMWxaSS2A5GGlPsR3z2BRkzg4HK3tHhE';
    console.log('使用token:', token.substring(0, 20) + '...');
    
    // 1. 使用token查询用户信息
    console.log('\n1. 查询用户信息...');
    const userProfileQuery = `
      query {
        userProfile {
          id
          name
          phone
          avatar
          gender
          birthday
          wxOpenId
          unionId
        }
      }
    `;
    
    const graphqlResponse = await fetch('http://localhost:8080/graphql', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
      },
      body: JSON.stringify({
        query: userProfileQuery
      })
    });
    
    const graphqlData = await graphqlResponse.json();
    console.log('GraphQL响应:', JSON.stringify(graphqlData, null, 2));
    
    if (graphqlData.data && graphqlData.data.userProfile) {
      const userProfile = graphqlData.data.userProfile;
      console.log('\n=== 用户信息分析 ===');
      console.log('ID:', userProfile.id);
      console.log('姓名:', userProfile.name);
      console.log('手机:', userProfile.phone);
      console.log('头像:', userProfile.avatar);
      console.log('性别:', userProfile.gender, '(类型:', typeof userProfile.gender, ')');
      console.log('生日:', userProfile.birthday, '(类型:', typeof userProfile.birthday, ')');
      console.log('微信OpenID:', userProfile.wxOpenId);
      console.log('UnionID:', userProfile.unionId);
      
      // 检查字段是否为空
      console.log('\n=== 字段检查 ===');
      console.log('性别是否为空:', userProfile.gender === null || userProfile.gender === undefined || userProfile.gender === '');
      console.log('生日是否为空:', userProfile.birthday === null || userProfile.birthday === undefined || userProfile.birthday === '');
    }
    
  } catch (error) {
    console.error('测试过程中出错:', error);
  }
}
 
testUserData();