-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disable operations #8275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Disable operations #8275
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
995da93
disable operations
AnilMaktala 96ca47f
added entry in directory file
AnilMaktala 6b1ccde
updated headings
AnilMaktala d79bb9e
updated
AnilMaktala 4f1049c
updated
AnilMaktala 8f5bbc5
fixed styling
AnilMaktala b5688ee
correction
AnilMaktala c1b0771
Update src/pages/[platform]/build-a-backend/data/data-modeling/disabl…
AnilMaktala 0c3bcde
Update index.mdx
AnilMaktala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ages/[platform]/build-a-backend/data/data-modeling/disable-operations/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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 enforcing access control patterns, optimizing performance, or implementing specialized API designs. | ||
|
||
## Usage | ||
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"] | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.