// 测试实际的用户数据结构
|
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();
|