Skip to content

Commit a291631

Browse files
committed
Add supported argument types section for custom operations
1 parent ab1f330 commit a291631

File tree

1 file changed

+36
-13
lines changed
  • src/pages/[platform]/build-a-backend/data/custom-business-logic

1 file changed

+36
-13
lines changed

src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,12 @@ const schema = a.schema({
6060
executionDuration: a.float()
6161
}),
6262

63-
Status: a.enum({
64-
values: ['ACCEPTED', 'REJECTED']
65-
})
66-
6763
// 2. Define your query with the return type and, optionally, arguments
6864
echo: a
6965
.query()
70-
// arguments that this query accepts - scalar, custom types, reference to custom types & enums
66+
// arguments that this query accepts
7167
.arguments({
72-
// scalar field
73-
content: a.string(),
74-
// inline custom type
75-
config: a.customType({
76-
filter: a.string(),
77-
// reference to enum
78-
status: a.ref('Status')
79-
}),
68+
content: a.string()
8069
})
8170
// return type of the query
8271
.returns(a.ref('EchoResponse'))
@@ -521,6 +510,40 @@ safePrint(echoResponse.echo.content);
521510
```
522511

523512
</InlineFilter>
513+
## Supported Argument Types in Custom Operations
514+
515+
Custom operations can accept different types of arguments. Understanding these options helps define flexible and well-structured APIs.
516+
517+
### Defining Arguments in Custom Operations
518+
519+
When defining a custom operation, you can specify arguments using different types:
520+
521+
- **Scalar Fields**: Basic types such as `string`, `integer`, `float`, etc.
522+
- **Custom Types**: Define inline `customType`.
523+
- **Reference Types**: Use `a.ref()` to reference enums and custom types.
524+
525+
```ts title="amplify/data/resource.ts"
526+
const schema = a.schema({
527+
Status: a.enum({
528+
values: ['ACCEPTED', 'REJECTED']
529+
}),
530+
531+
echo: a
532+
.query()
533+
.arguments({
534+
// scalar field
535+
content: a.string(),
536+
// inline custom type
537+
config: a.customType({
538+
filter: a.string(),
539+
// reference to enum
540+
status: a.ref('Status')
541+
}),
542+
})
543+
.returns(a.string())
544+
.authorization(allow => [allow.authenticated()])
545+
});
546+
```
524547

525548
## Async function handlers
526549

0 commit comments

Comments
 (0)