amplify-js
amplify-js copied to clipboard
DataStore query on many-to-many join table, using @manyToMany, not working, source tables are using owner auth. GraphQL create join table object, not working, due to missing owner field in Input model.
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
DataStore
Amplify Categories
api
Environment information
# Put output below this line
Describe the bug
Using GraphQL transformer V2.
Following the examples on many-to-many queries from:
Amplify Docs - DataSore - Many-to-many
With a graphql.schema like this:
type User @model @auth(rules: [{allow: owner, operations: [read]}]) {
id: ID!
name: String @index(name: "byName", queryField: "userByName")
cars: [Car] @manyToMany(relationName: "UserCar")
owner: String!
}
type Car @model @auth(rules: [{allow: owner, operations: [read]}]) {
id: ID!
name: String @index(name: "byName", queryField: "carByName")
users: [User] @manyToMany(relationName: "UserCar"),
owner: String
}
Query on UserCar
like this (notice no filter):
const result = await DataStore.query(UserCar);
Gives an empty array as result.
Query results on User or Car deliver the right objects. If I look in Amplify Studio, I see the many-to-many relationships, when I load a User or Car.
The corresponding join table object was inserted using GraphQL in a Lambda function, but it was not possible to provide the owner field for the join object, due to missing definition in the AppSync CreateUserCarInput
, although the type in AppSync for UserCar
contains the owner field. Just for a test I populated the owner field using DynamoDB console, but without any success. The local storage on the browser client for the UserCar
is always empty.
Please advice on how to proceed from here, because the only thing I can think about now, is to not use @manyToMany at all, because it seems to be not working as it should, even using GraphQL instead of DataStore, due to the fact, that the CreateUserCarInput
is missing the owner field, which is present in the type definition of UserCar
in AppSync.
If you link a Car
to a User
in Amplify Studio, the owner field is obviously also missing the DynamoDB data.
So this lets me think, that owner auth is not supported on many-to-many relationships.
Please confirm, so I can start removing DataStore immediately to start making some progress on my project.
Expected behavior
To be able to fetch join table object with owner auth.
Reproduction steps
See the description:
-
Create the model as shown in the description.
-
Create test data in Amplify Studio.
-
Try to fetch join table object using DataStore in the client.
-
Try to create a join table object with GraphQL, with and without owner field set.
Code Snippet
// Put your code below this line.
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
No response