Skip to content

Commit 634bf2f

Browse files
Dani PenevDani Penev
authored andcommitted
make necessary changes
1 parent bbcf3fd commit 634bf2f

File tree

4 files changed

+5691
-5772
lines changed

4 files changed

+5691
-5772
lines changed

packages/openapi-to-graphql/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"jsonpointer": "^5.0.0",
9595
"oas-validator": "^5.0.2",
9696
"pluralize": "^8.0.0",
97+
"query-string": "^7.1.1",
9798
"swagger2openapi": "^7.0.2",
9899
"tslib": "^2.3.0",
99100
"url-join": "4.0.1",

packages/openapi-to-graphql/src/resolver_builder.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import formurlencoded from 'form-urlencoded'
2828
import { PubSub } from 'graphql-subscriptions'
2929
import urljoin from 'url-join'
3030
import FormData from 'form-data'
31+
import * as querystring from 'query-string';
3132

3233
const pubsub = new PubSub()
3334

@@ -722,7 +723,11 @@ export function getResolver<TSource, TContext, TArgs>({
722723

723724
resolveData.usedRequestOptions = options
724725
resolveData.usedStatusCode = operation.statusCode
725-
setSearchParamsFromObj(url, qs, [])
726+
if (requestOptions.useQueryString) {
727+
setSearchFromObj(url, qs)
728+
} else {
729+
setSearchParamsFromObj(url, qs, [])
730+
}
726731
resolveData.url = url.toString().replace(url.search, '')
727732

728733
// Make the call
@@ -1411,6 +1416,12 @@ export function extractRequestDataFromArgs<TSource, TContext, TArgs>(
14111416
return { path, qs, headers }
14121417
}
14131418

1419+
// This can be extended in the future to take an optional object which controls
1420+
// the stringify options as listed here https://github.com/sindresorhus/query-string#stringifyobject-options
1421+
const setSearchFromObj = (url: URL, obj: any) => {
1422+
url.search = querystring.stringify(obj);
1423+
}
1424+
14141425
const setSearchParamsFromObj = (url: URL, obj: any, path: string[]) => {
14151426
for (const key in obj) {
14161427
const val = obj[key]

packages/openapi-to-graphql/src/types/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export type RequestOptions<TSource, TContext, TArgs> = Omit<
7575
> & {
7676
headers?: HeadersInit | RequestHeadersFunction<TSource, TContext, TArgs>
7777
qs?: Record<string, string>
78+
useQueryString?: boolean
7879
}
7980

8081
/**

0 commit comments

Comments
 (0)