From ab1f330f32b8f7017fbbf637546728d21cffd1cf Mon Sep 17 00:00:00 2001 From: Vaisshnavi Date: Tue, 18 Feb 2025 11:45:34 -0800 Subject: [PATCH 1/4] Update custom operations documentation with newly supported examples --- .../data/custom-business-logic/index.mdx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx index af509d70506..253f2249adf 100644 --- a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx @@ -60,12 +60,23 @@ const schema = a.schema({ executionDuration: a.float() }), + Status: a.enum({ + values: ['ACCEPTED', 'REJECTED'] + }) + // 2. Define your query with the return type and, optionally, arguments echo: a .query() - // arguments that this query accepts + // arguments that this query accepts - scalar, custom types, reference to custom types & enums .arguments({ - content: a.string() + // scalar field + content: a.string(), + // inline custom type + config: a.customType({ + filter: a.string(), + // reference to enum + status: a.ref('Status') + }), }) // return type of the query .returns(a.ref('EchoResponse')) From a291631125042d924ca6bcd53be17b6016a83819 Mon Sep 17 00:00:00 2001 From: Vaisshnavi Date: Thu, 20 Feb 2025 14:40:44 -0800 Subject: [PATCH 2/4] Add supported argument types section for custom operations --- .../data/custom-business-logic/index.mdx | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx index 253f2249adf..3ec421f0f78 100644 --- a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx @@ -60,23 +60,12 @@ const schema = a.schema({ executionDuration: a.float() }), - Status: a.enum({ - values: ['ACCEPTED', 'REJECTED'] - }) - // 2. Define your query with the return type and, optionally, arguments echo: a .query() - // arguments that this query accepts - scalar, custom types, reference to custom types & enums + // arguments that this query accepts .arguments({ - // scalar field - content: a.string(), - // inline custom type - config: a.customType({ - filter: a.string(), - // reference to enum - status: a.ref('Status') - }), + content: a.string() }) // return type of the query .returns(a.ref('EchoResponse')) @@ -521,6 +510,40 @@ safePrint(echoResponse.echo.content); ``` +## Supported Argument Types in Custom Operations + +Custom operations can accept different types of arguments. Understanding these options helps define flexible and well-structured APIs. + +### Defining Arguments in Custom Operations + +When defining a custom operation, you can specify arguments using different types: + +- **Scalar Fields**: Basic types such as `string`, `integer`, `float`, etc. +- **Custom Types**: Define inline `customType`. +- **Reference Types**: Use `a.ref()` to reference enums and custom types. + +```ts title="amplify/data/resource.ts" +const schema = a.schema({ + Status: a.enum({ + values: ['ACCEPTED', 'REJECTED'] + }), + + echo: a + .query() + .arguments({ + // scalar field + content: a.string(), + // inline custom type + config: a.customType({ + filter: a.string(), + // reference to enum + status: a.ref('Status') + }), + }) + .returns(a.string()) + .authorization(allow => [allow.authenticated()]) +}); +``` ## Async function handlers From 3fab5cd02ef9da519f75c7862522d3394ca4b6b1 Mon Sep 17 00:00:00 2001 From: Vaisshnavi Date: Fri, 21 Feb 2025 11:57:10 -0800 Subject: [PATCH 3/4] Update query name and remove periods --- .../build-a-backend/data/custom-business-logic/index.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx index 3ec421f0f78..a4f6702ecdf 100644 --- a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx @@ -518,9 +518,9 @@ Custom operations can accept different types of arguments. Understanding these o When defining a custom operation, you can specify arguments using different types: -- **Scalar Fields**: Basic types such as `string`, `integer`, `float`, etc. -- **Custom Types**: Define inline `customType`. -- **Reference Types**: Use `a.ref()` to reference enums and custom types. +- **Scalar Fields**: Basic types such as `string`, `integer`, `float`, etc +- **Custom Types**: Define inline `customType` +- **Reference Types**: Use `a.ref()` to reference enums and custom types ```ts title="amplify/data/resource.ts" const schema = a.schema({ @@ -528,7 +528,7 @@ const schema = a.schema({ values: ['ACCEPTED', 'REJECTED'] }), - echo: a + getPost: a .query() .arguments({ // scalar field From c0c716943311b1799dbdefa8bb724af970252d71 Mon Sep 17 00:00:00 2001 From: Vaisshnavi Date: Tue, 25 Feb 2025 09:21:53 -0800 Subject: [PATCH 4/4] update enum syntax --- .../build-a-backend/data/custom-business-logic/index.mdx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx index a4f6702ecdf..9930698f8a9 100644 --- a/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/custom-business-logic/index.mdx @@ -524,10 +524,8 @@ When defining a custom operation, you can specify arguments using different type ```ts title="amplify/data/resource.ts" const schema = a.schema({ - Status: a.enum({ - values: ['ACCEPTED', 'REJECTED'] - }), - + Status: a.enum(['ACCEPTED', 'REJECTED']), + getPost: a .query() .arguments({