Skip to content

WPGraphQL Integration

Matthew Ell edited this page Mar 25, 2024 · 2 revisions

As of #152, WP Curate has built-in integration with WPGraphQL to support GraphQL applications.

Integrations

  • The interface type named WPCurateInterface is registered to GraphQL via WPGraphQL.
  • A connection field named wpCuratePosts on RootQuery use to access WP Curate posts. Supports Inline Fragments when constructing your GraphQL queries.

Hooks

Add custom post types using wp_curate_allowed_post_types which will apply the WPCurateInterface to each of the registered GraphQL Types.

Example

An example GraphQL query that takes an array of IDs from various post types. The wpCuratePosts connection will identify the post type based on the ID and apply the appropriate inline fragment according to it's registered type.

query myQuery($ids: [ID!]!) {
  wpCuratePosts(where: {in: $ids}) {
    nodes {
      type: __typename
      id: databaseId
      title
      cleanTitle
      url: uri
      date
      updatedAt: modified
      slug
      ... on MyCustomPostType {
        tags {
          nodes {
            name
            slug
          }
        }
      }
      ... on Post {
        excerpt: excerptRawRaw
        categories {
          nodes {
            id: databaseId
            title: name
            url: uri
          }
        }
      }
    }
  },
}
Clone this wiki locally