diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index 4437768235f..937df52c6dd 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -234,6 +234,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx' } ] }, diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx new file mode 100644 index 00000000000..de81572c91e --- /dev/null +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx @@ -0,0 +1,97 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Disable Operations', + description: + 'Disable Operations for your data model', + platforms: [ + 'android', + 'angular', + 'flutter', + 'javascript', + 'nextjs', + 'react', + 'react-native', + 'swift', + 'vue' + ] +}; + +export const getStaticPaths = async () => { + return getCustomStaticPath(meta.platforms); +}; + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +The `disableOperations` method allows you to selectively disable specific GraphQL operations for a model in your Amplify application. This can be useful for implementing specialized API designs and reduce the number of resources being deployed. + +You can disable operations by adding the `disableOperations` method to your model definition: + +```ts title="amplify/data/resource.ts" +export const schema = a.schema({ + Customer: a + .model({ + name: a.string(), + phoneNumber: a.phone(), + accountRepresentativeId: a.id().required(), + }) + // highlight-next-line + .disableOperations(["mutations", "subscriptions", "queries"]) + .authorization(allow => [allow.publicApiKey()]), +}); +``` + +## Available Operation Types + +The `disableOperations` method accepts an array of operation types that you want to disable: + +### General Operation Categories + +- `mutations`: Disables all mutation operations (create, update, delete) +- `subscriptions`: Disables all real-time subscription operations (onCreate, onUpdate, onDelete) +- `queries`: Disables all query operations (get, list) + +### Specific Operations +You can also disable more granular operations: +Query Operations + +- `get`: Disables the ability to fetch a single item by ID +- `list`: Disables the ability to fetch multiple items + +### Mutation Operations + +- `create`: Disables the ability to create new items +- `update`: Disables the ability to update existing items +- `delete`: Disables the ability to delete items + +### Subscription Operations + +- `onCreate`: Disables real-time notifications when items are created +- `onUpdate`: Disables real-time notifications when items are updated +- `onDelete`: Disables real-time notifications when items are deleted + +You can specify one or more operation types in the array to disable them: + +``` +// Disable all mutations +disableOperations: ["mutations"] + +// Disable both subscriptions and queries +disableOperations: ["subscriptions", "queries"] + +// Disable specific operations +disableOperations: ["create", "update", "list"] + +// Disable specific subscription types +disableOperations: ["onCreate", "onUpdate"] + +// Mix general categories with specific operations +disableOperations: ["queries", "create", "onDelete"] +```