Skip to content

Commit

Permalink
feat(graphql/@searchBy): @searchByIgnored can be placed on `OBJEC…
Browse files Browse the repository at this point in the history
…T`, `INPUT_OBJECT`, `ENUM`, `SCALAR`.
  • Loading branch information
LastDragon-ru committed Dec 24, 2022
1 parent df48aac commit 6120f65
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use LastDragon_ru\LaraASP\GraphQL\Package;
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\BaseOperator;
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Comparison\Between;
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators\Comparison\Equal;
use LastDragon_ru\LaraASP\GraphQL\Testing\GraphQLExpectedSchema;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\BuilderDataProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider;
Expand Down Expand Up @@ -347,10 +348,19 @@ static function (self $test): GraphQLExpectedSchema {
'NestedB',
'NestedC',
'InputB',
'InputIgnored',
]);
},
'~full.graphql',
null,
static function (TestCase $test): void {
$package = Package::Name;

config([
"{$package}.search_by.operators.Date" => [
Equal::class,
],
]);
},
],
'example' => [
static function (self $test): GraphQLExpectedSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ enum EnumA {
two
}

enum EnumIgnored
@searchByIgnored
{
one
}

enum SearchByTypeFlag {
yes
}
Expand Down Expand Up @@ -151,6 +157,24 @@ input SearchByConditionInputA {
booleanScalarNotNull: SearchByScalarBoolean
@searchByOperatorProperty

"""
Property condition.
"""
customScalar: SearchByScalarDateOrNull
@searchByOperatorProperty

"""
Property condition.
"""
customScalarList: SearchByScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
customScalarNonNull: SearchByScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
Expand Down Expand Up @@ -380,6 +404,24 @@ input SearchByConditionObject {
booleanScalarNotNull: SearchByScalarBoolean
@searchByOperatorProperty

"""
Property condition.
"""
customScalar: SearchByScalarDateOrNull
@searchByOperatorProperty

"""
Property condition.
"""
customScalarList: SearchByScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
customScalarNonNull: SearchByScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
Expand Down Expand Up @@ -610,6 +652,40 @@ input SearchByScalarBooleanOrNull {
@searchByOperatorNotEqual
}

"""
Available operators for `scalar Date!` (only one operator allowed at a time).
"""
input SearchByScalarDate {
"""
Equal (`=`).
"""
equal: Date
@searchByOperatorEqual
}

"""
Available operators for `scalar Date` (only one operator allowed at a time).
"""
input SearchByScalarDateOrNull {
"""
Equal (`=`).
"""
equal: Date
@searchByOperatorEqual

"""
Is NOT NULL?
"""
isNotNull: SearchByTypeFlag
@searchByOperatorIsNotNull

"""
Is NULL?
"""
isNull: SearchByTypeFlag
@searchByOperatorIsNull
}

"""
Available operators for `scalar Float!` (only one operator allowed at a time).
"""
Expand Down Expand Up @@ -1176,6 +1252,24 @@ input SearchByScoutConditionInputA {
booleanScalarNotNull: SearchByScoutScalarBoolean
@searchByOperatorProperty

"""
Property condition.
"""
customScalar: SearchByScoutScalarDateOrNull
@searchByOperatorProperty

"""
Property condition.
"""
customScalarList: SearchByScoutScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
customScalarNonNull: SearchByScoutScalarDate
@searchByOperatorProperty

"""
Property condition.
"""
Expand Down Expand Up @@ -1328,6 +1422,28 @@ input SearchByScoutScalarBooleanOrNull {
@searchByOperatorEqual
}

"""
Available operators for `scalar Date!` (only one operator allowed at a time).
"""
input SearchByScoutScalarDate {
"""
Equal (`=`).
"""
equal: Date
@searchByOperatorEqual
}

"""
Available operators for `scalar Date` (only one operator allowed at a time).
"""
input SearchByScoutScalarDateOrNull {
"""
Equal (`=`).
"""
equal: Date
@searchByOperatorEqual
}

"""
Available operators for `scalar Float!` (only one operator allowed at a time).
"""
Expand Down Expand Up @@ -1495,10 +1611,29 @@ interface C {
): ID!
}

scalar Date
@scalar(
class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date"
)

scalar DateIgnored
@scalar(
class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date"
)
@searchByIgnored

type Object {
booleanScalar: Boolean
booleanScalarNotNull: Boolean!
customScalar: Date
customScalarIgnored: DateIgnored
customScalarIgnoredList: [DateIgnored!]!
customScalarIgnoredNonNull: DateIgnored!
customScalarList: [Date!]!
customScalarNonNull: Date!
enum: EnumA
enumEnumIgnoredNotNull: EnumIgnored!
enumIgnored: EnumIgnored
enumNotNull: EnumA!
floatScalar: Float
floatScalarNotNull: Float!
Expand All @@ -1508,6 +1643,9 @@ type Object {
ignored: String
@searchByIgnored

ignoredType: ObjectIgnored
ignoredTypeList: [ObjectIgnored!]!
ignoredTypeNonNull: ObjectIgnored!
inScalarNotNull: Int!
intScalar: Int
nested: ObjectNested
Expand All @@ -1525,6 +1663,12 @@ type Object {
unionNonNull: ObjectUnion!
}

type ObjectIgnored
@searchByIgnored
{
value: String
}

type ObjectNested {
nested: ObjectNested
value: String
Expand Down Expand Up @@ -1591,8 +1735,12 @@ Marks that field should be excluded from search.
"""
directive @searchByIgnored
on
| ENUM
| FIELD_DEFINITION
| INPUT_FIELD_DEFINITION
| INPUT_OBJECT
| OBJECT
| SCALAR

directive @searchByOperatorAllOf
on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ input InputA {
nestedNotNull: NestedA!
enum: EnumA
enumNotNull: EnumA!
enumIgnored: EnumIgnored
enumEnumIgnoredNotNull: EnumIgnored!
ignored: String @searchByIgnored
resolver: Float @field(
resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\DirectiveTest__Resolver"
)
ignoredType: InputIgnored
ignoredTypeList: [InputIgnored!]!
ignoredTypeNonNull: InputIgnored!
customScalar: Date
customScalarList: [Date!]!
customScalarNonNull: Date!
customScalarIgnored: DateIgnored
customScalarIgnoredList: [DateIgnored!]!
customScalarIgnoredNonNull: DateIgnored!
}

input NestedA {
Expand All @@ -62,11 +73,26 @@ input InputB {
id: ID
}

input InputIgnored @searchByIgnored {
id: ID
}

scalar Date
@scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")

scalar DateIgnored
@scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")
@searchByIgnored

enum EnumA {
one
two
}

enum EnumIgnored @searchByIgnored {
one
}

type Object {
idScalar: ID
idScalarNotNull: ID!
Expand All @@ -82,13 +108,24 @@ type Object {
nestedNotNull: ObjectNested!
enum: EnumA
enumNotNull: EnumA!
enumIgnored: EnumIgnored
enumEnumIgnoredNotNull: EnumIgnored!
ignored: String @searchByIgnored
resolver: Float @field(
resolver: "\\LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\DirectiveTest__Resolver"
)
union: ObjectUnion
unionList: [ObjectUnion!]!
unionNonNull: ObjectUnion!
ignoredType: ObjectIgnored
ignoredTypeList: [ObjectIgnored!]!
ignoredTypeNonNull: ObjectIgnored!
customScalar: Date
customScalarList: [Date!]!
customScalarNonNull: Date!
customScalarIgnored: DateIgnored
customScalarIgnoredList: [DateIgnored!]!
customScalarIgnoredNonNull: DateIgnored!
}

type ObjectNested {
Expand All @@ -97,3 +134,7 @@ type ObjectNested {
}

union ObjectUnion = Object | ObjectNested

type ObjectIgnored @searchByIgnored {
value: String
}
8 changes: 7 additions & 1 deletion packages/graphql/src/SearchBy/Directives/Ignored.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ public static function definition(): string {
"""
Marks that field should be excluded from search.
"""
directive @searchByIgnored on FIELD_DEFINITION | INPUT_FIELD_DEFINITION,
directive @searchByIgnored on
| FIELD_DEFINITION
| INPUT_FIELD_DEFINITION
| OBJECT
| INPUT_OBJECT
| ENUM
| SCALAR
GRAPHQL;
}
}

0 comments on commit 6120f65

Please sign in to comment.