Skip to content

Commit 36afaf4

Browse files
committed
fix: Update CustomOpArguments type
1 parent d7682c8 commit 36afaf4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/data-schema/__tests__/CustomOperations.test-d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,51 @@ describe('custom operations return types', () => {
539539
type _T3 = Expect<Equal<ActualHandler, ExpectedFunctionHandler>>;
540540
});
541541
});
542+
543+
describe('when using custom types with refs in function arguments', () => {
544+
it('resolves nested types correctly in functionHandler', () => {
545+
const schema = a.schema({
546+
Location: a.customType({
547+
coordinates: a.integer(),
548+
}),
549+
myQuery: a
550+
.query()
551+
.arguments({
552+
wrapper: a.customType({
553+
location: a.ref('Location'),
554+
}),
555+
})
556+
.handler(a.handler.function('myFunc'))
557+
.returns(a.string()),
558+
});
559+
560+
type Schema = ClientSchema<typeof schema>;
561+
562+
type ActualArgs = Prettify<Schema['myQuery']['args']>;
563+
type ActualResult = Prettify<Schema['myQuery']['returnType']>;
564+
type ActualHandler = Schema['myQuery']['functionHandler'];
565+
566+
type ExpectedArgs = {
567+
wrapper?:
568+
| {
569+
location?:
570+
| {
571+
coordinates?: number | null | undefined;
572+
}
573+
| null
574+
| undefined;
575+
}
576+
| null
577+
| undefined;
578+
};
579+
type ExpectedResult = string | null;
580+
type ExpectedHandler = AppSyncResolverHandler<ActualArgs, ActualResult>;
581+
582+
type _T1 = Expect<Equal<ActualArgs, ExpectedArgs>>;
583+
type _T2 = Expect<Equal<ActualResult, ExpectedResult>>;
584+
type _T3 = Expect<Equal<ActualHandler, ExpectedHandler>>;
585+
});
586+
});
542587
});
543588

544589
describe('RDS custom operations - current DX', () => {

packages/data-schema/src/ClientSchema/Core/ClientCustomOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface ClientCustomOperation<
3838
* ```
3939
*/
4040
functionHandler: AppSyncResolverHandler<
41-
CustomOpArguments<Op>,
41+
CustomOpArguments<Op, RefBag>,
4242
// If the final handler is an async function, the Schema['fieldname']['functionhandler']
4343
// should have a return type of `void`. This only applies to `functionHandler` and not
4444
// `returnType` because `returnType` determines the type returned by the mutation / query

0 commit comments

Comments
 (0)