【发布时间】:2022-07-04 15:38:36
【问题描述】:
我在本地主机中部署 enonic-xp cms。我想使用 graphql 获取数据。但它不起作用。我们在 localhost 中部署 enonic-xp,他们提供以下 URL 和断头台。
http://localhost:8080/site/hmdb/master/hmdb/api
当我在操场区域尝试下面的 graphql 代码时,它运行良好并且我可以看到结果。但是当我在 axios 中尝试时,它可能会产生未处理的承诺拒绝。我尝试在控制台日志中获得响应。
import React, {useState} from 'react';
import {View,Button} from 'react-native';
import axios from 'axios';
const endpoint = 'http://localhost:8080/site/hmdb/master/hmdb/api';
const GRAPHQL_QUERY = `
{
guillotine {
query(query: "type='testproject:movie'", first: 1) {
displayName
data : dataAsJson
}
}
}
`;
const Home = () => {
const fetchData = async () => {
await axios({
url: endpoint,
method: 'POST',
data: {
query: GRAPHQL_QUERY,
},
headers:{
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
}
}).then(response => console.log(response));
console.log(data);
};
return (
<View>
<Button title="get Data" onPress={fetchData} />
</View>
)}
export default Home;
错误
Possible Unhandled Promise Rejection (id: 1):
Error: Network Error
createError@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:111045:26
handleError@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:110831:69
dispatchEvent@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:31287:31
setReadyState@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:30402:33
__didCompleteResponse@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:30208:29
emit@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:2090:42
__callFunction@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:3056:36
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:2780:31
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:3007:15
callFunctionReturnFlushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.graphql&modulesOnly=false&runModule=true:2779:21
callFunctionReturnFlushedQueue@[native code]
【问题讨论】:
标签: react-native axios graphql content-management-system