You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Error: "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https:/aws-amplify/amplify-js/issues"
As you see it is obvious it will fail as it is attempting to mutate using apiKey instead changing to use userPool. It does change the auth mode for creating the Project but go back to the apiKey for the join table
I 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.
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.
asyncsubmitProject(data: Pick<Project,|'description'|'image'|'launchPlan'|'location'|'mediaHTML'|'name'|'problem'|'solution'>): Promise<Project>{constcognitoUser=awaitgetCurrentUser()constuserId=cognitoUser.userIdconst[organiser,participant,project]=awaitPromise.all([this.findOrCreateOrganiser(userId),this.findOrCreateParticipant(userId),awaitDataStore.save(newProject({name: data.name,description: data.description,location: data.location,problem: data.problem,solution: data.solution,launchPlan: data.launchPlan,status: ProjectStatus.DRAFT,mediaHTML: data.mediaHTML,image: data.image,})),])// This are the ones that failawaitPromise.all([DataStore.save(newProjectOrganiserConnection({
project,
organiser,})),DataStore.save(newProjectParticipantConnection({
project,
participant,})),])letlistener: anyreturnawaitnewPromise((resolve,reject)=>{/** * Wait for datastore to sync with the server */listener=Hub.listen('datastore',(hubData)=>{const{ event, data }=hubData.payloadif(event==='outboxStatus'){if((dataas{isEmpty: boolean})?.isEmpty){resolve(project)listener()}}})/** * If the sync takes too long, reject the promise */setTimeout(async()=>{// this actually doesn't work as I want, since the conflict resolution says "NO". But this is not the real problem I want to solve.if(project)DataStore.delete(project)reject('Timeout')},10000)})}
Log output
// Put your logs below this line
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. Ideal
Fig. 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:
Just wanted to mention this is affecting all joining tables on my application. I assume I can't be the only one on this one. This seems pretty important, I'm unsure why there is no more people commenting about it.
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: