I have a problem testing an application with Starlette's test client. I'm using Ariadne for GraphQL support and I have a resolver that takes two arguments: image and id. Image is an Ariadne Upload type, which in turn is an instance of Starlette's UploadFile. I'm trying to test that the upload resolver works using the client, but I can't get the image variables to map with the files I'm sending.
Here's the test I currently have
# Upload profile pic
update_query = """
mutation UploadAvatar($image: Upload!, $id: Int!) {
uploadUserImage(image: $image, id: $id) {
id
ok
}
}
"""
files_map = {"0": ["variables.image"]}
upload_data = {
"operationName": "UploadAvatar",
"query": update_query.replace('\n', '').strip(),
"variables": {
"image": None,
"id": 1
},
"map": files_map
}
file_cont = get_sample_file_contents()
files = {"file": (file_cont['name'], file_cont['content'], "image/png")}
headers = {
'content-type': 'application/json',
'access_token': access_token
}
upload_resp = client.post("/api/graphql", data=json.dumps(upload_data), headers=headers, files=files)
However, when I try to test this, I get the following error:
Variable '$image' of non-null type 'Upload!' must not be null.
Is there a way to use test client to correctly map the files to the resolver variables ?