1

I consistently receive the response of 'operation not found' when I send a GraphQL query or mutation in Cypress. Taking tips from this post https://stackoverflow.com/a/68750026/16958500 I have the following in my it block (its working in Postman)

it('Retrieve and Store Session Token', () => {
        const query = `mutation {
            requestSMSSessionToken(phoneNumber: "1666555021"){
          
             cookieKey
              tokenValue
              expires
          
                }
            }`;
              
          cy.request({
            method: 'POST',
            url: '/', 
            headers: {
            'Content-Type': 'application/json',
            }, 
            body: { query },        
        
          }).then((res)=>{
            cy.log(JSON.stringify(res))
            expect(res.status).to.eq(200)
          });

    })

Here is my Postman Curl Code Snippet (that's working)

curl --location --request POST '/' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation {\r\n            requestSMSSessionToken(phoneNumber: \"1666555021\"){\r\n          \r\n             cookieKey\r\n              tokenValue\r\n              expires\r\n          \r\n                }\r\n            }","variables":{}}'

any tips to share to get this working?

mark quinteros
  • 129
  • 1
  • 7
  • I don't have much experience with GraphQL. At my company, we have `operationName`(which holds the name of the mutation) passed along with the `query` params in the `body`. Have you given that a try? – jjhelguero Feb 02 '22 at 20:31
  • I haven't tried that yet, but will give it a shot - thanks – mark quinteros Feb 03 '22 at 14:44

0 Answers0