Skip to content

Remove calls to querystring.queryParamsStringify #446

@jeffdyke

Description

@jeffdyke

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @ory/hydra-client-fetch@v2.4.0-alpha.1 for the project I'm working on.

I've run into queryParamStringify is not a function repeatedly. Mainly after creating a production bundle using rollupjs with a mimicked directory structure. From the documentation it seems that queryParamStringify had been removed when querystring was removed, yet it is still called in runtime.ts

  get queryParamsStringify(): (params: HTTPQuery) => string {
        return this.configuration.queryParamsStringify || querystring;
    }

This has not really solved my problem yet, but i plan on this being my next attempt. If there is a canonical way to handle this, please let me know. Thanks!!

Here is the diff that solved my problem:

diff --git a/node_modules/@ory/hydra-client-fetch/src/runtime.ts b/node_modules/@ory/hydra-client-fetch/src/runtime.ts
index c7f8543..70929e5 100644
--- a/node_modules/@ory/hydra-client-fetch/src/runtime.ts
+++ b/node_modules/@ory/hydra-client-fetch/src/runtime.ts
@@ -48,7 +48,18 @@ export class Configuration {
     }
 
     get queryParamsStringify(): (params: HTTPQuery) => string {
-        return this.configuration.queryParamsStringify || querystring;
+      const searchParams = new URLSearchParams();
+      for (const key in params) {
+        if (Object.prototype.hasOwnProperty.call(params, key)) {
+          const value = params[key];
+          if (Array.isArray(value)) {
+            value.forEach(item => searchParams.append(key, item));
+          } else {
+            searchParams.append(key, value);
+          }
+        }
+      }
+      return searchParams.toString();
     }
 
     get username(): string | undefined {

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions