Homepage
Link to WPGraphQL on Github
Link to WPGraphQL on WordPress.org

graphql

Given an array with a Query and optional Variables and Operation Name this executes a GraphQL request.

Paramaters

  • $operation (array): An associative array of key/value pairs for the operation to execute.
    • $query (string): The Query string to execute. This can be a mutation as well.
    • $variables (array): Array of variables to be used with the operation
    • $operation_name (string): The name of the operation.

Source

File: access-functions.php

Examples

The graphql() function can be used to execute GraphQL operations within PHP. WPGraphQL uses this method heavily within it’s automated test suites.

Query a List of Posts in PHP

Here’s an example of querying a list of posts using the graphql() function:

Query with Arguments in PHP

Here’s an example of querying with arguments in PHP.