Skip to content

Commit

Permalink
Apply versioning only to reading state, and not to nested queries any…
Browse files Browse the repository at this point in the history
…more
  • Loading branch information
Aaron Carlino committed Feb 15, 2021
1 parent b6cab40 commit 821494e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/GraphQL/Plugins/VersionedRead.php
Expand Up @@ -40,6 +40,13 @@ public function apply(ModelQuery $query, Schema $schema, array $config = []): vo
return;
}

// The versioned argument only affects global reading state. Should not
// apply to nested queries.
$rootQuery = $schema->getQueryType()->getFieldByName($query->getName());
if (!$rootQuery) {
return;
}

$query->addResolverAfterware([VersionedResolver::class, 'resolveVersionedRead']);
$query->addArg('versioning', 'VersionedInputType');
}
Expand Down
6 changes: 4 additions & 2 deletions src/GraphQL/Resolvers/VersionedResolver.php
Expand Up @@ -101,8 +101,10 @@ public static function resolveVersionedRead(DataList $list, array $args, array $
return $list;
}

return Injector::inst()->get(VersionFilters::class)
->applyToList($list, $args['versioning']);
Injector::inst()->get(VersionFilters::class)
->applyToReadingState($args['versioning']);

return $list;
}

/**
Expand Down

0 comments on commit 821494e

Please sign in to comment.