> For the complete documentation index, see [llms.txt](https://docs.acpt.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.acpt.io/integrations/wpgraphql.md).

# WPGraphQL

WPGraphQL Integration

### First steps

If you don't have WPGraphQL installed, install it from the [official WordPress repository](https://wordpress.org/plugins/wp-graphql/).

Once it's installed, go to the main [ACPT dashboard](/basics/custom-post-types.md).

If you want to enable support for a particular custom post type, go to Edit > Settings, and here you'll find three new fields:

* **Show in GraphQL** - set to true
* **GraphQL single name** - the single name used for GraphQL queries
* **GraphQL plural name** - the plural name used for GraphQL queries

Single and plural names must be different.

Please note that Post and Page posts have the WPGraphQL support enabled by default.

### Performing base queries

Open up the GraphiQL IDE provided by WPGraphQL. Suppose you have a CPT named `movie`. In the left sidebar navigate to `movies` node; you'll notice a node called `acpt` in the edges.

Click to expand it. You find two main subnodes:

* `meta`: the meta boxes array representation
* `product_data`: the product data array (only for WooCommerce product CPT)

Now try to run this query by selecting all the `meta` subnodes:

```graphql
{
  movies {
    edges {
      node {
        databaseId
        title
        acpt {
          meta {
            meta_boxes {
              name
              meta_fields {
                name
                type
                values
              }
            }
          }
        }
      }
    }
  }
}
```

{% hint style="warning" %}
`meta` resolves to a **list of meta boxes** (`meta_boxes`), each with its own `meta_fields` — not a flat `meta_box`/`meta_fields` pair. Querying `values` on a **Repeater** field currently throws a GraphQL type error, since a repeater's value is a nested structure rather than a plain string; exclude Repeater fields from this query for now.
{% endhint %}

You'll obtain something like this:

<figure><img src="https://3235524095-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fiyf0tSKPgXiyoQ3zV3I6%2Fuploads%2Fgit-blob-e1293d87526f0babbd2da8beaed4e3497fb90a53%2Fwpgraphql-min.png?alt=media" alt=""><figcaption></figcaption></figure>

### More advanced queries

ACPT extends the base `RootQuery` adding the possibility to perform queries on meta.

Go again to `movies`, but this time expand the `query` node. Notice the `meta_query` subnode.

This node contains two subnodes:

* `elements` - the array of query elements:
  * `compare`
  * `key`
  * `type`
  * `value`
  * `value_num`
* `relation` - possible values: `OR` `AND`

As you can imagine this mimics the [WP Query](https://developer.wordpress.org/reference/classes/wp_query/) logic.

This is an example of a query performed on meta fields:

```graphql
{
  movies(
    where: {
      query: {
        meta_query: { elements: [{ key: "info_altro", value: "value" }] }
      }
    }
  ) {
    edges {
      node {
        id
        databaseId
        title
      }
    }
  }
}

```

We encourage you to use WPGraphQL in your projects, and read more about headless CMS Wordpress.
