Skip to content

Commit

Permalink
Adds support for generic ID Attribute (#7086)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored May 6, 2024
1 parent 4f56e59 commit b765e1f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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_InferType_When_AnnotatedGeneric()
{
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]
}

0 comments on commit b765e1f

Please sign in to comment.