Amplify Flutter returns null when creating a manyToMany item

119 views Asked by At

I am making a chat application which has two tables like below:

type User @model @auth(rules: [{ allow: public, operations: [create, read], provider: iam }]) {
    id: ID!

    # relation
    rooms: [Room] @manyToMany(relationName: "UserRoom")
}

type Room @model @auth(rules: [{ allow: public, operations: [create, read], provider: iam }]) {
    id: ID!

    # relation
    users: [User] @manyToMany(relationName: "UserRoom")
}

and I wrote a code to 'enter a chat room' like below:

Future<UserRoom?> join(Room room, User user) async {
  try {
    UserRoom userroom = UserRoom(room: room, user: user);
    final request = ModelMutations.create(userroom);
    final response = await Amplify.API.mutate(request: request).response;
    return response.data;
  } catch (error) {
    safePrint("Failed on Creating UserRoom: $error");
  }

  return null;
}

however the above function returns null and creates nothing in my DynamoDB.

I've tried Amplify DataStore, but it does not work as I expected. (e.g. I need to create an item simultaneously regardless of network condition but it take longer than I expected.)

I am expecting the joined row is successfully created.

0

There are 0 answers