Skip to content

Commit

Permalink
[@searchBy] Root will not contain fields, they are will be in new…
Browse files Browse the repository at this point in the history
… `field` field.
  • Loading branch information
LastDragon-ru committed Feb 8, 2024
1 parent da5efb7 commit 0b3888f
Show file tree
Hide file tree
Showing 27 changed files with 3,800 additions and 508 deletions.
26 changes: 26 additions & 0 deletions packages/graphql/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)

* [ ] `scalar SearchByCondition` => `scalar SearchByObject`.

* [ ] Added the root type that will contain only extra operators and newly added `field` operator (always present and cannot be removed). The new query syntax is:

```graphql
query {
# WHERE name = "LastDragon"
users(where: {
field: { name: {equal: "LastDragon"} }
}) {
id
}
}
```

If you want to use old query syntax, you can add following bindings into application provider:

```php
$this->app->bind(
LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\Root::class,
LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\V5::class,
);
$this->app->bind(
LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\Condition::class,
LastDragon_ru\LaraASP\GraphQL\SearchBy\Types\Condition\V5::class,
);
```

## `@sortBy`

* [ ] `enum SortByTypeFlag { yes }` => `enum SortByTypeFlag { Yes }`. 🤝
Expand Down
40 changes: 24 additions & 16 deletions packages/graphql/docs/Directives/@searchBy.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ That's all, just search 😃 (or look at [generated GraphQL schema](../../src/Se
query {
# WHERE name = "LastDragon"
users(where: {
name: {equal: "LastDragon"}
field: { name: { equal: "LastDragon" } }
}) {
id
}

# WHERE name != "LastDragon"
users(where: {
name: {notEqual: "LastDragon"}
field: { name: { notEqual: "LastDragon" } }
}) {
id
}

# WHERE name = "LastDragon" or name = "Aleksei"
users(where: {
anyOf: [
{name: {equal: "LastDragon"}}
{name: {equal: "Aleksei"}}
{ field: { name: { equal: "LastDragon" } } }
{ field: { name: { equal: "Aleksei" } } }
]
}) {
id
Expand All @@ -101,8 +101,8 @@ query {
users(where: {
not: {
anyOf: [
{name: {equal: "LastDragon"}}
{name: {equal: "Aleksei"}}
{ field: { name: { equal: "LastDragon" } } }
{ field: { name: { equal: "Aleksei" } } }
]
}
}) {
Expand All @@ -111,16 +111,20 @@ query {

# WHERE date IS NULL
users(where: {
date: {isNull: yes}
field: { date: { isNull: Yes } }
}) {
id
}

# Relationship: WHERE EXIST (related table)
comments(where: {
user: {
where: {
date: {between: {min: "2021-01-01", max: "2021-04-01"}}
field: {
user: {
where: {
field: {
date: { between: { min: "2021-01-01", max: "2021-04-01" } }
}
}
}
}
}) {
Expand All @@ -129,12 +133,16 @@ query {

# Relationship: WHERE COUNT (related table) = 2
comments(where: {
user: {
where: {
date: {between: {min: "2021-01-01", max: "2021-04-01"}}
}
count: {
equal: 2
field: {
user: {
where: {
field: {
date: { between: { min: "2021-01-01", max: "2021-04-01"} }
}
}
count: {
equal: 2
}
}
}
}) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/docs/Directives/@stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Query:
query example(
$limit: Int!,
$offset: StreamOffset,
$where: SearchByConditionObject,
$where: SearchByRootObject,
$order: [SortByRootObject!],
) {
objects(where: $where, order: $order, limit: $limit, offset: $offset) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\GraphQL\SearchBy\Definitions;

use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Field;

class SearchByOperatorFieldDirective extends Field {
// Lighthouse loads all classes from directive namespace this leads to
// 'Class "Orchestra\Testbench\TestCase" not found' error for our *Test
// classes. This class required to avoid this error.
}
Loading

0 comments on commit 0b3888f

Please sign in to comment.