How to query media in UsersPermissionsMe in graphQL

Hi!

Im missing documentation on how to use the GraphQL extensionService. I have added an media field on the user called profile_image and I want to return it when calling me and on login etc in GraphQL.

I have text fields as well, which return fine. now Im stuck with the media field.
I have this in my index:

register({ strapi }) {
    const extensionService = strapi.service("plugin::graphql.extension");
    extensionService.use(({ nexus }) => ({
      types: [
        nexus.extendType({
          type: 'UsersPermissionsMe',
          definition(t) {
            // here define fields you need
            t.string('first_name');
            t.string('last_name');
            t.string('profile_image', {
              type: 'UploadFileEntityResponse',
              resolve: async (root, args) => {
                const userData = await strapi.db.query('plugin::users-permissions.user').findOne({
                  select: [],
                  where: { id: root.id },
                  populate: { profile_image: true },
                });
                const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
                console.dir(userData.profile_image)
                return toEntityResponse(userData.profile_image ?? null, {
                  args,
                  resourceUID: "plugin::uploads.uploads",
                })
              },
            });
          },
        }),
      ]
    }));
  },

I can now create this query, but the profile image data is always `null:

query fetchMe {
  me {
    id
    email
    first_name
    last_name
    profile_image {
      data {
        id
        attributes {
          url
        }
      }
    }
  }
}

It’s probably because of the wrong resourceUID in toEntityResponse but I have no clue on what to use there. Is there a list of options somewhere? Is this documented?

1 Like

all graphql documentation is in

if it is not in there you can maby make a issue on the strapi docs github to get somone to improve the docs on this

So I actually tried your code and it works for me. Exactly the code you shared without changing anything other than the name of the fields. Maybe you had a typo with your media name?

{
  "data": {
    "me": {
      "id": "2",
      "email": "pasd@asd.com",
      "firstName": "asd",
      "lastName": "wqe",
      "picture": {
        "data": {
          "id": "2",
          "attributes": {
            "url": "/uploads/Harry_1_e3a9ddd11c.jpg"
          }
        }
      }
    }
  }
}

may be u didn’t upload image!