Skip to content

Commit 4637c25

Browse files
authored
Merge pull request #26 from Linq2GraphQL/support-interfaces
Support interfaces
2 parents e300724 + a3c531b commit 4637c25

29 files changed

Lines changed: 1865 additions & 111 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
4+
using Linq2GraphQL.Client;
5+
6+
namespace StarWars.Client;
7+
8+
public static class IF
9+
{
10+
}
11+
12+

docs/StarWars.Client/Generated/Interfaces/Node.cs

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,96 @@
11
using System;
2-
using System.Collections.Generic;
2+
using System.Text.Json;
3+
using System.Text.Json.Nodes;
34
using System.Text.Json.Serialization;
45
using Linq2GraphQL.Client;
56
using Linq2GraphQL.Client.Converters;
67

78
namespace StarWars.Client;
89

9-
[JsonConverter(typeof(InterfaceConverter<Node__Concrete, Node>))]
10+
public static class NodeExtentions
11+
{
12+
13+
14+
[GraphInterface]
15+
public static Film Film(this Node value)
16+
{
17+
if (value.__TypeName == "Film")
18+
{
19+
return (Film)value;
20+
}
21+
return null;
22+
}
23+
24+
[GraphInterface]
25+
public static Person Person(this Node value)
26+
{
27+
if (value.__TypeName == "Person")
28+
{
29+
return (Person)value;
30+
}
31+
return null;
32+
}
33+
34+
[GraphInterface]
35+
public static Planet Planet(this Node value)
36+
{
37+
if (value.__TypeName == "Planet")
38+
{
39+
return (Planet)value;
40+
}
41+
return null;
42+
}
43+
44+
[GraphInterface]
45+
public static Species Species(this Node value)
46+
{
47+
if (value.__TypeName == "Species")
48+
{
49+
return (Species)value;
50+
}
51+
return null;
52+
}
53+
54+
[GraphInterface]
55+
public static Starship Starship(this Node value)
56+
{
57+
if (value.__TypeName == "Starship")
58+
{
59+
return (Starship)value;
60+
}
61+
return null;
62+
}
63+
64+
[GraphInterface]
65+
public static Vehicle Vehicle(this Node value)
66+
{
67+
if (value.__TypeName == "Vehicle")
68+
{
69+
return (Vehicle)value;
70+
}
71+
return null;
72+
}
73+
}
74+
75+
76+
internal class NodeConverter : InterfaceJsonConverter<Node>
77+
{
78+
public override Node Deserialize(string typeName, JsonObject json) => typeName switch
79+
{
80+
"Film" => json.Deserialize<Film>(),
81+
"Person" => json.Deserialize<Person>(),
82+
"Planet" => json.Deserialize<Planet>(),
83+
"Species" => json.Deserialize<Species>(),
84+
"Starship" => json.Deserialize<Starship>(),
85+
"Vehicle" => json.Deserialize<Vehicle>(),
86+
_ => json.Deserialize< Node__Concrete>()
87+
};
88+
}
89+
90+
91+
92+
93+
[JsonConverter(typeof(NodeConverter))]
1094
public interface Node
1195
{
1296
[JsonPropertyName("id")]

docs/StarWars.Client/Generated/Types/Film.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,35 @@ public partial class Film : Node
6262
/// <summary>
6363
/// Do not use in Query, only to retrive result
6464
/// </summary>
65-
[GraphQLShadowProperty]
65+
[GraphShadowProperty]
6666
[JsonPropertyName("speciesConnection")]
6767
public FilmSpeciesConnection SpeciesConnection { get; set; }
6868

6969
/// <summary>
7070
/// Do not use in Query, only to retrive result
7171
/// </summary>
72-
[GraphQLShadowProperty]
72+
[GraphShadowProperty]
7373
[JsonPropertyName("starshipConnection")]
7474
public FilmStarshipsConnection StarshipConnection { get; set; }
7575

7676
/// <summary>
7777
/// Do not use in Query, only to retrive result
7878
/// </summary>
79-
[GraphQLShadowProperty]
79+
[GraphShadowProperty]
8080
[JsonPropertyName("vehicleConnection")]
8181
public FilmVehiclesConnection VehicleConnection { get; set; }
8282

8383
/// <summary>
8484
/// Do not use in Query, only to retrive result
8585
/// </summary>
86-
[GraphQLShadowProperty]
86+
[GraphShadowProperty]
8787
[JsonPropertyName("characterConnection")]
8888
public FilmCharactersConnection CharacterConnection { get; set; }
8989

9090
/// <summary>
9191
/// Do not use in Query, only to retrive result
9292
/// </summary>
93-
[GraphQLShadowProperty]
93+
[GraphShadowProperty]
9494
[JsonPropertyName("planetConnection")]
9595
public FilmPlanetsConnection PlanetConnection { get; set; }
9696

docs/StarWars.Client/Generated/Types/Person.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public partial class Person : Node
5959
/// <summary>
6060
/// Do not use in Query, only to retrive result
6161
/// </summary>
62-
[GraphQLShadowProperty]
62+
[GraphShadowProperty]
6363
[JsonPropertyName("filmConnection")]
6464
public PersonFilmsConnection FilmConnection { get; set; }
6565

@@ -69,14 +69,14 @@ public partial class Person : Node
6969
/// <summary>
7070
/// Do not use in Query, only to retrive result
7171
/// </summary>
72-
[GraphQLShadowProperty]
72+
[GraphShadowProperty]
7373
[JsonPropertyName("starshipConnection")]
7474
public PersonStarshipsConnection StarshipConnection { get; set; }
7575

7676
/// <summary>
7777
/// Do not use in Query, only to retrive result
7878
/// </summary>
79-
[GraphQLShadowProperty]
79+
[GraphShadowProperty]
8080
[JsonPropertyName("vehicleConnection")]
8181
public PersonVehiclesConnection VehicleConnection { get; set; }
8282

docs/StarWars.Client/Generated/Types/Planet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public partial class Planet : Node
5353
/// <summary>
5454
/// Do not use in Query, only to retrive result
5555
/// </summary>
56-
[GraphQLShadowProperty]
56+
[GraphShadowProperty]
5757
[JsonPropertyName("residentConnection")]
5858
public PlanetResidentsConnection ResidentConnection { get; set; }
5959

6060
/// <summary>
6161
/// Do not use in Query, only to retrive result
6262
/// </summary>
63-
[GraphQLShadowProperty]
63+
[GraphShadowProperty]
6464
[JsonPropertyName("filmConnection")]
6565
public PlanetFilmsConnection FilmConnection { get; set; }
6666

docs/StarWars.Client/Generated/Types/Species.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ public partial class Species : Node
5656
/// <summary>
5757
/// Do not use in Query, only to retrive result
5858
/// </summary>
59-
[GraphQLShadowProperty]
59+
[GraphShadowProperty]
6060
[JsonPropertyName("personConnection")]
6161
public SpeciesPeopleConnection PersonConnection { get; set; }
6262

6363
/// <summary>
6464
/// Do not use in Query, only to retrive result
6565
/// </summary>
66-
[GraphQLShadowProperty]
66+
[GraphShadowProperty]
6767
[JsonPropertyName("filmConnection")]
6868
public SpeciesFilmsConnection FilmConnection { get; set; }
6969

docs/StarWars.Client/Generated/Types/Starship.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public partial class Starship : Node
6565
/// <summary>
6666
/// Do not use in Query, only to retrive result
6767
/// </summary>
68-
[GraphQLShadowProperty]
68+
[GraphShadowProperty]
6969
[JsonPropertyName("pilotConnection")]
7070
public StarshipPilotsConnection PilotConnection { get; set; }
7171

7272
/// <summary>
7373
/// Do not use in Query, only to retrive result
7474
/// </summary>
75-
[GraphQLShadowProperty]
75+
[GraphShadowProperty]
7676
[JsonPropertyName("filmConnection")]
7777
public StarshipFilmsConnection FilmConnection { get; set; }
7878

docs/StarWars.Client/Generated/Types/Vehicle.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public partial class Vehicle : Node
5959
/// <summary>
6060
/// Do not use in Query, only to retrive result
6161
/// </summary>
62-
[GraphQLShadowProperty]
62+
[GraphShadowProperty]
6363
[JsonPropertyName("pilotConnection")]
6464
public VehiclePilotsConnection PilotConnection { get; set; }
6565

6666
/// <summary>
6767
/// Do not use in Query, only to retrive result
6868
/// </summary>
69-
[GraphQLShadowProperty]
69+
[GraphShadowProperty]
7070
[JsonPropertyName("filmConnection")]
7171
public VehicleFilmsConnection FilmConnection { get; set; }
7272

src/Linq2GraphQL.Client/GraphArgumentAttribute.cs renamed to src/Linq2GraphQL.Client/Attributes/GraphArgumentAttribute.cs

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Linq2GraphQL.Client;
2+
3+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
4+
public class GraphInterfaceAttribute : Attribute
5+
{
6+
7+
}

0 commit comments

Comments
 (0)