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 Network タブには、予想されるリクエスト ペイロードが表示されます。
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 内」
どうすればこれを修正できますか?
アップデート
[ネットワーク] タブのスクリーン ショットを次に示します。