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
- Github Student Plan showing as free plan
In my Github student plan it showing as basic plan instead of pro plan. Till few hours back it worked ok, but now showing errors and couldn't use any pro featur...
- 404 page not found
Hey I am trying to run a simple Svelte-kit project on appwrite self-hosted but the logs says: ```bash [13:56:26] [open-runtimes] Build packaging finished. [13:...
- Appwrite for Education
I am writing to report an issue with my account limits. I currently have the GitHub Student Developer Pack active, which should include 10 Appwrite Pro projects...