Codex Assistant
21 小时以前 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
67
68
69
const http = require('http');
 
// 使用刚才获取的有效token
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItODMzNDg4IiwicGhvbmUiOiJvZ3h4QTEtS3JTVlRkcUk5VDF1YUIxQlF3UEdVIiwiaWF0IjoxNzU5ODQwNDc2LCJleHAiOjE3NTk5MjY4NzZ9.vyGAs6TWqgHN1KRAJbTp7xMdRSh0CIy7rrbE6TqS6i0';
 
const mutation = `
mutation {
  saveUserInfo(input: {
    name: "测试用户"
    phone: "13800138000"
    gender: "MALE"
    birthday: "1990-01-01"
  }) {
    id
    name
    phone
    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('请求数据:', postData);
 
const req = http.request(options, (res) => {
  console.log(`响应状态码: ${res.statusCode}`);
  
  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();