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

deregister_graphql_field

Given a Type Name and Field Name, this removes the field from the TypeRegistry

Parameters

  • $type_name (string): The Type Name
  • $field_name (string): The Field Name to remove from the TypeRegistry

Source

File: access-functions.php

Examples

Below is an example of removing the commentCount field from the Post type. First the comment count can be seen on the Post type in the below GraphiQL example:

Example showing the commentCount field is available on the Post type

Now we can use the deregister_graphql_field function to remove this field from the Post type.

Now this field is no longer available to be queried and results in a GraphQL error.