Using Vue 3 and Django backend using Graphql, I want to count button click shares.The problem is referring to PostId of Post model in django and graphene-django gives me error: "Variable '$postId' got invalid value {'isTrusted': True, '_vts': 1714830156331} ID cannot represent value
. How can I refer to PostId from the Django database?
In SocialMediaButtons.vue:
<code>const toggleShares = (postId) => {
navigator.clipboard.writeText(window.open (shareUrl, '_blank'));
copied.value = true;
console.log('Post Shared!');
store.toggleShares(postId);
};
</code>
<code>const toggleShares = (postId) => {
navigator.clipboard.writeText(window.open (shareUrl, '_blank'));
copied.value = true;
console.log('Post Shared!');
store.toggleShares(postId);
};
</code>
const toggleShares = (postId) => {
navigator.clipboard.writeText(window.open (shareUrl, '_blank'));
copied.value = true;
console.log('Post Shared!');
store.toggleShares(postId);
};
And using Pinia state management I have userInteraction:
<code>toggleShares(postId) {
const postStore = usePostStore();
const post = postStore.getPostBySlug(postId);
if (post) {
const url = window.location.origin + '/post/' + post.slug;
window.open(url, '_blank');
}
this.shares += 1; // Increment shares count
console.log('Share button clicked. Shares:', this.shares);
this.updateBackend(postId, 'shares', this.shares);
},
async updateBackend(postId, field, value) {
// Send GraphQL mutation to update backend
const response = await apolloClient.mutate({
mutation: gql`
mutation UpdatePostInteractions($postId: ID!, $likes: Int!, $dislikes: Int!, $shares:Int!) {
updatePostInteractions(postId: $postId, likes: $likes, dislikes: $dislikes, shares:$shares) {
post{
postId
likes
dislikes
shares}
}
}
`,
variables: {
postId,
likes: field === 'likes' ? value : this.likes,
dislikes: field === 'dislikes' ? value : this.dislikes,
shares: field === 'shares' ? value : this.shares,
},
});
</code>
<code>toggleShares(postId) {
const postStore = usePostStore();
const post = postStore.getPostBySlug(postId);
if (post) {
const url = window.location.origin + '/post/' + post.slug;
window.open(url, '_blank');
}
this.shares += 1; // Increment shares count
console.log('Share button clicked. Shares:', this.shares);
this.updateBackend(postId, 'shares', this.shares);
},
async updateBackend(postId, field, value) {
// Send GraphQL mutation to update backend
const response = await apolloClient.mutate({
mutation: gql`
mutation UpdatePostInteractions($postId: ID!, $likes: Int!, $dislikes: Int!, $shares:Int!) {
updatePostInteractions(postId: $postId, likes: $likes, dislikes: $dislikes, shares:$shares) {
post{
postId
likes
dislikes
shares}
}
}
`,
variables: {
postId,
likes: field === 'likes' ? value : this.likes,
dislikes: field === 'dislikes' ? value : this.dislikes,
shares: field === 'shares' ? value : this.shares,
},
});
</code>
toggleShares(postId) {
const postStore = usePostStore();
const post = postStore.getPostBySlug(postId);
if (post) {
const url = window.location.origin + '/post/' + post.slug;
window.open(url, '_blank');
}
this.shares += 1; // Increment shares count
console.log('Share button clicked. Shares:', this.shares);
this.updateBackend(postId, 'shares', this.shares);
},
async updateBackend(postId, field, value) {
// Send GraphQL mutation to update backend
const response = await apolloClient.mutate({
mutation: gql`
mutation UpdatePostInteractions($postId: ID!, $likes: Int!, $dislikes: Int!, $shares:Int!) {
updatePostInteractions(postId: $postId, likes: $likes, dislikes: $dislikes, shares:$shares) {
post{
postId
likes
dislikes
shares}
}
}
`,
variables: {
postId,
likes: field === 'likes' ? value : this.likes,
dislikes: field === 'dislikes' ? value : this.dislikes,
shares: field === 'shares' ? value : this.shares,
},
});