wp-graphql / wp-graphql

:rocket: GraphQL API for WordPress

Home Page:https://www.wpgraphql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avatar URLs are included in responses when Show Avatars setting is disabled

mindctrl opened this issue · comments

Description

When avatar display is disabled in WordPress under Settings > Discussion, WPGraphQL still provides the avatar URL in responses at viewer.avatar.url.

For comparison, the WP REST API does not include the avatar URLs in responses when this setting is disabled.

Screenshot of setting being referenced:
image

Example query:

query NewQuery {
  viewer {
    avatar {
      url
    }
  }
}

Output from example query:

{
  "data": {
    "viewer": {
      "avatar": {
        "url": "http://1.gravatar.com/avatar/729ae85bf62b9917e93538db2f2688ca?s=96&d=mm&r=g"
      }
    }
  }
}

Steps to reproduce

  1. Go to Settings > Discussions in wp-admin
  2. Ensure the "Show Avatars" checkbox is NOT checked and save the settings
  3. Do the above example query
  4. See avatar URLs in response

Additional context

No response

WPGraphQL Version

1.21.0

WordPress Version

6.4.3

PHP Version

8.1.23

Additional environment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.

@mindctrl thanks for opening this issue!

We have 2 options (maybe more) to consider here.

Currently users are able to query for an avatar like so:

{
  users {
    nodes {
      avatar {
        sourceUrl
      }
    }
  }
}

and get a payload like:

{
  "data": {
    "users": {
      "nodes": [
        {
          "id": "dXNlcjoz",
          "avatar": {
            "url": "https://0.gravatar.com/avatar/94bf4ea789246f76c48bcf8509bcf01e?s=96&d=mm&r=g"
          }
        },
      ]
    }
  }
}

And that avatar.url renders an avatar like so:

CleanShot 2024-03-01 at 15 56 35

I think we have 2 options here:

Resolve as Null

Resolve as null for all queries to the avatar field, like so:

{
  "data": {
    "users": {
      "nodes": [
        {
          "id": "dXNlcjoz",
          "avatar":  null,
        },
      ]
    }
  }
}

Resolve with a default fallback avatar

Resolve an avatar, but have it be a fallback one, like:

{
  "data": {
    "users": {
      "nodes": [
        {
          "id": "dXNlcjoz",
          "avatar":  "https://2.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=96&d=mm&r=g",
        },
      ]
    }
  }
}

i.e.

CleanShot 2024-03-01 at 15 59 22


I think the "right" answer is likely to return null and let the client determine what a fallback should be if nothing is returned. 🤔

I think the "right" answer is likely to return null and let the client determine what a fallback should be if nothing is returned

+1 not just because that's how REST avatars (and WPGraphQL media items, in a sense) work, but also because of

  • the headache involved of trying to determine from the schema results when a served image is a fallback.
  • the WP setting toggles showing/disabling avatars (there's a separate option for choosing a default fallback to mystery man or whatever if avatars are enabled but unset for a user).

(Philosophically, the pure approach is probably to remove the avatar field altogether, but without user Interfaces that are justifiable from a DX perspective this would break reusability e.g. Faust's already over-coupled Admin Bar.)