Giter Site home page Giter Site logo

Custom QueryString parser support about nestia HOT 9 OPEN

radixxko avatar radixxko commented on August 20, 2024 1
Custom QueryString parser support

from nestia.

Comments (9)

gitaugakwa avatar gitaugakwa commented on August 20, 2024 1

I'm also having the same issue.

Would be nice getting this addressed.

from nestia.

radixxko avatar radixxko commented on August 20, 2024 1

The main issue is that if somebody is already using its own querystring parser that works in nestjs, it stops working once nestia is installed since you are not using already parsed query value that Express/Fastify framework already handled.

We have spend few hours debugging why we are receiving completely different values with TypedQuery which should happen

from nestia.

samchon avatar samchon commented on August 20, 2024 1

I will study how native nestjs (platform of both express and fastify), and will determine how.

from nestia.

samchon avatar samchon commented on August 20, 2024

Your suggestion is a typical anti pattern that violating standard.

If you write a query string "person.address.id=2", it means obj["person.address.id"] = 2 in the query string spec.

Also, URL path has length limit in most browsers (about 1,023), and nested query is much dangerous than non-nested.

from nestia.

samchon avatar samchon commented on August 20, 2024

Instead, I recommend to use request body of POST/PATCH/PUT/DELETE methods.

The request body does not have any length and depth limit.

In my case, I prefer PATCH method when replacing GET method endpoint for the same reason with you.

https://github.com/samchon/bbs-backend/blob/5d398c6fc3aa26deec975b1870f457a71c0beed6/src/controllers/bbs/BbsArticlesController.ts#L13-L29

https://github.com/samchon/bbs-backend/blob/5d398c6fc3aa26deec975b1870f457a71c0beed6/src/api/structures/bbs/IBbsArticle.ts#L78-L118

from nestia.

samchon avatar samchon commented on August 20, 2024

In that case, it would better to use @Query() of original NestJS.

Also, in that case, how serialize the query string in the frontend application?

I need to update the SDK generator only for @Query() decorator case.

from nestia.

radixxko avatar radixxko commented on August 20, 2024

PHP and similar languages are supporting nested associative arrays natively when parsing querystring therefore quite a lot of people used nested objects - NodeJS ecosystem offloaded support to 3rd party libraries like qs.

Origins of our problem started few weeks ago when swagger client library was updated and it started generating querystring using JSON.stringify for arrays instead of comma separated values and backend started throwing exceptions for those queries - therefore we started using qs library for parsing querystring but it was ignored by nestia.

swagger-js v3.26.6

Screenshot 2024-05-01 at 08 00 55

Example of QS stringify

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'
qs.stringify({ a: { b: { c: 'd', e: 'f' } } });
// 'a[b][c]=d&a[b][e]=f'

If it helps i might have a look and create a merge request

from nestia.

samchon avatar samchon commented on August 20, 2024

Oh my god, looking at the format option, it seems terrible and why could not be standard.

Have you to use it? It seems not easy to support from SDK generator.

from nestia.

radixxko avatar radixxko commented on August 20, 2024

We have been using deep nested object serialization for past 20 years, since my backend origins were PHP.

Nonetheless swagger does offer deepObject serialization type and it is the only way to make it generic and universal enough so every backend can parse it

Screenshot 2024-05-01 at 08 10 57

There is an option native to expressJS for parsing nested objects

const app = express();
app.set('query parser', 'extended');

from nestia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.