The error disappeared after setting streaming to True inside the graph.as_query_engine() function. I had previously just put it inside custom_query_engines which I thought would have been sufficient as custom_query_engines is an argument in graph.as_query_engine().