Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added attributes for filtering and sorting (#2453)
Co-authored-by: Michael Staib <michael@chillicream.com>
- Loading branch information
1 parent
b8b4b0b
commit 00b1234
Showing
12 changed files
with
382 additions
and
3 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
32 changes: 32 additions & 0 deletions
32
src/HotChocolate/Data/src/Data/Filters/Attributes/FilterFieldDescriptorAttribute.cs
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,32 @@ | ||
using System; | ||
using System.Reflection; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
namespace HotChocolate.Data.Filters | ||
{ | ||
[AttributeUsage( | ||
AttributeTargets.Property | AttributeTargets.Method, | ||
Inherited = true, | ||
AllowMultiple = true)] | ||
public abstract class FilterFieldDescriptorAttribute | ||
: DescriptorAttribute | ||
{ | ||
protected sealed override void TryConfigure( | ||
IDescriptorContext context, | ||
IDescriptor descriptor, | ||
ICustomAttributeProvider element) | ||
{ | ||
if (descriptor is IFilterFieldDescriptor d && | ||
element is MemberInfo m) | ||
{ | ||
OnConfigure(context, d, m); | ||
} | ||
} | ||
|
||
public abstract void OnConfigure( | ||
IDescriptorContext context, | ||
IFilterFieldDescriptor descriptor, | ||
MemberInfo member); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/HotChocolate/Data/src/Data/Filters/Attributes/FilterInputTypeDescriptorAttribute.cs
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,32 @@ | ||
using System; | ||
using System.Reflection; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
namespace HotChocolate.Data.Filters | ||
{ | ||
[AttributeUsage( | ||
AttributeTargets.Class | AttributeTargets.Struct, | ||
Inherited = true, | ||
AllowMultiple = true)] | ||
public abstract class FilterInputTypeDescriptorAttribute | ||
: DescriptorAttribute | ||
{ | ||
protected sealed override void TryConfigure( | ||
IDescriptorContext context, | ||
IDescriptor descriptor, | ||
ICustomAttributeProvider element) | ||
{ | ||
if (descriptor is IFilterInputTypeDescriptor d && | ||
element is Type t) | ||
{ | ||
OnConfigure(context, d, t); | ||
} | ||
} | ||
|
||
public abstract void OnConfigure( | ||
IDescriptorContext context, | ||
IFilterInputTypeDescriptor descriptor, | ||
Type type); | ||
} | ||
} |
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
src/HotChocolate/Data/src/Data/Sorting/Attributes/SortFieldDescriptorAttribute.cs
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,32 @@ | ||
using System; | ||
using System.Reflection; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
namespace HotChocolate.Data.Sorting | ||
{ | ||
[AttributeUsage( | ||
AttributeTargets.Property | AttributeTargets.Method, | ||
Inherited = true, | ||
AllowMultiple = true)] | ||
public abstract class SortFieldDescriptorAttribute | ||
: DescriptorAttribute | ||
{ | ||
protected sealed override void TryConfigure( | ||
IDescriptorContext context, | ||
IDescriptor descriptor, | ||
ICustomAttributeProvider element) | ||
{ | ||
if (descriptor is ISortFieldDescriptor d && | ||
element is MemberInfo m) | ||
{ | ||
OnConfigure(context, d, m); | ||
} | ||
} | ||
|
||
public abstract void OnConfigure( | ||
IDescriptorContext context, | ||
ISortFieldDescriptor descriptor, | ||
MemberInfo member); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/HotChocolate/Data/src/Data/Sorting/Attributes/SortInputTypeDescriptorAttribute.cs
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,32 @@ | ||
using System; | ||
using System.Reflection; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
namespace HotChocolate.Data.Sorting | ||
{ | ||
[AttributeUsage( | ||
AttributeTargets.Class | AttributeTargets.Struct, | ||
Inherited = true, | ||
AllowMultiple = true)] | ||
public abstract class SortInputTypeDescriptorAttribute | ||
: DescriptorAttribute | ||
{ | ||
protected sealed override void TryConfigure( | ||
IDescriptorContext context, | ||
IDescriptor descriptor, | ||
ICustomAttributeProvider element) | ||
{ | ||
if (descriptor is ISortInputTypeDescriptor d && | ||
element is Type t) | ||
{ | ||
OnConfigure(context, d, t); | ||
} | ||
} | ||
|
||
public abstract void OnConfigure( | ||
IDescriptorContext context, | ||
ISortInputTypeDescriptor descriptor, | ||
Type type); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...Filters.Tests/__snapshots__/FilterAttributeTests.Create_Schema_With_FilterAttributes.snap
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,39 @@ | ||
schema { | ||
query: Query4 | ||
} | ||
|
||
type Bar { | ||
baz: Long! | ||
shouldNotBeVisible: Int | ||
} | ||
|
||
type Query4 { | ||
bars(where: ItWorks): [Bar!]! | ||
} | ||
|
||
input ComparableOperationFilterInputOfInt64FilterInput { | ||
eq: Long | ||
neq: Long | ||
in: [Long!] | ||
nin: [Long!] | ||
gt: Long | ||
ngt: Long | ||
gte: Long | ||
ngte: Long | ||
lt: Long | ||
nlt: Long | ||
lte: Long | ||
nlte: Long | ||
} | ||
|
||
input ItWorks { | ||
and: [ItWorks!] | ||
or: [ItWorks!] | ||
baz: ComparableOperationFilterInputOfInt64FilterInput | ||
} | ||
|
||
"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1." | ||
scalar Int | ||
|
||
"The `Long` scalar type represents non-fractional signed whole 64-bit numeric values. Long can represent values between -(2^63) and 2^63 - 1." | ||
scalar Long |
Oops, something went wrong.