Gato GraphQL logo

Internal GraphQL Server

Internal GraphQL Server

This extension installs an internal GraphQL Server, that can be invoked within your application, using PHP code.

The internal GraphQL server provides class GraphQLServer with three methods:

  • executeQuery: Execute a GraphQL query
  • executeQueryInFile: Execute a GraphQL query contained in a (.gql) file
  • executePersistedQuery: Execute a persisted GraphQL query (providing its ID as an int, or slug as a string)

For instance, we can hook into an action hook, and call GraphQLServer::executeQuery passing the hook values to the query:

  function (WP_Post $post) {
    if ($post->post_type !== 'post') {
    $query = ' { ... } ';
    $variables = [
      'postTitle' => $post->post_title,
      'postContent' => $post->post_content,
    GraphQLServer::executeQuery($query, $variables);