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);
|
});
|