Skip to content

Commit 1cb696e

Browse files
committed
Documentation improvements
Signed-off-by: Alan Cha <[email protected]>
1 parent 66b2c8b commit 1cb696e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type AuthOptions = {
5555

5656
type GetResolverParams<TSource, TContext, TArgs> = {
5757
operation: Operation
58-
argsFromLink?: { [key: string]: string }
58+
argsFromLink?: { [key: string]: any }
5959
payloadName?: string
6060
responseName?: string
6161
data: PreprocessingData<TSource, TContext, TArgs>
@@ -65,6 +65,14 @@ type GetResolverParams<TSource, TContext, TArgs> = {
6565
fetch: typeof crossFetch
6666
}
6767

68+
type inferLinkArgumentsParam<TSource, TContext, TArgs> = {
69+
paramName: string
70+
value: any
71+
resolveData: Partial<ResolveData<TSource, TContext, TArgs>>
72+
source: TSource
73+
args: TArgs
74+
}
75+
6876
type GetSubscribeParams<TSource, TContext, TArgs> = {
6977
operation: Operation
7078
argsFromLink?: { [key: string]: string }
@@ -325,7 +333,7 @@ export function getPublishResolver<TSource, TContext, TArgs>({
325333
}
326334

327335
/**
328-
* Returns values for link arguments, also covers the cases for
336+
* Returns values for link arguments, also covers the cases for
329337
* if the link parameter contains constants that are appended to the link parameter
330338
*
331339
* e.g. instead of:
@@ -334,15 +342,23 @@ export function getPublishResolver<TSource, TContext, TArgs>({
334342
* it could be:
335343
* abc_{$response.body#/employerId}
336344
*/
337-
function inferLinkArguments (paramName, value, resolveData, source, args) {
345+
function inferLinkArguments<TSource, TContext, TArgs>({
346+
paramName,
347+
value,
348+
resolveData,
349+
source,
350+
args
351+
}: inferLinkArgumentsParam<TSource, TContext, TArgs>) {
338352
if (Object.prototype.toString.call(value) === '[object Object]') {
339353
return Object.entries(value).reduce((acc, [key, value]) => {
340-
acc[key] = inferLinkArguments(paramName, value, resolveData, source, args)
354+
acc[key] = inferLinkArguments({paramName, value, resolveData, source, args})
341355
return acc
342356
}, {})
343357
}
344358

345-
if (value.search(/{|}/) === -1) {
359+
if (typeof value !== 'string') {
360+
return value
361+
} else if (value.search(/{|}/) === -1) {
346362
return isRuntimeExpression(value)
347363
? resolveRuntimeExpression(paramName, value, resolveData, source, args)
348364
: value
@@ -476,7 +492,7 @@ export function getResolver<TSource, TContext, TArgs>({
476492

477493
let value = argsFromLink[paramName]
478494

479-
args[saneParamName] = inferLinkArguments(paramName, value, resolveData, source, args)
495+
args[saneParamName] = inferLinkArguments({paramName, value, resolveData, source, args})
480496
}
481497

482498
// Stored used parameters to future requests:

packages/openapi-to-graphql/test/example_api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ test('Non-nullable properties from nested allOf', () => {
24122412
})
24132413
})
24142414

2415-
test('it formats the request url appropriate when style and explode is set to true', async () => {
2415+
test('Format the query params appropriately when style and explode are set to true', async () => {
24162416
const LIMIT = 10
24172417
const OFFSET = 0
24182418

0 commit comments

Comments
 (0)