-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper way to update author info #210
Comments
Looks like this was somewhat answered here, but how can I add additional fields/extend calls for this plugin for GraphQL? |
If you base on Strapi Users simply add fields to them and populate proper ones in your query. For more detailed suggestion please provide idea you've got. |
I guess the larger question would be, what is the proper way to use |
About extensions you can read here but I guess you want to add more fields to User Collection to which we have got relation in the comment schema. After adding fields you should follow the "Populating" chapter in the Strapi Doc. |
@cyp3rius I understand how to add fields to users and how to populate. My confusion is around extending GraphQL for comments specifically. For example, this is what i'd expect to be able to do, something like below.
Is there an example on how to do this or does this need to be handled a special way? Sorry, it's very confusing and Strapi 4's docs kind of suck. |
Let me check that on weekend and back to you with some advice :) |
@cyp3rius Thanks! That'd be great. Even you just find a sample somewhere or an article. It's just tough cause Strapi's docs are all over the place with V3 and V4, GraphQL makes it tough, and then you add in the complexity of this plugin having specific calls and types, it's tough to know how to handle things properly. |
@cyp3rius Yes that's what i'm already doing. That's where the code is. It just doesn't work. I think part of it is the |
Please add the like feature, manage likes for each comment. I think adding the like feature will make your plugin more perfect |
@cyp3rius It looks like the |
Looking into that |
Hi @jnovak-SM2Dev, I dug a bit deeper. Comment entity connects either to Strapi user or displays details provided at comment creation. Both are displayed as Long story short you cannot read author as a strapi user or author as static values at comments level. Only one of them at the time. You query both from the same field. |
you just need to extend the response, create a field and resolve, in index.js const extensionService = strapi.plugin("graphql").service("extension");
extensionService.use(({ nexus }) => ({
types: [
nexus.extendType({
type: "CommentSingle",
definition(t) {
t.string("authorFull", {
type: "UsersPermissionsUserEntityResponse",
description: "Author full data",
resolve: async (parent, root, args) => {
const { toEntityResponse } = strapi.service(
"plugin::graphql.format"
).returnTypes;
console.log("parent", parent.author.id);
const user = await strapi.db
.query("plugin::users-permissions.user")
.findOne({
where: { id: parent.author.id },
populate: { profile_image: true },
});
console.log("user", user);
return toEntityResponse(user);
},
});
},
}),
], |
I'm a bit confused about how the author is handled. I have to pass in the author's email, avatar, etc. What happens if that info changes (ie the user updates their profile)? Do I need to get all comments by the user and update each instance?
The text was updated successfully, but these errors were encountered: