WpgraphQL Viewer query always returns null

106 Views Asked by At

I am working on a headless WordPress + Next.js app

In my GraphiQL ide when i query the current viewer (me !) I keep getting null as a result

I am using the latest WP version + latest wpgraphqQL + latest WPGraphQL CORS plugin

May be this is caused by the fact that for the moment my WordPress installation is in local but i tried to add wpgraphQL on another website in production and to reproduce this and I still get this null for my current Viewer

Don't know if this issue is linked to wpgraphQL or me

Thanks for any help

Here is my query

query MyQuery {
  viewer {
    name
    username
  }
}
1

There are 1 best solutions below

0
Nicholas Pretorius On

Viewer queries will return null when the authenticated user is not logged in.

For example:

  • If your WP Admin user is not logged in, you will receive null.
  • When your WP Admin user is logged in, you will receive the values for the viewer specified by your query.

If you are running queries within the WP Admin area and within the WP GraphiQL IDE, there is a small icon to the right of the "Run Query" (play) button with a profile icon.

Clicking this button will run your queries as authenticated (green dot) or not within the WP GraphiQL IDE.

You can find more details in the WP GraphQL docs here: https://www.wpgraphql.com/docs/wp-graphiql#toggle-between-public-and-authenticated-requests