Empty GQL Variables causes 400 Bad Request

Yaak version: Version 2024.12.0 (20241116.233905)

OS: macOS 15.0

When sending a GraphQL request without variables, Yaak appears to send variables as null instead of an empty JSON object (`{}`), this results in an HTTP 400 status code.

The request succeeds when manually setting variables to an empty JSON object.

This behavior appears to be a regression from previous versions.

Steps to reproduce:

  1. Launch a Strawberry GQL Server:

from dataclasses import dataclass
from typing import Optional

import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter


@dataclass
class Animal:
    id: str
    name: str
    species: str
    age: int
    color: Optional[str] = None

ANIMALS = [
    Animal(id="1", name="Leo", species="Lion", age=5, color="Golden"),
    Animal(id="2", name="Raja", species="Tiger", age=3, color="Orange"),
    Animal(id="3", name="Gray", species="Wolf", age=2, color="Gray"),
    Animal(id="4", name="Hop", species="Rabbit", age=1, color="White")
]

@strawberry.type
class AnimalType:
    id: str
    name: str
    species: str
    age: int
    color: Optional[str] = None

def get_animal() -> AnimalType:
    animal = ANIMALS[0]
    return AnimalType(
        id=animal.id,
        name=animal.name,
        species=animal.species,
        age=animal.age,
        color=animal.color
    )

@strawberry.type
class Query:
    animal: AnimalType = strawberry.field(resolver=get_animal)

schema = strawberry.Schema(query=Query)

app = FastAPI()

graphql_app = GraphQLRouter(schema)

app.include_router(graphql_app, prefix="/graphql")

@app.get("/")
def read_root():
    return {"message": "Welcome to the Animal GraphQL API"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8005)
  1. Using Yaak, run the query, without filling the variables field

query {

animal {

id

name

species

age

color

}

}

Same behavior also occurred when querying https://countries.trevorblades.com/

Please authenticate to join the conversation.

Upvoters
Status

Released

Board

Feedback

Tags

Bug

Date

24 days ago

Author

gertzgal

Subscribe to post

Get notified by email when there are changes.