strapi-plugin-comments
strapi-plugin-comments copied to clipboard
[CU-86934hpbh] Author avatar is always null in Graphql Queries
Author avatar is always null in Graphql Queries. It only works with the API call after passing the populate /flat?populate[author][populate][0]=avatar
REST is fine, you can try
but Graphql is better, how to do it?
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);
},
});
},
}),
],