Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
FastAPI router add route for GraphQL()

I got problems, when FastAPI route use call graphQL app, found error as below.

RuntimeError: Unexpected ASGI message 'http.response.start' sent, after response already completed.

I know I can app.mount(graphql_app) or app.add_route, but our company want this style.

@router.post('/')
def graph_ql():
  pass

here is my code.

  • create_graphql_app
from starlette_graphene3 import GraphQLApp
import graphene

def create_graphql_app(
        query: graphene.types.ObjectType = None,
        mutation=None,
        subscription=None
) -> GraphQLApp:
    """

    Args:
        query: graph_ql query
        mutation: graph_ql update and insert
        subscription: graph_ql streaming data

    Returns:

    """
    schema = graphene.Schema(
        query=query,
        mutation=mutation,
        subscription=subscription
    )
    graphql_app = GraphQLApp(
        schema=schema,
        on_get=make_graphiql_handler()  # Graphiql IDE
    )

    return graphql_app
  • fastapi router
graphql_app = create_graphql_app(query=Query)
router = APIRouter()

@router.post('/')
async def graph_query(request: Request):
    return await graphql_app(
        scope=request.scope,
        receive=request.receive,
        send=request.send
    )
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!