[Python] GraphQL mutation via Ariadne in FastAPI returns 400 error despite correct schema —...

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    I’m building a FastAPI microservice that exposes a GraphQL endpoint using Ariadne. It implements a TextCleaner node in a modular workflow engine.

    type Mutation {
    cleanText(context: ExecutionContextInput, state: CleanTextInput): CleanTextOutput
    }

    input ExecutionContextInput {
    executionId: String!
    }

    input CleanTextInput {
    text: String!
    }

    type CleanTextOutput {
    response: CleanTextResponse
    }

    type CleanTextResponse {
    text: String
    }



    When I try to call the mutation from Python using httpx:

    import httpx

    query = """
    mutation CleanText($context: ExecutionContextInput!, $state: CleanTextInput!) {
    cleanText(context: $context, state: $state) {
    response {
    text
    }
    }
    }
    """

    variables = {
    "context": { "executionId": "123" },
    "state": { "text": "Hello World!!" }
    }

    resp = httpx.post(
    "http://localhost:8000/graphql",
    json={"query": query, "variables": variables}
    )

    print(resp.status_code)
    print(resp.text)



    I keep getting:

    400 Bad Request
    {"errors": [{"message": "Invalid GraphQL request"}]}


    Verified schema with graphql-core introspection

    Mutation works in GraphQL Playground

    Using the same JSON body in curl works fine

    httpx GET requests work for queries but not POST for this mutation

    What’s the correct way to structure and send the GraphQL mutation from Python so Ariadne doesn’t return a 400 error?

    Continue reading...

Compartilhe esta Página