我有一个在 localhost:3010/graphiql 中正常工作的 Apollo 查询:
询问
query getIMs($fromID: String!, $toID: String!){
instant_message(fromID:$fromID, toID: $toID){
fromID,
toID,
msgText
}
}
查询变量
{
"fromID": "1",
"toID": "2"
}
这是我通过调用 graphql() 运行查询的代码:
const GETIMS_QUERY = gql`
query getIMs($fromID: String!, $toID: String!){
instant_message(fromID:$fromID, toID: $toID){
fromID,
toID,
msgText
}
} `;
const CreateIMPageWithDataAndMutations = graphql(GETIMS_QUERY, {
options({ toID, userID }) {
return {
variables: { fromID: `${userID}`, toID: `${toID}`}
};
}
})(CreateIMPageWithMutations);
Chrome 网络选项卡显示了预期的请求负载:
operationName:"getIMs" query: "query getIMs($fromID: String!, $toID: String!) {↵ instant_message(fromID: $fromID, toID: $toID) {↵<br> fromID↵ toID↵ msgText↵ __typename↵ }↵}↵" 变量:{fromID: "DsmkoaYPeAumREsqC", toID: "572bddac4ecbbac0ffe37fdd"} fromID:"DsmkoaYPeAumREsqC" toID:"572bddac4ecbbac0ffe37fdd"
但是该data
对象返回了 ApolloError:
“网络错误:位置 0 的 JSON 中的意外令牌 <”
我该如何纠正?
更新
这是“网络”选项卡的屏幕截图: