-
Notifications
You must be signed in to change notification settings - Fork 825
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
DataStore sync fails for any type with multiple cognito @auth #6023
Comments
Hello @paddlefish When adding another auth mode to protect the subscription the owner argument should be optional in this scenario. Labeling this as a bug. |
Thanks @SwaySway let me know if i should revise teh description since I wasn't sure which way to phrase it. |
We are experiencing the same error when using multiple ownerfields on one model. On all subscriptions, all ownerfields are marked as mandatory... |
Are there any news when to expect a fix? |
reproducible with GraphQL Transformer V2 as well, used below schema type Test
@model
@auth(
rules: [
{ allow: private, operations: [create, read, update, delete] }
{
allow: private
provider: iam
operations: [create, read, update, delete]
}
{ allow: owner, ownerField: "owner" }
]
) {
id: ID!
} |
@lazpavel for v2, I think the last auth rule would need to explicitly list the allowed (This probably doesn't affect the output of the transformer re: subscriptions, but just in case) type Test
@model
@auth(
rules: [
{ allow: private, operations: [read] }
{
allow: private
provider: iam
operations: [create, read, update, delete]
}
{ allow: owner, ownerField: "owner", operations: [create, read, update, delete] }
]
) {
id: ID!
} |
@iartemiev, from V2 docs:
|
@lazpavel - you're right. I had forgotten that implicitly-defined operations have the same effect as all operations explicitly allow-listed |
This looks to be solved by this PR: #7765, please reopen if issue still persists |
Describe the bug
I'm not sure if this is a documentation bug, a cli bug, or an appsync bug. It probably could be handled in any of those ways, i'll leave it up to you.
If you declare a type in your schema.graphql and add two or more cognito auth types to it, then datastore will no longer be able to sync that type.
If this is the expected behavior then I suggest a warning be added to the documentation, e.g. here:
https://docs.amplify.aws/lib/datastore/setup-auth-rules/q/platform/js
where it describes various auth access patterns to warn that you must not mix these. For example this is a valid auth decoration for a type:
@auth(rules: [{ allow: owner }])
But the following declaration will result in a strange error ("errors":[{"message":"Validation error of type UnknownArgument: Unknown field argument owner @ 'onCreateXYZ'"}]}) when datastore tries to sync:
The documentation should caution against adding extra cognito auth types, and include the error message so that someone who encounters it will be lead to that warning when doing a search of the documentation.
Furthermore, I think the aws cli should detect when the schema auth params are invalid and issue a warning when you run
amplify push
. Because the sooner you can detect an error the better. As it is now, it's a runtime error when datastore tries to sync! It'd be much better to catch the error when running codegen or pushing.Finally, I'm not convinced this isn't an outright bug in how the appsync schema and resolvers get generated. Why does it build resolvers that do NOT take an owner argument when additional cognito auth are found? Maybe it should generate uniquely named resolvers for each auth? or maybe it should take an optional owner and use one auth if it's provided and the other if not? or maybe appsync codegen should fail if it sees multiple cognito auth params since at best it is only guessing about which one to make a subscription for.
Background:
The reason this results in an error is because the generated schema in appsync loses the
owner
attribute to the Subscription type. Here are before/after screenshots from the AppSync console viewing the schema:This shows the correct Subscription schema, where onCreateX, etc... have an
owner
attribute:This shows the invalid Subscription schema that gets created if additional cognito @auth attributes are included. Notice how onCreateX lacks the
owner
attribute:Amplify CLI Version
4.36.2
To Reproduce
Create an amplify project using datastore
add
{ allow: private, operations: [read] }
to the auth for a typeamplify push
run the app
Expected behavior
amplify push
failed with a message: You cannot use two kinds of cognito auth on a type with the path to the scema.graphql file and the line number this is on and the name of the type.Desktop (please complete the following information):
Additional context
This problem was clarified with the help of Ivan (ObjectiveCat) on a chat
The text was updated successfully, but these errors were encountered: