PHPackages                             mohiohio/graphql-wp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mohiohio/graphql-wp

ActiveWordpress-muplugin[API Development](/categories/api)

mohiohio/graphql-wp
===================

A GraphQL endpoint for WordPress

0.8.5(5y ago)3032.0k20[1 PRs](https://github.com/tim-field/graphql-wp/pulls)GPL-2.0-or-laterPHPPHP &gt;=7

Since Mar 17Pushed 4y ago13 watchersCompare

[ Source](https://github.com/tim-field/graphql-wp)[ Packagist](https://packagist.org/packages/mohiohio/graphql-wp)[ RSS](/packages/mohiohio-graphql-wp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (39)Used By (0)

graphql-wp
==========

[](#graphql-wp)

A GraphQL endpoint for WordPress that's easy to customize.

This is a WordPress Plugin that exposes a GraphQL endpoint at **/graphql**.

Uses this excellent [graphql-php](https://github.com/webonyx/graphql-php) library.

Supports Relay Connections.

Install
-------

[](#install)

`composer require mohiohio/graphql-wp`

If your aren't familiar with using composer with WordPress I'd recommend using a setup like [bedrock](https://roots.io/bedrock/). Otherwise you will at the least need to [require autoload.php](https://getcomposer.org/doc/01-basic-usage.md#autoloading) for this to work.

Using
-----

[](#using)

The best way to explore / develop with this is by visiting `/graphiql` after installation. This will show you the endpoints and arguments that are available. Note this will only work if you are a logged in admin user.

[![https://github.com/tim-field/graphql-wp/raw/master/.readme.md/graphiql.png](https://github.com/tim-field/graphql-wp/raw/master/.readme.md/graphiql.png)](https://github.com/tim-field/graphql-wp/raw/master/.readme.md/graphiql.png)

### wp\_query

[](#wp_query)

This is designed to follow WordPress' existing WP Query functions. So as a rule you can pass the same parameters as your can to [WP Query](https://codex.wordpress.org/Class_Reference/WP_Query)\*.

\**In reality there are a lot of params you can pass to WP\_Query, and I've only implemented the ones that I've needed so far. But adding more is trivial as the arguments are just passed directly to the get\_posts function, so its just a matter of defining them in the schema.*

```
query example {
  wp_query {
    posts(first: 10) {
      edges {
        node {
          title
          name
          terms(taxonomy: "category") {
            name
            slug
          }
        }
      }
    }
  }
}
```

Will give you

```
{
  "data": {
    "wp_query": {
      "posts": {
        "edges": [
          {
            "node": {
              "title": "Dashboard",
              "name": "hello-world",
              "terms": [
                {
                  "name": "Uncategorized",
                  "slug": "uncategorized"
                }
              ]
            }
          }
        ]
      }
    }
  }
}
```

### Post

[](#post)

And of course you can get an individual post

```
query example {
  wp_post(ID: 9) {
    title
    content
    status
  }
}
```

### Custom Fields

[](#custom-fields)

Any meta fields are available like so

```
query example {
  wp_post(ID: 9) {
    title
    foo: meta_value(key: "foo")
    bar: meta_value(key: "bar")
  }
}
```

If you want to define your own resolver / type you can extend the field schema for a post type like so.

```
// There is a get_{post_type}_schema call available for each post type
add_filter('graphql-wp/get_post_schema', function($schema) {

    $schema['fields'] = function() use ($schema) {
        // Note call to "parent" function here
        return $schema['fields']() + [
            'foo' => [
                'type' => Type::string(),
                'resolve' => function($post) {
                    return get_post_meta($post->ID, 'foo' ,true);
                }
            ],
            'bar' => [
                'type' => Type::string(),
                'resolve' => function($post) {
                    return get_post_meta($post->ID, 'bar' ,true);
                }
            ]
        ];
    };
    return $schema;
});
```

### Custom Post Types

[](#custom-post-types)

This is how you can add custom post types ( which have custom fields ) to a client specific plugin. graphql-wp/get\_post\_types is a good hook for this. Where `$types` is a hash of the schema we are working with, so just add new items into this and you are good to go.

```
use GraphQL\Type\Definition\Type;
use Mohiohio\GraphQLWP\Type\Definition\Post;
use Mohiohio\GraphQLWP\Type\Definition\Attachment;

class Foo extends Post {

    static function getDescription() {
        return "A custom post type example, for post type `foo`";
    }

    static function getFieldSchema() {
        return parent::getFieldSchema() + [
            'website' => [
                'type' => Type::string(),
                'resolve' => function($post) {
                    return get_post_meta($post->ID,'website',true);
                },
            ],
            'image' => [
                'type' => Attachment::getInstance(),
                'resolve' => function($post) {
                    $attachment_id = get_post_meta($post->ID,'image',true);
                    return $attachment_id ? get_post($attachment_id) : null;
                },
            ]
        ];
    }
}

add_filter('graphql-wp/schema-types', function($types){
    return array_merge($types, [
        Foo::getInstance()
    ]);
});
```

### In the wild

[](#in-the-wild)

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 89.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~46 days

Recently: every ~3 days

Total

35

Last Release

2140d ago

PHP version history (4 changes)0.0.1PHP &gt;=5.4

0.1.2PHP &gt;=5.5

0.2.x-devPHP &gt;=5.6

0.4.4PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bdb150c3bf62b8fcc5f86ff9eba0a29ba426dfbdadcfbf8b00ff84570090bcd?d=identicon)[timfield](/maintainers/timfield)

---

Top Contributors

[![tim-field](https://avatars.githubusercontent.com/u/1326910?v=4)](https://github.com/tim-field "tim-field (160 commits)")[![balintsera](https://avatars.githubusercontent.com/u/8377085?v=4)](https://github.com/balintsera "balintsera (8 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (3 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (2 commits)")[![tony-luisi](https://avatars.githubusercontent.com/u/13082144?v=4)](https://github.com/tony-luisi "tony-luisi (2 commits)")[![jbenesch](https://avatars.githubusercontent.com/u/34683?v=4)](https://github.com/jbenesch "jbenesch (1 commits)")[![dlackty](https://avatars.githubusercontent.com/u/14349?v=4)](https://github.com/dlackty "dlackty (1 commits)")[![graphan](https://avatars.githubusercontent.com/u/22321063?v=4)](https://github.com/graphan "graphan (1 commits)")[![Aaron3](https://avatars.githubusercontent.com/u/2073168?v=4)](https://github.com/Aaron3 "Aaron3 (1 commits)")

---

Tags

graphqlgraphql-endpointgraphql-wpheadless-cmswordpress

### Embed Badge

![Health badge](/badges/mohiohio-graphql-wp/health.svg)

```
[![Health](https://phpackages.com/badges/mohiohio-graphql-wp/health.svg)](https://phpackages.com/packages/mohiohio-graphql-wp)
```

###  Alternatives

[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

169425.2k8](/packages/pocketmine-bedrock-protocol)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
