const http = require('http');
|
|
// 使用刚才获取的有效token
|
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItODMzNDg4IiwicGhvbmUiOiJvZ3h4QTEtS3JTVlRkcUk5VDF1YUIxQlF3UEdVIiwiaWF0IjoxNzU5ODQwNDc2LCJleHAiOjE3NTk5MjY4NzZ9.vyGAs6TWqgHN1KRAJbTp7xMdRSh0CIy7rrbE6TqS6i0';
|
|
const mutation = `
|
mutation {
|
saveUserInfo(input: {
|
name: "测试用户"
|
phone: "13800138000"
|
avatar: "https://example.com/avatar.jpg"
|
gender: "male"
|
birthday: "1990-01-01"
|
}) {
|
id
|
name
|
phone
|
avatar
|
gender
|
birthday
|
}
|
}`;
|
|
const postData = JSON.stringify({
|
query: mutation
|
});
|
|
const options = {
|
hostname: 'localhost',
|
port: 8080,
|
path: '/api/graphql',
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
'Content-Length': Buffer.byteLength(postData),
|
'Authorization': `Bearer ${token}`
|
}
|
};
|
|
console.log('发送GraphQL请求测试saveUserInfo...');
|
console.log('Token:', token.substring(0, 50) + '...');
|
console.log('请求数据:', postData);
|
|
const req = http.request(options, (res) => {
|
console.log(`响应状态码: ${res.statusCode}`);
|
console.log('响应头:', res.headers);
|
|
let data = '';
|
res.on('data', (chunk) => {
|
data += chunk;
|
});
|
|
res.on('end', () => {
|
console.log('响应内容:', data);
|
try {
|
const response = JSON.parse(data);
|
if (response.errors) {
|
console.log('GraphQL错误:', response.errors);
|
} else {
|
console.log('成功响应:', response.data);
|
}
|
} catch (e) {
|
console.log('解析响应失败:', e.message);
|
}
|
});
|
});
|
|
req.on('error', (e) => {
|
console.error(`请求错误: ${e.message}`);
|
});
|
|
req.write(postData);
|
req.end();
|