Liking the other user post

Hey, when I try doing it, I get

HTTP request to ‘http://localhost:7007/api/v0/commits’ failed with status ‘Internal Server Error’: {“error”:“Can not verify signature for commit bagcqcera…: invalid_jws: not a valid verificationMethod for issuer: did:key:z6Mkn6apNNb8yWrxnuUT…”}

How should make liking others posts (I guess mutating some of the fields of it, to be more accurate) available? Thanks

the scheme looks like this

type MyBasicProfile @loadModel(id: "kjzl6hvfrbw6c6lrz2473dhpljc01v97qvgge7zxdxhufagtrd4w4g7yf14x2xs") {
	id: ID!
}
type Likes {
	counter: Int!
	authors: [String] @string(minLength: 1, maxLength: 100) @list(maxLength: 1000)
}

type Comment {
	body: String! @string(minLength: 1, maxLength: 100)
	edited: DateTime
	created: DateTime!
	author: String! @string(minLength: 1, maxLength: 30)
	likes: Likes
}

type Post @createModel(accountRelation: LIST, description: "A simple Post") {
	body: String! @string(minLength: 1, maxLength: 1000)
	edited: DateTime
	created: DateTime!
	comments: [Comment] @list(maxLength: 100)
	likes: Likes
	profileID: StreamID! @documentReference(model: "MyBasicProfile")
	profile: MyBasicProfile! @relationDocument(property: "profileID")
}

Hey @0x69A. What authentication method are you using to authenticate the users?

Hello @0x69A

In re-reviewing your question I think I understand what’s happening here. Your goal is to have other users who were not the original author of each corresponding Post be able to like those posts. However, your Post model currently has a Likes array. Since each document can only have one controller, you won’t be able to have other users mutate this field (which is why I suspect you’re receiving those error messages). Instead, I’d recommend creating a separate model that defines the relationship between likes and corresponding posts.

This blog article actually does a great job of walking through how to define those relations and query against them.

1 Like

thanks… so I changed the models and separated them

now I want to be able to like the post, so here’s the model

type Post @loadModel(id: "kjzl6hvfrbw6c7oyieu386yamok6facluch99pkbenqe4cc8qw27a271uf1ghnf") {
	id: ID!
}

type Author {
	id: StreamID!
	userName: String! @string(minLength: 1, maxLength: 100)
}

type Like @createModel(accountRelation: SINGLE, description: "A post like") {
	author: Author
	postID: StreamID! @documentReference(model: "Post")
	post: Post! @relationDocument(property: "postID")
}

and when I do such mutation

const addLikeMutation = await composeClient.executeQuery(`
		mutation {
			createLike(input: {
				content: {
					author: {
						id: "${profile.id}"
						userName: "${profile.userName}"
					}
					postID: "${postID}"
				}})
			{
				document {
					author{
						id
						userName
					}
					postID
				}
			}
		}`);

the result is:

HTTP request to 'http://localhost:7007/api/v0/streams' failed with status 'Internal Server Error': {"error":"insert into kjzl6hvfrbw6c8sg08cw0kbdjlptrh1umt1m52uc8gqkalbsaj18jymx2utjmj3 (controller_did, created_at, custom_postID, first_anchored_at, last_anchored_at, stream_content, stream_id, tip, updated_at) values ('did:pkh:eip155:1:0x69afa407989952dac58fd00be19585b8be694ce4', 1691519408271, NULL, NULL, NULL, '{}', 'k2t6wzhkhabz0vgf2ahiava2ktoo97pwg6o6qju9t85syocixkgkwuvyk0zety', 'bafyreiavkzc37izplymwookanyj5l7o36uor3xvbfmdnyxiqw6j27vpf2y', 1691519408271) on conflict (stream_id) do update set stream_id = 'k2t6wzhkhabz0vgf2ahiava2ktoo97pwg6o6qju9t85syocixkgkwuvyk0zety',controller_did = 'did:pkh:eip155:1:0x69afa407989952dac58fd00be19585b8be694ce4',stream_content = '{}',tip = 'bafyreiavkzc37izplymwookanyj5l7o36uor3xvbfmdnyxiqw6j27vpf2y',updated_at = 1691519408271 - SQLITE_CONSTRAINT: NOT NULL constraint failed: kjzl6hvfrbw6c8sg08cw0kbdjlptrh1umt1m52uc8gqkalbsaj18jymx2utjmj3.custom_postID"}

Looks like the node is receiving null as the postID. Can you check what "${postID}" is returning?

no it’s not null
image

I’ve found the issue, it was needed to set the accountReference to LIST


I just thought about it wrong I guess, needing to have a logic of that a user can like a post only once, but the accountReference SINGLE I guess means that a user would only be able to like only one post

yeah, what you’re looking for is what we have described internally as the SET accountRelation - where the user can have multiple but only one per a given relation to another document. That is a feature request we are looking to build in the coming months.

CC @jpham - feature request for SET account relation

1 Like