-
Notifications
You must be signed in to change notification settings - Fork 247
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
ModelMutation.delete not working for custom primary keys #1486
Comments
Thanks @tr-asimpson for reporting this issue. Observing the attached compiled GraphQL schema, we can see this input type: input DeleteBikeInput {
key: String!
}
type Mutation {
...
deleteBike(input: DeleteBikeInput!, condition: ModelBikeConditionInput): Bike @aws_api_key @aws_cognito_user_pools
...
} The CLI GraphQL transformer seems honor the custom PK settings Currently amplify-codegen and amplify-flutter don't fully support custom primary key. I will investigate this feature gap, and also test and verify the behavior GraphQL transformer v2. Where the schema would be: type Bike @model @auth(rules: [
{ allow: owner, operations: [create,delete]}
{ allow: private, operations: [read,update]}
{ allow: public, provider: apiKey, operations: [read,create,update,delete]}
]) {
id: ID!
key: String! @primaryKey
name: String
sharedUsers: String
battery: Float
autoUnlock: Boolean
armed: Boolean
muteAudioAlarm: Boolean
firmwareVersion: String
locationLat: Float
locationLon: Float
locationAltitude: Float
odometer: String
tripOdometer: String
owner: String
updatedAt: AWSDateTime
alarmTriggered: Boolean
} |
Hi @tr-asimpson I did some digging, unfortunately, that should be case that amplify-codegen and amplify-flutter (amplify-ios and amplify-flutter, the dependencies of amplify-fluter) have never fully supported custom primary key. With the current implementation of all platform libraries, it always assumes
It internally generates a GraphQL document that supplies the This feature gap will be addressed with #1426. The workaround you can take:
// following the type DeleteBikeInput
// input: { key: \$key } is expected to invoke deleteBike mutation
String graphQLDocument =
'''mutation deleteBike(\$key: ID!) {
deleteTodo(input: { key: \$key }) {
id
key
// ... other fields
}
}''';
var operation = Amplify.API.mutate(
request: GraphQLRequest<String>(document: graphQLDocument, variables: {
'key': 'the-key-you-want-to-delete'
})); |
Thankyou @HuiSF I have implemented the manual GraphQL request for now. Appreciate the help and all the work you and the team put into this amazing plugin! Thanks. |
Glad to hear @tr-asimpson |
Description
Hi,
I am attempting to delete an item using the GraphQL helpers as below. It seems this was previously working in 4.0.0
This is the response
This is the model
I have attached the compiled schema.
schema.zip
Categories
Steps to Reproduce
Have a model with a custom primary key and attempt to delete an item using
See the response
You can also try deleteById
This is the response which is the same as not using deleteById
Dependencies
Device
Samsung S21 Ultra
OS
Android 11
CLI Version
7.6.23
Additional Context
No response
The text was updated successfully, but these errors were encountered: