Adewale Perfect
Adewale Perfect

Reputation: 573

Why do my GraphQL Link shows query error in WordPress

I installed WPGraphQL plugin on my wordpress dashboard but And I tried accessing it via mysite/graphql

I got this error

{"errors":[{"message":"GraphQL Request must include at least one of those two parameters: \"query\" or \"queryId\"","extensions":{"category":"request"}}],"extensions":{"debug":[]}}

What could be the cause?

Upvotes: 3

Views: 5581

Answers (5)

moonmeister
moonmeister

Reputation: 26

As others have pointed out, while that is the GraphQL endpoint, it requires a data to be provided. There are several options:

  1. Use the built in GraphiQL IDE

screenshot of admin dashboard showing GraphiQL IDE

As the image show there are links in the Admin Bar, under the GraphQL menu on the left side or you can go link directly there (e.g. http://localhost:8080/wp-admin/admin.php?page=graphiql-ide)

  1. Provide a query for your HTTP GET request as has been suggested

From the browser: http://localhost:8080/graphql?query={posts{nodes{title,content}}}

  1. Make an HTTP POST request with the query in the body

using curl: curl -H "Content-Type: application/json" -X POST -d '{ "query":"{posts{nodes{title,slug}}}" }' http://localhost:8080/graphql

Upvotes: 0

Hossein Hashemi
Hossein Hashemi

Reputation: 15

If you want to use "GraphQl playground" and facing this error,you may entered the wrong url ,the correct url for playground is : "http://127.0.0.1:8000/graphql-playground"

Upvotes: 0

KiwiTau
KiwiTau

Reputation: 1

I think something like this is what you may be after:

curl -v -X POST -H 'X-WP-NONCE: 6fd57fe0ac' --cookie 'wordpress_logged_in_37d007a56d816107ce5b52c10342db37=wordpress|1647471410|i2dnczBB8vm2pblmRJWQ0NtuQ1lA7elWpB1TiRhXeMi|9c3dc66b56babcafa294156dc91f65cc6b2c2feb5e784a0380eb6c44141fb5c6' -F 'query={posts{edges{node{id}}}}' 'http://localhost:8080/graphql'

Upvotes: 0

brentj
brentj

Reputation: 3

As others have stated, you need a query.

When the extension is activated, it serves as any API. It'll give you the data that you request, not direct you to some website. You can access the GraphiQL IDE to get a visual representation of the queries you can make.

Upvotes: 0

Syed Arsalan Ahmed
Syed Arsalan Ahmed

Reputation: 165

You have to pass an query parameter e-g: http://localhost:8000/graphql?query={user(id:1){email}} and you want graphql-playground then install play-ground package then just access play-ground by this link: http://localhost:8000/graphql-playground

Upvotes: 2

Related Questions