WebDevStudios / wds-headless-wordpress

This codebase has been moved to a monorepo. Please see the documentation to learn more. 🍻
https://github.com/WebDevStudios/nextjs-wordpress-starter
GNU General Public License v2.0
32 stars 15 forks source link

Make users visible to public in GraphQL context #12

Closed donmhico closed 3 years ago

donmhico commented 3 years ago

Issue

The issue is that we are receiving null as author on comments from users without published post. This is related to https://github.com/WebDevStudios/nextjs-wordpress-starter/issues/233

Feature Description

Per WP GraphQL's docs

WPGraphQL follows WordPress access control rights, and only exposes data publicly that WordPress already exposes publicly. Users that have published posts are considered public entities in WordPress. Users that have not published posts are considered private and will not be included in public GraphQL requests, but will be included in GraphQL requests made by authenticated users with proper capabilities to see the users.

Reference: https://www.wpgraphql.com/docs/users/

This PR make all users public.

Screenshots

How comments look like in the backend Screen Shot 2021-03-12 at 9 37 00 PM

WP GraphQL response prior to this PR Screen Shot 2021-03-12 at 9 39 56 PM

Notice that null is returned instead of John Doe

"node": {
    "content": "<p>Example comment from a new user.<\/p>\n",
    "author": {
        "node": null
    }
}

WP GraphQL with this PR code changes Screen Shot 2021-03-12 at 9 45 20 PM

Steps To Verify Feature

  1. Create a new WP User via WP Dashboad > Users.
  2. Switch to any default theme first so you can comment to a blog post via WP site (not from NextJS frontend).
  3. Perform a non-authenticated GraphQL request that returns the comment. You should see something like the second screenshot above.
  4. Switch to WDS Headless Theme then perform again the same non-authenticated GraphQL request. You should now see the correct author instead of null.

Note: Do not use the GraphiQL IDE on WP Dashboard since it will be authenticated.