Below is a connection that adds the ability to query page siblings (i.e. pages that share the same parent)
Post Type Archives: Recipes
Fix pagination conflict with the “Advanced Taxonomy Terms Order” plugin
When using the Advanced Taxonomy Terms Order plugin along with WPGraphQL, you might experience some issues with paginated queries. This snippet should help correct the conflict: What this snippet does: First, this hooks into pre_get_terms which fires when WP_Term_Query is executing to get Terms out of the database. This checks to see if the request …
Continue reading “Fix pagination conflict with the “Advanced Taxonomy Terms Order” plugin”
Fix pagination conflict with the “Post Type Order” plugin
When using the Post Type Order plugin along with WPGraphQL, you might experience some issues with paginated queries. This snippet should help correct the conflict: What this snippet does: First, this hooks into pre_get_posts which fires when WP_Query is executing. This then checks to see if the request is a GraphQL request and whether Post …
Continue reading “Fix pagination conflict with the “Post Type Order” plugin”
Deprecating a field in the Schema
Sometimes it can be helpful to deprecate a field in the Schema without removing it altogether. This snippet shows how to deprecate the `Post.excerpt` field. You can use this technique to deprecate other fields. After using this snippet, we can verify in the WPGraphQL Schema Docs that the field is indeed deprecated:
Allow login mutation to be public when the endpoint is fully restricted
If you’ve configured your WPGraphQL settings to “Limit the execution of GraphQL operations to authenticated requests”, this will block all root operations unless the user making the request is already authenticated. If you’re using a GraphQL mutation to authenticate, such as the one provided by WPGraphQL JWT Authentication, you might want to allow the login …
Continue reading “Allow login mutation to be public when the endpoint is fully restricted”
Remove Extensions from GraphQL Response
This snippet removes the “extensions” from the GraphQL response: Before After
Query the Homepage
In WordPress, the homepage can be a Page or an archive of posts of the Post post_type (which is represented by WPGraphQL as a “ContentType” node). This query allows you to query the homepage, and specify what data you want in response if the homepage is a page, or if the homepage is a ContentType …
Make all Users Public
The following snippets allow for Users with no published content to be shown in public (non-authenticated) WPGraphQL query results. For a more detailed write-up, read the blog post: Allowing WPGraphQL to show unpublished authors in User Queries
Register a basic Mutation
This snippet shows how to register a basic GraphQL Mutation with a single input field, a single output field, and the input is simply returned as the value for the output.
Showing Post Type labels in public queries
WPGraphQL respects WordPress core access control rights. This means that data that is only available to authenticated users in the WordPress admin is only available to authenticated users making GraphQL requests. Sometimes, you want to expose fields that are restricted by default. Take the Post Type Label field, for example. Querying for the label of …
Continue reading “Showing Post Type labels in public queries”