Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for generic ID Attribute #7086

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public override void OnBeforeRegisterDependencies(
foreach (var field in def.Fields)
{
if (field is FilterFieldDefinition filterField &&
filterField.Member?.GetCustomAttribute(typeof(IDAttribute)) != null)
filterField.Member is { } member &&
(member.GetCustomAttribute(typeof(IDAttribute)) is { } ||
member.GetCustomAttribute(typeof(IDAttribute<>)) is { }))
{
filterField.Type = discoveryContext.TypeInspector.GetTypeRef(
typeof(IdOperationFilterInputType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public async Task Filtering_Should_InfereType_When_Annotated()
schema.MatchSnapshot();
}

[Fact]
public async Task Filtering_Should_InfereType_When_AnnotatedGeneric()
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
{
var schema = await new ServiceCollection()
.AddGraphQL()
.AddQueryType(x => x.Name("Query").Field("test").Resolve("a"))
.AddType(new FilterInputType<FooIdGeneric>())
.AddFiltering()
.BuildSchemaAsync();

schema.MatchSnapshot();
}

public class Foo
{
public string? Bar { get; }
Expand All @@ -46,4 +59,10 @@ public class FooId
[ID]
public string? Bar { get; }
}

public class FooIdGeneric
{
[ID<Foo>]
public string? Bar { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
schema {
query: Query
}

type Query {
test: String
}

input FooIdGenericFilterInput {
and: [FooIdGenericFilterInput!]
or: [FooIdGenericFilterInput!]
bar: IdOperationFilterInput
}

input IdOperationFilterInput {
eq: ID
neq: ID
in: [ID]
nin: [ID]
}
Loading