Skip to content

Commit 066f608

Browse files
Disable operations (#8275)
* disable operations * added entry in directory file * updated headings * updated * updated * fixed styling * correction * Update src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx Co-authored-by: josef <[email protected]> * Update index.mdx --------- Co-authored-by: josef <[email protected]>
1 parent e72668d commit 066f608

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export const directory = {
234234
},
235235
{
236236
path: 'src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index/index.mdx'
237+
},
238+
{
239+
path: 'src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx'
237240
}
238241
]
239242
},
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Disable Operations',
5+
description:
6+
'Disable Operations for your data model',
7+
platforms: [
8+
'android',
9+
'angular',
10+
'flutter',
11+
'javascript',
12+
'nextjs',
13+
'react',
14+
'react-native',
15+
'swift',
16+
'vue'
17+
]
18+
};
19+
20+
export const getStaticPaths = async () => {
21+
return getCustomStaticPath(meta.platforms);
22+
};
23+
24+
export function getStaticProps(context) {
25+
return {
26+
props: {
27+
platform: context.params.platform,
28+
meta
29+
}
30+
};
31+
}
32+
33+
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.
34+
35+
You can disable operations by adding the `disableOperations` method to your model definition:
36+
37+
```ts title="amplify/data/resource.ts"
38+
export const schema = a.schema({
39+
Customer: a
40+
.model({
41+
name: a.string(),
42+
phoneNumber: a.phone(),
43+
accountRepresentativeId: a.id().required(),
44+
})
45+
// highlight-next-line
46+
.disableOperations(["mutations", "subscriptions", "queries"])
47+
.authorization(allow => [allow.publicApiKey()]),
48+
});
49+
```
50+
51+
## Available Operation Types
52+
53+
The `disableOperations` method accepts an array of operation types that you want to disable:
54+
55+
### General Operation Categories
56+
57+
- `mutations`: Disables all mutation operations (create, update, delete)
58+
- `subscriptions`: Disables all real-time subscription operations (onCreate, onUpdate, onDelete)
59+
- `queries`: Disables all query operations (get, list)
60+
61+
### Specific Operations
62+
You can also disable more granular operations:
63+
Query Operations
64+
65+
- `get`: Disables the ability to fetch a single item by ID
66+
- `list`: Disables the ability to fetch multiple items
67+
68+
### Mutation Operations
69+
70+
- `create`: Disables the ability to create new items
71+
- `update`: Disables the ability to update existing items
72+
- `delete`: Disables the ability to delete items
73+
74+
### Subscription Operations
75+
76+
- `onCreate`: Disables real-time notifications when items are created
77+
- `onUpdate`: Disables real-time notifications when items are updated
78+
- `onDelete`: Disables real-time notifications when items are deleted
79+
80+
You can specify one or more operation types in the array to disable them:
81+
82+
```
83+
// Disable all mutations
84+
disableOperations: ["mutations"]
85+
86+
// Disable both subscriptions and queries
87+
disableOperations: ["subscriptions", "queries"]
88+
89+
// Disable specific operations
90+
disableOperations: ["create", "update", "list"]
91+
92+
// Disable specific subscription types
93+
disableOperations: ["onCreate", "onUpdate"]
94+
95+
// Mix general categories with specific operations
96+
disableOperations: ["queries", "create", "onDelete"]
97+
```

0 commit comments

Comments
 (0)