Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Created February 5, 2019 20:36
Show Gist options
  • Save jasonbahl/6ec45e7182dba5270506b82e9218a08a to your computer and use it in GitHub Desktop.
Save jasonbahl/6ec45e7182dba5270506b82e9218a08a to your computer and use it in GitHub Desktop.
pseudo code to filter mutations to not execute if they're duplicate requests. . .see: https://github.com/wp-graphql/wp-graphql/issues/602#issuecomment-460791863
add_action( 'graphql_before_resolve_field', function( $source, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info, $field_resolver, $type_name, $field_key, $field ) {
if ( 'RootMutation' === $info->parentType->name ) {
$type = \WPGraphQL\TypeRegistry::get_type( $type_name );
if ( isset( $type ) && ! empty( $field = $type->getField( $field_key ) ) ) {
if ( isset( $field->config['isPublic'] ) && true === $field->config['isPublic'] ) {
if ( true === true ) {
throw new Exception( __( 'This mutation has been executed too many times in the allowed timeframe', 'wp-graphql' ) );
}
}
}
}
return;
}, 10, 8 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment