hasura / hasura/graphql-engine

REST API Calls (GET) fail when "/" (forward slash) is part of the query (key) string

Open
#8,642 0 comments 0 reactions 0 assignees View on GitHub
k/bug t/gql-services
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.8.1

### Environment

Cloud

### What is the expected behaviour?

RESTified endpoints should support and correctly parse strings with "/" in it.

### Keywords

REST API, Query Param

### What is the current behaviour?

When a "/" is part of the query param in a REST (GET) API, it results in the following error messages:

**Error Message: The endpoint does not exist
Error Status code: 404**

### How to reproduce the issue?

1. Create a Hasura cloud project and add a database.
2. Create and track table with a String field type:

```
CREATE TABLE api_test
(
id int NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
locationKey TEXT,
locationName TEXT
);
```

3. INSERT Some test values into the table:

```
INSERT INTO api_test(locationKey, locationName) values ('us-west-1', 'US West #1');
INSERT INTO api_test(locationKey, locationName) values ('us-west-2', 'US West #2');
INSERT INTO api_test(locationKey, locationName) values ('us-east/3', 'US East #3'); -- locationKey has a slash

```

4. Create a [RESTified Graphql endpoint](https://hasura.io/docs/latest/graphql/core/api-reference/restified/) using this table with an argument for locationKey, for example using this query:

```
query MyQuery2 ($loc_id: String!) {
api_test(where: {locationKey: {_eq: $loc_id}}) {
id
locationKey
locationName
}
}
```

5. Configure the endpoint to accept GET requests and test it with loc_id **("us-east/3").**

![Screen Shot 2022-06-28 at 5 35 01 PM](https://user-images.githubusercontent.com/101733366/176326891-96772716-2b47-47e7-b115-e86b697d7b8f.png)

6. Run the Request. Observe the following error:

![Screen Shot 2022-06-28 at 5 40 05 PM](https://user-images.githubusercontent.com/101733366/176327125-7cc0d9c9-f5ec-4241-9d88-38f87bea9713.png)

### Any possible solutions?

The loc_id is parsed correctly if passed in the request body of a POST API call.

Contributor guide

Open the contributing guide

Research direction

Reproduce the RESTified GET endpoint described in the issue with the loc_id value "us-east/3", then compare it with the POST behavior, which reportedly parses the value correctly. Trace the REST API query-parameter and path parsing entry point; done means GET requests accept slash-containing query values instead of returning a 404 endpoint error.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, postgres
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.