Nullable field does not work.
I have a field:
client_users = List(ClientUserType, ids=List(Int)) that accepts null as an argument to the param ids because clearly I did not say NonNull(List(Int)), but when I do a query in GraphiQL using null as argument like so:
query {
clientUsers(ids: null) {
id
}
}
I get the following error:
"message": "Syntax Error GraphQL request (2:20) Unexpected Name \"null\"\n\n1: query {\n2: clientUsers(ids: null) {\n ^\n3: id\n",
Clearly, something is not right. Is my understanding incorrect?
Try this instead? I think it will be null already.
query {
clientUsers {
id
}
}
I think GraphQL does not allow for null fields.
If that's the case, then there's a bug I've encountered. Given this query:
{
player {
games {
...
}
}
}
This schema works without error:
class Game(ObjectType):
...
class Player(ObjectType):
games = List(Game, recent_count=Int(default_value=0))
But this does not (the default is None instead of 0):
class Game(ObjectType):
...
class Player(ObjectType):
games = List(Game, recent_count=Int(default_value=None))
def resolve_games(root, info, recent_count):
...
Even though both of the schemas provide a default value, only the latter actually uses the default value; the latter fails with resolve_games() missing 1 required positional argument: 'recent_count'
HOWEVER:
When I change resolve_games to this:
def resolve_games(root, info, recent_count=None): # Added a default to the function
The query works without arguments. It should be made clear that GraphQL does support queries without arguments, or with optional arguments, but implementing that in the schema requires modifying the resolver function, not the class field.
This is hinted at because the error message, "