Skip to content

Commit 995da93

Browse files
authored
disable operations
1 parent 10054a4 commit 995da93

File tree

1 file changed

+98
-0
lines changed
  • src/pages/[platform]/build-a-backend/data/data-modeling/disable-operations

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 enforcing access control patterns, optimizing performance, or implementing specialized API designs.
34+
35+
## Usage
36+
You can disable operations by adding the `disableOperations` method to your model definition:
37+
38+
```ts title="amplify/data/resource.ts"
39+
export const schema = a.schema({
40+
Customer: a
41+
.model({
42+
name: a.string(),
43+
phoneNumber: a.phone(),
44+
accountRepresentativeId: a.id().required(),
45+
})
46+
// highlight-next-line
47+
.disableOperations(["mutations","subcriptions","queries"])
48+
.authorization(allow => [allow.publicApiKey()]),
49+
});
50+
```
51+
52+
##Available Operation Types
53+
54+
The disableOperations method accepts an array of operation types that you want to disable:
55+
56+
###General Operation Categories
57+
58+
"mutations": Disables all mutation operations (create, update, delete)
59+
"subscriptions": Disables all real-time subscription operations (onCreate, onUpdate, onDelete)
60+
"queries": Disables all query operations (get, list)
61+
62+
###Specific Operations
63+
You can also disable more granular operations:
64+
Query Operations
65+
66+
"get": Disables the ability to fetch a single item by ID
67+
"list": Disables the ability to fetch multiple items
68+
69+
###Mutation Operations
70+
71+
"create": Disables the ability to create new items
72+
"update": Disables the ability to update existing items
73+
"delete": Disables the ability to delete items
74+
75+
###Subscription Operations
76+
77+
"onCreate": Disables real-time notifications when items are created
78+
"onUpdate": Disables real-time notifications when items are updated
79+
"onDelete": Disables real-time notifications when items are deleted
80+
81+
You can specify one or more operation types in the array to disable them:
82+
83+
```
84+
// Disable all mutations
85+
disableOperations: ["mutations"]
86+
87+
// Disable both subscriptions and queries
88+
disableOperations: ["subscriptions", "queries"]
89+
90+
// Disable specific operations
91+
disableOperations: ["create", "update", "list"]
92+
93+
// Disable specific subscription types
94+
disableOperations: ["onCreate", "onUpdate"]
95+
96+
// Mix general categories with specific operations
97+
disableOperations: ["queries", "create", "onDelete"]
98+
```

0 commit comments

Comments
 (0)