-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package
graphql
migrated to object-based config.
- Loading branch information
1 parent
6d9b78a
commit 4f0eddc
Showing
37 changed files
with
817 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Operator; | ||
use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Direction; | ||
use LastDragon_ru\LaraASP\GraphQL\SortBy\Enums\Nulls; | ||
use Nuwave\Lighthouse\Schema\Directives\RenameDirective; | ||
use LastDragon_ru\LaraASP\GraphQL\PackageConfig; | ||
|
||
/** | ||
* ----------------------------------------------------------------------------- | ||
* GraphQL Settings | ||
* ----------------------------------------------------------------------------- | ||
* | ||
* Note: You need to clear/rebuild the cached schema and IDE helper files after | ||
* changing any of the settings. | ||
* | ||
* @see https://lighthouse-php.com/master/api-reference/commands.html#clear-cache | ||
* @see https://lighthouse-php.com/master/api-reference/commands.html#ide-helper | ||
* | ||
* @var array{ | ||
* search_by: array{ | ||
* operators: array<string, list<string|class-string<Operator>>>, | ||
* }, | ||
* sort_by: array{ | ||
* operators: array<string, list<string|class-string<Operator>>>, | ||
* nulls: Nulls|non-empty-array<value-of<Direction>, Nulls>|null, | ||
* }, | ||
* stream: array{ | ||
* search: array{ | ||
* name: string, | ||
* enabled: bool, | ||
* }, | ||
* sort: array{ | ||
* name: string, | ||
* enabled: bool, | ||
* }, | ||
* limit: array{ | ||
* name: string, | ||
* default: int<1, max>, | ||
* max: int<1, max>, | ||
* }, | ||
* offset: array{ | ||
* name: string, | ||
* } | ||
* }, | ||
* builder: array{ | ||
* allowed_directives: list<class-string>, | ||
* }, | ||
* } $settings | ||
*/ | ||
$settings = [ | ||
/** | ||
* Settings for {@see \LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByDirective @searchBy} directive. | ||
*/ | ||
'search_by' => [ | ||
/** | ||
* Operators | ||
* --------------------------------------------------------------------- | ||
* | ||
* You can redefine operators for exiting (=default) types OR define own | ||
* types here. Note that directives is the recommended way and have | ||
* priority over the array. Please see the documentation for more | ||
* details. | ||
*/ | ||
'operators' => [ | ||
// empty | ||
], | ||
], | ||
|
||
/** | ||
* Settings for {@see \LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions\SortByDirective @sortBy} directive. | ||
*/ | ||
'sort_by' => [ | ||
/** | ||
* Operators | ||
* --------------------------------------------------------------------- | ||
* | ||
* You can redefine operators for exiting (=default) types OR define own | ||
* types here. Note that directives is the recommended way and have | ||
* priority over the array. Please see the documentation for more | ||
* details. | ||
*/ | ||
'operators' => [ | ||
// empty | ||
], | ||
|
||
/** | ||
* NULLs | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* Determines how the `NULL` values should be treatment. By default, | ||
* there is no any processing, so the order of `NULL` depends on the | ||
* database. It may be set for all (if single value) or for each | ||
* direction (if array). Not all databases/builders may be supported. | ||
* Please check the documentation for more details. | ||
* | ||
* @see Nulls | ||
*/ | ||
'nulls' => null, | ||
], | ||
|
||
/** | ||
* Settings for {@see \LastDragon_ru\LaraASP\GraphQL\Stream\Definitions\StreamDirective @stream} directive. | ||
*/ | ||
'stream' => [ | ||
'search' => [ | ||
'name' => 'where', | ||
'enabled' => true, | ||
], | ||
'sort' => [ | ||
'name' => 'order', | ||
'enabled' => true, | ||
], | ||
'limit' => [ | ||
'name' => 'limit', | ||
'default' => 25, | ||
'max' => 100, | ||
], | ||
'offset' => [ | ||
'name' => 'offset', | ||
], | ||
], | ||
$config = PackageConfig::getDefaultConfig(); | ||
|
||
/** | ||
* General settings for all `Builder` directives like `@searchBy`/`@sortBy`/etc. | ||
*/ | ||
'builder' => [ | ||
/** | ||
* The list of the directives which should be copied from the original | ||
* field into the generated `input` field. | ||
* | ||
* Important notes: | ||
* - All other directives except {@see Operator} (for the current | ||
* directive) will be ignored. | ||
* - There are no any checks that directive can be used on | ||
* `INPUT_FIELD_DEFINITION`. | ||
* - The `instanceof` operator is used to check. | ||
* - Applies for Implicit types only. | ||
*/ | ||
'allowed_directives' => [ | ||
RenameDirective::class, | ||
], | ||
], | ||
]; | ||
// ... | ||
|
||
return $settings; | ||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/graphql/docs/Directives/@searchByConfigOperators.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\PackageConfig; | ||
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorBetweenDirective; | ||
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions\SearchByOperatorEqualDirective; | ||
|
||
$config = PackageConfig::getDefaultConfig(); | ||
|
||
// You can define a list of operators for each type | ||
$config->searchBy->operators['Date'] = [ | ||
SearchByOperatorEqualDirective::class, | ||
SearchByOperatorBetweenDirective::class, | ||
// MyCustomOperator::class, | ||
]; | ||
|
||
// Or re-use existing type | ||
$config->searchBy->operators['DateTime'] = [ | ||
'Date', | ||
]; | ||
|
||
// Or re-use built-in type | ||
$config->searchBy->operators['Int'] = [ | ||
'Int', // built-in operators for `Int` will be used | ||
// MyCustomOperator::class, // the custom operator will be added | ||
]; | ||
|
||
// You can also use enum name to redefine default operators for it: | ||
$config->searchBy->operators['MyEnum'] = [ | ||
'Boolean', | ||
]; | ||
|
||
// Return | ||
return $config; |
Oops, something went wrong.