my name is Nico and I am new to development, nevertheless I will try my best to make this as streamlines as possible.
Important to know is that i use the same code for "likes", and "events", "bars", "groups". It still works for "likes" but the program stopped working since the update on 30th april for the other 3 cases. I will post the segments to "likes" and "events" below so one can see that there are no differences.
I followed this tutorial to get the baseline of my code. https://www.youtube.com/watch?v=_W3R2VwRyF4&t=6611s
- Project ID: 65a033873cf893718c5e
- Error 1: "PATCH https://cloud.appwrite.io/v1/databases/65a0475331c0192aa8ed/collections/65ab8d3ff190c144ff4f/documents/65ad6c02b5ec448e65e5 400 (Bad Request)"
followed by Error 2: "AppwriteException: Invalid relationship value. Must be either an array of documents or document IDs, NULL given."
- The error points to the following segments: "api.ts / querriesAndMutations.ts / eventStats.ts
Thanks in advance for your help. Me and my team are really struggeling to find the issue. Since it was once working and "likes" is still working it makes it even more strange...
HERE THE CODE:
**CODE FOR "EVENTS: ** API FILE export async function participantEvent(eventId: string, participantArray: string[]) { try { const updatedEvent = await databases.updateDocument( appwriteConfig.databaseId, appwriteConfig.eventCollectionId, eventId, { participant: participantArray, } );
if (!updatedEvent) throw Error;
return updatedEvent;
} catch (error) {
console.error(error);
}
}
QUERRIESANDMUTATION export const useParticipantEvent = () => { const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ eventId, participantArray }: { eventId: string; participantArray: string[]; }) =>
participantEvent(eventId, participantArray),
onSuccess: (data) => {
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET_EVENT_BY_ID, data?.$id],
});
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET_RECENT_EVENTS],
});
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET_EVENTS],
});
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET_CURRENT_USER],
});
},
});
};
EVENTSTATS FILE const handleParticipantEvent = ( e: React.MouseEvent<HTMLImageElement, MouseEvent> ) => { e.stopPropagation();
let participantArray = [...participants];
if (participantArray.includes(userId)) {
participantArray = participantArray.filter((Id) => Id !== userId);
} else {
participantArray.push(userId);
}
setParticipants(participantArray);
participantEvent({ eventId: event.$id, participantArray });
// Redirect to "groups" page
navigate('/groups');
};
CODE FOR "LIKES": API FILE export async function likePost(postId: string, likesArray: string[]) { try { const updatedPost = await databases.updateDocument( appwriteConfig.databaseId, appwriteConfig.postCollectionId, postId, { likes: likesArray, } );
if (!updatedPost) throw Error;
return updatedPost;
} catch (error) {
console.log(error);
}
}
QUERRIESANDMUTATION export const useLikePost = () => { const queryClient = useQueryClient(); return useMutation({ mutationFn: ({ postId, likesArray, }: { postId: string; likesArray: string[]; }) => likePost(postId, likesArray), onSuccess: (data) => { queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_POST_BY_ID, data?.$id], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_RECENT_POSTS], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_POSTS], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_CURRENT_USER], }); }, }); };
POSTSTATS FILE const handleLikePost = ( e: React.MouseEvent<HTMLImageElement, MouseEvent> ) => { e.stopPropagation();
let likesArray = [...likes];
if (likesArray.includes(userId)) {
likesArray = likesArray.filter((Id) => Id !== userId);
} else {
likesArray.push(userId);
}
setLikes(likesArray);
likePost({ postId: post.$id, likesArray });
};
AppwriteException: Invalid relationship value.
Recommended threads
- Custom API domain is unreachable
Earlier my custom api domain was working fine. Now it seems to be offline without a trace a few hours later. I didn't change anything, all the relevant DNS reco...
- "Invalid console fingerprint" when unpau...
I've tried logging out and logging back in, still can't figure out why this is happening.
- Inviting members while SMTP is disabled ...
Issue: https://github.com/appwrite/console/issues/3125 PR: https://github.com/appwrite/console/pull/3126