Skip to content

Commit ec66d44

Browse files
committed
Interface work
1 parent 4b335c1 commit ec66d44

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/Linq2GraphQL.Client/Attributes/GraphInterfacePropertyAttribute.cs renamed to src/Linq2GraphQL.Client/Attributes/GraphInterfaceAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Linq2GraphQL.Client;
22

33
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
4-
public class GraphInterfacePropertyAttribute : Attribute
4+
public class GraphInterfaceAttribute : Attribute
55
{
66

77
}

src/Linq2GraphQL.Client/Converters/InterfaceConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public override void Write(
5656
break;
5757
default:
5858
{
59-
var type = value.GetType();
60-
JsonSerializer.Serialize(writer, value, type, options);
59+
JsonSerializer.Serialize(writer, value, value.GetType(), options);
6160
break;
6261
}
6362
}

src/Linq2GraphQL.Client/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static void ParseExpressionInternal(Expression body, QueryNode parent)
7272

7373
private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpression methodCallExp)
7474
{
75-
var grapInterfaceAttribute = methodCallExp.Method.GetCustomAttribute<GraphInterfacePropertyAttribute>();
75+
var grapInterfaceAttribute = methodCallExp.Method.GetCustomAttribute<GraphInterfaceAttribute>();
7676
if (grapInterfaceAttribute != null)
7777
{
7878
var queryNode = new QueryNode(methodCallExp.Method, methodCallExp.Method.Name, null, true);

test/Linq2GraphQL.TestClient/Generated/Interfaces/IAnimal.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Linq2GraphQL.TestClient;
1111

1212
public static class IAnimalExtentions
1313
{
14-
[GraphInterfaceProperty]
14+
[GraphInterface]
1515
public static Pig Pig(this IAnimal animal)
1616
{
1717
if (animal.__TypeName == "Pig")
@@ -21,7 +21,7 @@ public static Pig Pig(this IAnimal animal)
2121
return null;
2222
}
2323

24-
[GraphInterfaceProperty]
24+
[GraphInterface]
2525
public static Spider Spider(this IAnimal animal)
2626
{
2727
if (animal.__TypeName == "Spider")
@@ -44,8 +44,6 @@ internal class IAnimalConverter : InterfaceJsonConverter<IAnimal>
4444
}
4545

4646

47-
//[JsonConverter(typeof(InterfaceConverter<IAnimal__Concrete, IAnimal>))]
48-
//[JsonConverter(typeof(InterfaceTypeConverter<IAnimal>))]
4947
[JsonConverter(typeof(IAnimalConverter))]
5048
public interface IAnimal
5149
{

test/Linq2GraphQL.Tests/QueryInterfaceTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task Interface_QuerySubClass()
3232
.Query
3333
.Animals()
3434
.Include(e => e.Nodes.Select(e => e.Pig()))
35-
.Include(e => e.Nodes.Select(e => e.Spider()))
35+
//.Include(e => e.Nodes.Select(e => e.Spider()))
3636
.Select(e=> e.Nodes)
3737
;
3838

@@ -45,6 +45,26 @@ public async Task Interface_QuerySubClass()
4545

4646
}
4747

48+
49+
[Fact]
50+
public async Task Interface_Projection()
51+
{
52+
var query = sampleClient
53+
.Query
54+
.Animals()
55+
.Include(e => e.Nodes.Select(e => e.Pig()))
56+
.Include(e => e.Nodes.Select(e => e.Spider()))
57+
.Select(e => e.Nodes.Select(f => new { Pig = f.Pig(), Spider = f.Spider() }));
58+
59+
60+
var request = await query.GetRequestAsync();
61+
var result = await query.ExecuteAsync();
62+
63+
var baseType = query.BaseResult;
64+
Assert.NotNull(result);
65+
66+
}
67+
4868
}
4969

5070
}

0 commit comments

Comments
 (0)