Amplify DataStore Validation error of type FieldUndefined

Viewed 135

I have problem with DataStore.save() . I want to create chat room, but I get error

DataStore - subscriptionError, Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field 'chatroom' in type 'ChatRoomUser' is undefined @ 'onUpdateChatRoomUser/chatroom'"}]}

I'm using react-native and Expo

My function:

const onPress = async () => {
      //Create a chat room
      const newChatRoom = await DataStore.save(new ChatRoom({newMessages: 0}))
      //Connect auth user with the chat room
      const authUser = await Auth.currentAuthenticatedUser()
      const dbUser = await DataStore.query(User, authUser.attributes.sub)
      await DataStore.save(new ChatRoomUser({
        user: dbUser,
        chatroom: newChatRoom
      }))

      //Connect clicked user with the chat room
      await DataStore.save(new ChatRoomUser({
        user,
        chatroom: newChatRoom
      }))

      console.log(newChatRoom)

      navigation.navigate('ChatRoom' as never, {id: newChatRoom.id} as never)
    }

0 Answers
Related