0

I am getting the following error from an axios thunk:

ExceptionsManager.js:82 messed up in createMeeting:  Error: Request failed with status code 400
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.handleLoad (xhr.js:59)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:572)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
    at XMLHttpRequest.js:507
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:366)
    at MessageQueue.js:106

The problem is with my axios request and not with my graphql schema, because I am able to complete this mutation with (my ngrok url)/graphiql and also localhost/graphql. Is my query too long for axios or something? I've consoled logged all the information that I am inputting and it is all in the correct format, but again, the information is not even making it to my server. Also, the data.data.newMeeting looks weird, but that part is actually correct. Here is my thunk:

export const createMeeting = (chatId, userId, invitation) => {
  return async dispatch => {
    try {
      const dateString = invitation.date.toDateString()
     let {data} = await axios({
            url: `${url}/graphql`,
            method: 'POST',
            data: {
              query: `mutation{
                newMeeting(chatId:${chatId}, 
                           userId:${userId}, 
                            latitude:${invitation.coords[0]},
                           longitude:${invitation.coords[1]},
                           name:"${invitation.name}",
                           rating:${invitation.rating},
                            address:"${invitation.address}",
                            date:"${dateString}"){
                               location
                                 name
                                rating
                                date
                               senderId
                               chatId
                }
             }`
            }
          })
      dispatch(setCurrentMeeting(data.data.newMeeting))
      clearInvitation()
    } catch (error) {
      console.error('messed up in createMeeting: ', error)
    }
  }
}
Eric Grossman
  • 219
  • 1
  • 4
  • 9
  • 1
    400 means your query is malformed or otherwise invalid. You can review the actual response from the server (`error.response.data`) to see what went wrong. If I had to guess, I'd say it's probably one of the values you're injecting. You shouldn't use string interpolation for dynamic values. Use variables instead, which ensures the values will be parsed correctly. – Daniel Rearden Dec 02 '19 at 05:53
  • thank you, you were correct! – Eric Grossman Dec 16 '19 at 14:36

0 Answers0