Filters

WordPress provides an API called "filters" which allow functions to modify data of other functions. WPGraphQL applies many filters throughout its codebase allowing developers to customize the Schema and other parts of the GraphQL server. Below are the filters provided by WPGraphQL that are available for developers to hook into.

graphql_schema_config

Set the $filterable_config as the $config that was passed to the WPSchema when instantiated

View Filter

graphql_object_fields

Filter all object fields, passing the $typename as a param. This is useful when several different types need to be easily filtered at once. . .for example, if ALL types with a field of a certain name needed to be adjusted, or something to that tune.

View Filter

graphql_request_data

Allow the request data to be filtered. Previously this filter was only applied to non-HTTP requests. Since 0.2.0, we will apply it to all requests.

View Filter

graphql_map_input_fields_to_wp_user_query

Filter the input fields. This allows plugins/themes to hook in and alter what $args should be allowed to be passed from a GraphQL Query to the WP_User_Query.

View Filter

graphql_map_input_fields_to_get_terms

Filter the input fields. This allows plugins/themes to hook in and alter what $args should be allowed to be passed from a GraphQL Query to the get_terms query.

View Filter

graphql_term_object_connection_query_args

Filter the query_args that should be applied to the query. This filter is applied AFTER the input args from the GraphQL Query have been applied and has the potential to override the GraphQL Query Input Args.

View Filter

graphql_is_graphql_http_request

Filter whether the request is a GraphQL HTTP Request. Default is false, as the majority of WordPress requests are NOT GraphQL requests (at least today that’s true ????).

View Filter

graphql_pre_is_graphql_http_request

Filter whether the request is a GraphQL HTTP Request. Default is null, as the majority of WordPress requests are NOT GraphQL requests (at least today that’s true ????).

View Filter

graphql_endpoint

Pass the route through a filter in case the endpoint /graphql should need to be changed

View Filter

graphql_request_results

Filter the $response of the GraphQL execution. This allows for the response to be filtered before it’s returned, allowing granular control over the response at the latest point.

View Filter

graphql_authentication_errors

If false, there are no authentication errors. If true, execution of the GraphQL request will be prevented and an error will be thrown.

View Filter

graphql_post_object_create_default_post_status

Filter the default post status to use when the post is initially created. Pass through a filter to allow other plugins to override the default (for example, Edit Flow, which provides control over customizing statuses or various E-commerce plugins that make heavy use of custom statuses)

View Filter

graphql_map_input_fields_to_wp_query

Filter the input fields. This allows plugins/themes to hook in and alter what $args should be allowed to be passed from a GraphQL Query to the WP_Query.

View Filter

graphql_pre_return_field_from_model

Filter to short circuit the callback for any field on a type. Returning anything other than null will stop the callback for the field from executing, and will return your data or execute your callback instead.

View Filter

graphql_resolve_menu_item

Allow users to override how nav menu items are resolved. This is useful since we often add taxonomy terms to menus but would prefer to represent the menu item in other ways, e.g., a linked post object (or vice-versa).

View Filter

graphql_pre_resolve_field

When this filter return anything other than the $nil it will be used as the resolved value and the execution of the actual resolved is skipped. This filter can be used to implement field level caches or for efficiently hiding data by returning null.

View Filter

graphql_resolve_node_type

Add a filter to allow externally registered node types to return the proper type based on the node_object that’s returned

View Filter

graphql_map_input_fields_to_wp_comment_query

Filter the input fields. This allows plugins/themes to hook in and alter what $args should be allowed to be passed from a GraphQL Query to the get comments query.

View Filter

graphql_comment_connection_query_args

Filter the query_args that should be applied to the query. This filter is applied AFTER the input args from the GraphQL Query have been applied and has the potential to override the GraphQL Query Input Args.

View Filter

graphql_app_context_config

This filters the config for the AppContext. This can be used to store additional context config, which is available to resolvers throughout the resolution of a GraphQL request.

View Filter

graphql_data_loaders

This filters the data loaders, allowing for additional loaders to be added to the AppContext or for existing loaders to be replaced if needed.

View Filter

graphql_dataloader_pre_get_model

This filter allows the model generated by the DataLoader to be filtered. Returning anything other than null here will bypass the default model generation for an object.

View Filter

graphql_connection

Filter the connection. In some cases, connections will want to provide additional information other than edges, nodes, and pageInfo. This filter allows additional fields to be returned to the connection resolver

View Filter

graphql_connection_nodes

Set the items. These are the “nodes” that make up the connection. Filters the nodes in the connection.

View Filter

graphql_connection_should_execute

Check if the connection should execute. If conditions are met that should prevent the execution, we can bail from resolving early, before the query is executed.

View Filter

graphql_connection_max_query_amount

Filter the maximum number of posts per page that should be queried. The default is 100 to prevent queries from being exceedingly resource intensive, however individual systems can override this for their specific needs. This filter is intentionally applied AFTER the query_args filter.

View Filter

graphql_connection_query_args

Get the Query Args. This accepts the input args and maps it to how it should be used in the WP_Query.

View Filter

graphql_post_entities_allowed_post_types

Define the $allowed_post_types to be exposed by GraphQL Queries Pass through a filter to allow the post_types to be modified (for example if a certain post_type should not be exposed to the GraphQL API)

View Filter

graphql_show_admin

This filter can be used to disable or enable the GraphQL Admin pages with code.

View Filter