Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

GraphQL mutation not possible. 405 Method not allowed.

default discord avatar
rene.k3last year

I'm trying to make a GraphQL Mutation (POST) request from a Next.js app.



My request:


mutation loginUser($email: String!, $password: String!) {
        loginUser(email: $email, password: $password) {
            user {
                email
            }
            exp
            token
        }
    }


I'm getting the error saying:

405 (Method Not Allowed)

The response headers:


[{"name":"allow","value":"GET, HEAD"},{"name":"cache-control","value":"no-store, must-revalidate"},{"name":"connection","value":"close"},{"name":"content-encoding","value":"gzip"},{"name":"content-type","value":"text/html; charset=utf-8"},{"name":"date","value":"Tue, 18 Jul 2023 08:11:59 GMT"},{"name":"etag","value":"\"lwb687lsku26b\""},{"name":"transfer-encoding","value":"chunked"},
{"name":"vary","value":"Accept-Encoding"},{"name":"x-powered-by","value":"Next.js"}]


The response headers show that only GET and HEAD are allowed methods. What's the way to go here so I can make

mutations

from the app? Do I have to allow POST in the config? Or do I have to make changes in the request?



Never mind. I got it. In case you have a similar problem, here is what was wrong in my case:



In the payload.config.ts file I had the csrf and cors urls as https not http. Localhosts are running under http 😉



I haven't set up the payload, so it took me a while to figure that out. 🤦‍♂️

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.