deregister_graphql_field

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

deregister_graphql_field( string $type_name, string $field_name );

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.

add_action( 'graphql_register_types', 'example_extend_wpgraphql_schema' );

function example_extend_wpgraphql_schema($type_registry) {
	deregister_graphql_field( 'Post', 'commentCount' );
}

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