• Besides doing raw cURL calls like

    curl -d '{"query": "query { echo(message: \"Hello World\") }" }' -H "Content-Type: application/json" https://testapi.test/graphql

    What would be the best way of doing the same from WordPress?

    Do I need to manually parse the graphQL query, then just use wp_remote_post and pass the data, or is there a smarter way to do it?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    wp_remote_post() is a wrapper function for WP_Http class methods. Using this class object is preferable to using cURL because it’s more portable. Not all systems have cURL installed. It’s also preferred over native PHP functions like file_get_contents().

    By default WP tries to use cURL when available. If not, it falls back to a stream transport. It’s possible add other compatible transports via the ‘http_api_transports’ filter.

    As you’ve surmised, all this does is send a request and return a response. It’s up to you to construct a proper request and handle the response. There are too many different APIs for WP to provide any higher level interface.

    Of course there’s more flexibility in interfacing with the WP REST API, but for other APIs you’re pretty much on your own.

Viewing 1 replies (of 1 total)
  • The topic ‘Querying 3rd party GraphQL from WordPress’ is closed to new replies.