Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update field cache to allow it to be used wihtout the query_name #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/FieldCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,9 @@ function activate(AbstractBackend $backend)

function __action_do_graphql_request(string $query, $operation_name)
{
// Capture from operation name if available
if ($operation_name === $this->query_name) {
$this->query = $query;
return;
}

$current_query_name = Utils::get_query_name($query);
if ($current_query_name === $this->query_name) {
$this->query = $query;
}
$this->query = $query;

}

function __filter_graphql_pre_resolve_field(
Expand All @@ -98,6 +91,7 @@ function __filter_graphql_pre_resolve_field(
$field,
$field_resolver
) {

// No query, no query name match
if (!$this->query) {
return $nil;
Expand All @@ -116,13 +110,22 @@ function __filter_graphql_pre_resolve_field(
// Mark as mached ie. this field should be cached
$this->match = true;

$query_name = Utils::sanitize($this->query_name);
$field_name = Utils::sanitize($this->field_name);
$args_hash = Utils::hash(Utils::stable_string($args));
$query_hash = Utils::hash($this->query);
$user_id = get_current_user_id();

$this->key = "field-{$query_name}-${field_name}-${user_id}-{$query_hash}-${args_hash}";
if ( $this->query_name ) {
// If query name is configured, include the query hash in the cache key.

$query_name = Utils::sanitize($this->query_name);
$query_hash = Utils::hash($this->query);

$this->key = "field-${query_name}-${field_name}-${user_id}-${query_hash}-${args_hash}";
} else {
// If query name is not configured, do not include the query hash in the cache key.

$this->key = "field-${field_name}-${user_id}-${args_hash}";
}

$this->read_cache();

Expand Down