Econify/graphql-rest-router

Encoded version of path variables should be used

joshua-econify opened this issue · 0 comments

Module currently uses decoded path variables via req params:

asExpressRoute() {
    return async (req: express.Request, res: express.Response) => {
      const { query, params, body } = req;
      
      const parsedQueryVariables = this.typecastVariables(query);
      const parsedPathVariables = this.typecastVariables(params);
...

https://github.com/Econify/graphql-rest-router/blob/master/Route.ts#L290

req.params implicitly decodes each part of the path into a corresponding path variable.

If one of the path variables is used as a slug, then that slug would need to be stored decoded in the database in order to be looked up. Storing a slug as a decoded path means the slug is no longer a valid part of a URL. If the slug is used for embedded URLs this means it will have to be encoded every time.

Since a slug is part of URL, believe it is a reasonable expectation of consumers of the library to store slugs in a valid encoded form.

To my knowledge, because const { params } = req; implicitly decodes each value in the object, it is currently impossible to look up an encoded slug.

Thoughts/ideas/gotchas?