1

このミューテーションは、http://localhost:8080/graphiqlの GraphIQL で正しく機能しています。

クエリ

mutation($fromID: String!, $toID: String!, $msgText: String!){
  createIM(fromID: $fromID, toID: $toID, msgText: $msgText){
    fromID
    toID
    msgText
  }
}

...そしてクエリ変数

{
  "fromID": "1",
  "toID": "2",
  "msgText": "Test from GraphIQL #3. It's working!!!"
}

これをコードに実装する必要があります。

クライアントコード

sendInstantMsg(){
    const {textToSend} = this.refs;
    const {toID} = this.props;

    const fromID = Meteor.userId();
    const msgText = trimInput(textToSend.getValue());

    client.query({
        query: gql`
            query mutation($fromID: String!, $toID: String!, $msgText: String!){
                createIM(fromID: $fromID, toID: $toID, msgText: $msgText){
                    fromID
                    toID
                    msgText
                }
            }
        `,
        variables: {
            fromID: fromID,
            toID: toID,
            msgText: msgText
        },
        forceFetch: false,
    }).then(({ data }) => {
        console.log('got data', data);
    }).catch((error) => {
        console.log('there was an error sending the query', error);
    });
}

クエリ変数 (fromID、toID、および msgText) は期待どおりに関数に入りますが、Apollo はエラーをスローします。

message: "Network error: Unexpected token < in JSON at position 0"

私は何が欠けていますか?

4

1 に答える 1