Skip to content

Support nested query or get raw query or both... #1255

@prpanto

Description

@prpanto

Describe the feature

I have a nested query like filter[color]=red&filter[size]=large&user[product][id]=385&sort=-createdAt&include=author,comments&active=true. I want to get the raw query to transform the query into object with qs lib or I would like to see this on the getQuery.

An example how I use qs lib:

const query = "?filter[color]=red&filter[size]=large&user[product][id]=385&sort=-createdAt&include=author,comments&active=true";
      
      const queryObject = qs.parse(query, {
        ignoreQueryPrefix: true,
        decoder: (str: string, defaultDecoder: qs.defaultDecoder, charset: string, type: "key" | "value") => {    
          if (type === "value" && !!Number(str)) {
            return Number(str);
          }

          if (type === "value" && str === "true") {
            return true;
          }
          
          if (type === "value" && str === "false") {
            return false;
          }

          if (type === "value" && str.includes(",")) {
            return str.split(",").map((s: string) => s.trim());
          }

          return defaultDecoder(str);
        }
      });

Edit: One way to get the raw query is: const rawQuery = getRequestURL(event).search;
If I had the getRawQuery it will be better...

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions