graphql-python / flask-graphql

Adds GraphQL support to your Flask application.
MIT License
1.32k stars 140 forks source link

Throw more sensible error in empty batch query #28

Closed dewiniaid closed 7 years ago

dewiniaid commented 7 years ago

With a view constructed as:

view = GraphQLView.as_view('graphql_batch', schema=schema, batch=True)
app.add_url_rule('/graphql/batch`, view_func=view)

Simply navigating to the URI in a browser (and thus submitting no queries) results in an empty list of responses here, which causes ValueError: max() arg is an empty sequence


This PR raises a BadRequest error if there are no queries in a batch, which produces a more sensible error message than what currently happens.

Having not looked at the GraphQL specs in-depth, it's debatable as to whether this behavior or returning an empty list of results with status=200 is the more desirable option. However, an empty list of queries is almost certainly an error on the client side and raising error in that event makes that situation easier to troubleshoot. Either outcome is better than the current situation, however.

dewiniaid commented 7 years ago

Submitted against the wrong branch.

[Edit: Actually, looks like master restructured this entirely, so the error may not even exist.]