1 module graphql.starwars.types;
2 
3 import std.typecons : Nullable, nullable;
4 
5 import nullablestore;
6 
7 import graphql.uda;
8 
9 @safe:
10 
11 @GQLDUda(
12 	GQLDDescription("One of the films in the Star Wars Trilogy")
13 )
14 enum Episode {
15 	NEWHOPE = 4,
16 	EMPIRE = 5,
17 	JEDI = 6
18 }
19 
20 @GQLDUda(
21 	GQLDDescription("A character in the Star Wars Trilogy"),
22 	TypeKind.INTERFACE
23 )
24 abstract class Character {
25 	@GQLDUda(GQLDDescription("The id of the character"))
26 	string id;
27 
28 	@GQLDUda(GQLDDescription("The name of the character"))
29 	Nullable!string name;
30 
31 	@GQLDUda(
32 		GQLDDescription("The friends of the character, or an empty list if "
33 			~ "they have none."
34 		)
35 	)
36 	NullableStore!(Nullable!(Nullable!(Character)[])) friends;
37 
38 	@GQLDUda(Ignore.yes)
39 	string[] friendsId;
40 
41 	@GQLDUda(GQLDDescription("Which movies they appear in."))
42 	Nullable!(Nullable!(Episode)[]) appearsIn;
43 
44 	@GQLDUda(
45 		GQLDDescription("Where are they from and how they came to be who they "
46 			~ " are.")
47 	)
48 	Nullable!string secretBackstory;
49 
50 	this(string id, string name, string[] friends, int[] appearsIn) {
51 		import std.array : array;
52 		import std.algorithm.iteration : map;
53 		this.id = id;
54 		this.name = name;
55 		this.friendsId = friends;
56 		this.appearsIn = appearsIn.map!(e => nullable(cast(Episode)e)).array;
57 	}
58 }
59 
60 class Human : Character {
61 	@GQLDUda(
62 		GQLDDescription("The home planet of the human, or null if unknown.")
63 	)
64 	string homePlanet;
65 
66 	this(string id, string name, string[] friends, int[] appearsIn,
67 			string homePlanet)
68 	{
69 		super(id, name, friends, appearsIn);
70 		this.homePlanet = homePlanet;
71 	}
72 }
73 
74 @GQLDUda(
75 	GQLDDescription("A mechanical creature in the Star Wars universe.")
76 )
77 class Droid : Character{
78 	@GQLDUda(
79 		GQLDDescription("The primary function of the droid.")
80 	)
81 	Nullable!string primaryFunction;
82 
83 	this(string id, string name, string[] friends, int[] appearsIn,
84 			string primaryFunction)
85 	{
86 		super(id, name, friends, appearsIn);
87 		this.primaryFunction = nullable(primaryFunction);
88 	}
89 }