Unable to run mutation on join table created by amplify after v6 upgrade #13226
Labels
DataStore
Related to DataStore category
question
General question
to-be-reproduced
Used in order for Amplify to reproduce said issue
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
DataStore
Amplify Version
v6
Amplify Categories
No response
Backend
Amplify CLI
Environment information
Describe the bug
TL;DR: The
@manyToMany
relationship isn't utilizing the "userPool" auth mode in DataStore, causing failed requests to mutate the join table as "Unauthorized". Manually adding the join table resolves this issue but introduces additional negative side effects.As you see it is obvious it will fail as it is attempting to mutate using
apiKey
instead changing to useuserPool
. It does change the auth mode for creating the Project but go back to theapiKey
for the join tableI have a schema where the Project model is related to the Participant model via a
@manyToMany
relationship. In my application, when a user creates a project, the code first creates or finds an organizer and a participant, and then attempts to create a record in the join table.I initially tried creating the join table manually and applying authorization policies on my own, which worked. However, I encountered issues with AppSync where I could retrieve tags using the join table, but I couldn't query tags directly from the Project model, which is essential for certain functionalities within the app.
Expected behavior
I would have expected that the relationship will work as it used to do for version 5. I haven't spot updates that I needed to do on the schema to make this work according to https://docs.amplify.aws/javascript/build-a-backend/graphqlapi/data-modeling/#many-to-many-relationship and https://docs.amplify.aws/javascript/build-a-backend/more-features/datastore/relational-models/#many-to-many-relationships it seems it should work. Maybe I'm missing something?
Reproduction steps
@manyToMany
relationships that need special auth directives (like private for edit and public only reads)Code Snippet
As you see the Project has several "manyToMany" relationships with other models such
Participants
(see model below). Since I have upgraded to version 6 the relationship doesn't work properly anymore as I'm not able to mutate on the connection model due to auth errors.Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
If for some reason the only solution is to create manually the join tables, I don't have issue with it but I wonder if the expected result is for it to work like this:
Fig. 1 This is how it looks with
@manyToMany
. IdealFig. 2. This is how it looks when querying with the manual join tables in place
Fig. 3. Prove that the record on the join table exists
The text was updated successfully, but these errors were encountered: