Skip to content
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

[CU-86934hpbh] Author avatar is always null in Graphql Queries #225

Open
jainsuneet opened this issue Aug 6, 2023 · 3 comments
Open

[CU-86934hpbh] Author avatar is always null in Graphql Queries #225

jainsuneet opened this issue Aug 6, 2023 · 3 comments
Assignees
Labels
bug Something isn't working graphql GraphQL API issue in progress v4 Strapi v4

Comments

@jainsuneet
Copy link

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

@cyp3rius cyp3rius added bug Something isn't working v4 Strapi v4 graphql GraphQL API issue in progress labels Nov 3, 2023
@cyp3rius cyp3rius changed the title Author avatar is always null in Graphql Queries [CU-86934hpbh] Author avatar is always null in Graphql Queries Nov 15, 2023
@111Tashmo
Copy link

REST is fine, you can try

@jusiho
Copy link

jusiho commented Jun 20, 2024

but Graphql is better, how to do it?

@jusiho
Copy link

jusiho commented Jun 20, 2024

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);
              },
            });
          },
        }),
      ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graphql GraphQL API issue in progress v4 Strapi v4
Projects
None yet
Development

No branches or pull requests

5 participants