lrj
21 小时以前 9f8395fab13ca4b230a0f7d62636e209745c91d4
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
const axios = require('axios');
 
// 测试新的手机号获取API
async function testNewPhoneAPI() {
    const graphqlEndpoint = 'http://localhost:8080/api/graphql';
    
    // 测试GraphQL schema是否包含新的mutation
    const introspectionQuery = `
        query IntrospectionQuery {
            __schema {
                mutationType {
                    fields {
                        name
                        description
                        args {
                            name
                            type {
                                name
                                kind
                            }
                        }
                        type {
                            name
                            kind
                        }
                    }
                }
            }
        }
    `;
    
    try {
        console.log('🔍 检查GraphQL schema中的mutation...');
        const introspectionResponse = await axios.post(graphqlEndpoint, {
            query: introspectionQuery
        }, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        
        if (introspectionResponse.data.errors) {
            console.error('❌ GraphQL introspection错误:', introspectionResponse.data.errors);
            return;
        }
        
        const mutations = introspectionResponse.data.data.__schema.mutationType.fields;
        console.log('📋 可用的mutations:');
        mutations.forEach(mutation => {
            console.log(`  - ${mutation.name}: ${mutation.description || '无描述'}`);
            if (mutation.args && mutation.args.length > 0) {
                console.log(`    参数: ${mutation.args.map(arg => `${arg.name}(${arg.type.name || arg.type.kind})`).join(', ')}`);
            }
        });
        
        // 检查是否存在新的getPhoneNumberByCode mutation
        const newPhoneAPI = mutations.find(m => m.name === 'getPhoneNumberByCode');
        if (newPhoneAPI) {
            console.log('✅ 找到新的手机号获取API: getPhoneNumberByCode');
            console.log('   参数:', newPhoneAPI.args.map(arg => `${arg.name}(${arg.type.name || arg.type.kind})`).join(', '));
            console.log('   返回类型:', newPhoneAPI.type.name);
        } else {
            console.log('❌ 未找到新的手机号获取API: getPhoneNumberByCode');
        }
        
        // 检查旧的API是否还存在
        const oldPhoneAPI = mutations.find(m => m.name === 'decryptPhoneNumber');
        if (oldPhoneAPI) {
            console.log('✅ 旧的手机号获取API仍然存在: decryptPhoneNumber');
        }
        
        // 测试新API调用(使用模拟的code)
        console.log('\n🧪 测试新API调用...');
        const testMutation = `
            mutation TestGetPhoneNumberByCode($code: String!) {
                getPhoneNumberByCode(code: $code) {
                    phoneNumber
                    purePhoneNumber
                    countryCode
                }
            }
        `;
        
        const testResponse = await axios.post(graphqlEndpoint, {
            query: testMutation,
            variables: {
                code: "test_code_123" // 这是一个测试code,预期会失败但能验证API结构
            }
        }, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        
        if (testResponse.data.errors) {
            console.log('⚠️  预期的错误(使用测试code):', testResponse.data.errors[0].message);
            console.log('✅ API结构正确,能够接收请求');
        } else {
            console.log('✅ API调用成功:', testResponse.data.data);
        }
        
    } catch (error) {
        console.error('❌ 测试失败:', error.response?.data || error.message);
    }
}
 
// 运行测试
testNewPhoneAPI().then(() => {
    console.log('\n🎉 测试完成');
}).catch(error => {
    console.error('💥 测试异常:', error);
});