Ad
Wpgraphql- Make Data Private
I want to make data private (to return null when query is fetched). I know that there is graphql_data_is_private filter, but I don't know how to implement my query, there's no example in docs.
Docs (https://www.wpgraphql.com/filters/graphql_data_is_private/):
apply_filters( 'graphql_data_is_private', bool $is_private, string $model_name, mixed $data, string $visibility, int $owner, WP_User $current_user );
My query:
query MyQuery {
users {
edges {
node {
lastName
}
}
}
}
Ad
Answer
It's not a query option, it's a BE definition, you should add a filter (in your plugin or theme code) to modify (adapt to your needs) standard BE behaviour. This filter (hook) (for queried object) is used to check if data should be returned.
add_filter('graphql_data_is_private', 'add_graphql_private_visibility_filter', 10, 6);
function add_graphql_private_visibility_filter($is_private, $model_name, $data, $visibility, $owner, $current_user)
{
if ('UserObject' === $model_name) {
// if( is_your_allowed_data_condition ) return false;
return true;
}
// return not changed for other objects
return $is_private;
}
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad