Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Aug 3, 2022
1 parent f812c8a commit bd0ee2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-walls-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/openapi': patch
---

Use `qs` to stringify query parameters because URLSearchParameters doesn't respect nested values
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ export function getResolver<TSource, TContext, TArgs>(
};
}

urlObject.search = qs.stringify(query);
const allQueryParams = {};

Object.assign(allQueryParams, query);

/**
* Determine possible payload
Expand Down Expand Up @@ -512,22 +514,12 @@ export function getResolver<TSource, TContext, TArgs>(
}
// Query string:
if (typeof data.options.qs === 'object') {
for (const query in data.options.qs) {
const val = data.options.qs[query];
if (val) {
urlObject.searchParams.set(query, val);
}
}
Object.assign(allQueryParams, data.options.qs);
}
}

if (typeof customQs === 'object') {
for (const query in customQs) {
const val = customQs[query];
if (val) {
urlObject.searchParams.set(query, val);
}
}
Object.assign(allQueryParams, customQs);
}

// Get authentication headers and query parameters
Expand All @@ -541,12 +533,8 @@ export function getResolver<TSource, TContext, TArgs>(
options.headers[headerName] = headerValue;
}
}
for (const query in authQs) {
const val = authQs[query];
if (val) {
urlObject.searchParams.set(query, val);
}
}

Object.assign(allQueryParams, authQs);

// Add authentication cookie if created
if (authCookie !== null) {
Expand All @@ -558,12 +546,7 @@ export function getResolver<TSource, TContext, TArgs>(
// Extract OAuth token from context (if available)
if (data.options.sendOAuthTokenInQuery) {
const oauthQueryObj = createOAuthQS(data, ctx, logger);
for (const query in oauthQueryObj) {
const val = oauthQueryObj[query];
if (val) {
urlObject.searchParams.set(query, val);
}
}
Object.assign(allQueryParams, oauthQueryObj);
} else {
const oauthHeader = createOAuthHeader(data, ctx, logger);
for (const headerName in oauthHeader) {
Expand All @@ -574,6 +557,8 @@ export function getResolver<TSource, TContext, TArgs>(
}
}

urlObject.search = qs.stringify(allQueryParams);

const urlWithoutQuery = urlObject.href.replace(urlObject.search, '');
resolveData.url = urlWithoutQuery;
resolveData.usedRequestOptions = Object.assign({}, options);
Expand Down

0 comments on commit bd0ee2f

Please sign in to comment.