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


WPGraphQL provides support for querying Media Items, what WordPress calls "attachments".

This page will be most useful for users what are familiar with GraphQL Concepts and understand the basics of writing GraphQL Queries.

Querying Media Items

WPGraphQL supports querying Media Items in various ways.

Below are some common examples of querying Media Items with WPGraphQL.

List of Media Items

Below is an example of querying a list of media items.

Screenshot of a query for a list of Media Items

Single Media Item by Global ID

Below is an example of querying a Media Item using its Global ID.

Screenshot of a query for a Media Item using the global ID

Single Media Item by Source Url

If you have the source url for an image in the media library, you can use that as a unique identifier for querying an Media Item.

Screenshot of a Query for a Media Item using the sourceUrl as the ID

Query a post with it's featured image

Below is an example of querying a Post using its Database ID, and its connected Featured Image.

The connection between the Post and Featured image is a good example of a one-to-one connection.

Screenshot of a GraphQL Query for a post and its connected featured image

Mutating Media Items

NOTE: WPGraphQL supports mutations for the data stored in the Database for Media Items, but WPGraphQL does not (yet) provide a way to handle the actual uploads of files. See open issues related to this topic.