Skip to content

Commit

Permalink
Format and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Dec 14, 2022
1 parent 1f67e49 commit 6991ddc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can find and compare releases at the [GitHub release page](https://github.co

### Fixed

- Create a new `ResolveInfo` class to extend with `$argumentSet` in response to PHP 8.2 deprecating dynamic properties
- Wrap base `ResolveInfo` class and extend it with `public ArgumentSet $argumentSet` in response to PHP 8.2 deprecating dynamic properties

## v5.69.0

Expand Down
2 changes: 1 addition & 1 deletion docs/5/custom-directives/field-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Query {
A [`\Nuwave\Lighthouse\Support\Contracts\FieldBuilderDirective`](https://github.com/nuwave/lighthouse/blob/master/src/Support/Contracts/FieldBuilderDirective.php)
directive allows modifying the database query that Lighthouse creates for a field.

> This directive only works if the field resolver passes its builder through a call to `$resolveInfo->argumentSet->enhanceBuilder()`.
> This directive only works if the field resolver passes its builder through a call to `$resolveInfo->enhanceBuilder()`.
> Built-in field resolver directives that query the database do this, such as [@all](../api-reference/directives.md#all) or [@hasMany](../api-reference/directives.md#hasmany).

The following directives use the defined filter for resolving the query:
Expand Down
2 changes: 1 addition & 1 deletion docs/master/custom-directives/field-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Query {
A [`\Nuwave\Lighthouse\Support\Contracts\FieldBuilderDirective`](https://github.com/nuwave/lighthouse/blob/master/src/Support/Contracts/FieldBuilderDirective.php)
directive allows modifying the database query that Lighthouse creates for a field.

> This directive only works if the field resolver passes its builder through a call to `$resolveInfo->argumentSet->enhanceBuilder()`.
> This directive only works if the field resolver passes its builder through a call to `$resolveInfo->enhanceBuilder()`.
> Built-in field resolver directives that query the database do this, such as [@all](../api-reference/directives.md#all) or [@hasMany](../api-reference/directives.md#hasmany).

The following directives use the defined filter for resolving the query:
Expand Down
2 changes: 2 additions & 0 deletions src/Execution/Arguments/ArgumentSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function has(string $key): bool
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\Relation|\Laravel\Scout\Builder
*
* @phpstan-return TBuilder
*
* @deprecated will be moved to \Nuwave\Lighthouse\Execution\ResolveInfo
*/
public function enhanceBuilder(object $builder, array $scopes, \Closure $directiveFilter = null): object
{
Expand Down
10 changes: 6 additions & 4 deletions src/Schema/Directives/AllDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public function resolveField(FieldValue $fieldValue): FieldValue
$query = $this->getModelClass()::query();
}

return $resolveInfo->enhanceBuilder(
$query,
$this->directiveArgValue('scopes', [])
)->get();
return $resolveInfo
->enhanceBuilder(
$query,
$this->directiveArgValue('scopes', [])
)
->get();
});

return $fieldValue;
Expand Down
10 changes: 6 additions & 4 deletions src/Schema/Directives/FindDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public static function definition(): string
public function resolveField(FieldValue $fieldValue): FieldValue
{
$fieldValue->setResolver(function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): ?Model {
$results = $resolveInfo->enhanceBuilder(
$this->getModelClass()::query(),
$this->directiveArgValue('scopes', [])
)->get();
$results = $resolveInfo
->enhanceBuilder(
$this->getModelClass()::query(),
$this->directiveArgValue('scopes', [])
)
->get();

if ($results->count() > 1) {
throw new Error('The query returned more than one result.');
Expand Down
10 changes: 6 additions & 4 deletions src/Schema/Directives/FirstDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public static function definition(): string
public function resolveField(FieldValue $fieldValue): FieldValue
{
$fieldValue->setResolver(function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): ?Model {
return $resolveInfo->enhanceBuilder(
$this->getModelClass()::query(),
$this->directiveArgValue('scopes', [])
)->first();
return $resolveInfo
->enhanceBuilder(
$this->getModelClass()::query(),
$this->directiveArgValue('scopes', [])
)
->first();
});

return $fieldValue;
Expand Down

0 comments on commit 6991ddc

Please sign in to comment.