hasura / hasura/graphql-engine
REST endpoints do not allow for optional parameters
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.0.10
### Environment
OSS
### What is the expected behaviour?
When creating a rest api endpoint like:
```
query MyQuery($id: uuid) {
companies(where: {id: {_eq: $id}}) {
id
}
}
```
I would like ?id=xxxx to be an optional search parameter (a fairly typical REST pattern). Not specifying an ID simply returns all companies, as I would expect. This worked correctly in Hasura v1 (or with `HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE=false`).
### Keywords
REST, optional parameters
### What is the current behaviour?
API endpoint returns `{"path":"$.selectionSet.companies.args.where.id._eq","error":"unexpected null value for type \"uuid\"","code":"validation-failed"}`
This is a problem for any REST API endpoint where you want a parameter to be optional or nullable.
### How to reproduce the issue?
Create above query (or something similar) as a REST API endpoint.
Go to the endpoint without specifying an id parameter
error returns
### Screenshots or Screencast

### Any possible solutions?
Either the Hasura REST API implementation needs work to be able to automatically exclude parameters that are null from the query, or make the default for *queries only* to ignore null parameters. I understand why the change was made to prevent mutations from doing dangerous `delete_users(where: {id: {_eq: null}})` type behaviour, but enforcing that restriction in a place more safe like queries breaks features like REST.
Contributor guide
Assessment
This issue has not been assessed yet.