1 module graphql.testschema; 2 3 import std.algorithm.iteration : map; 4 import std.datetime : DateTime, Date; 5 import std.typecons : Nullable; 6 import std.format : format; 7 8 import vibe.data.json; 9 import nullablestore; 10 11 import graphql.schema.directives; 12 import graphql.helper; 13 14 import graphql.uda; 15 16 @safe: 17 18 Json datetimeToJson(DateTime dt) { 19 return Json(dt.toISOExtString()); 20 } 21 22 // The Schema used by graphqld 23 24 union SearchResult { 25 Android android; 26 Humanoid humanoid; 27 Starship ship; 28 } 29 30 string dtToString(DateTime dt) { 31 return dt.toISOExtString(); 32 } 33 34 @GQLDUda(TypeKind.OBJECT) 35 struct Query { 36 @GQLDUda( 37 GQLDDescription("Get the captain by Series") 38 ) 39 Character captain(Series series); 40 @GQLDUda( 41 GQLDDeprecated(IsDeprecated.yes, "To complex") 42 ) 43 SearchResult search(string name); 44 Nullable!Starship starship(long id); 45 Starship starshipDoesNotExist(); 46 Starship[] starships(float overSize = 100.0); 47 Starship[] shipsselection(long[] ids); 48 Nullable!Character character(long id); 49 Character[] character(Series series); 50 Humanoid[] humanoids(); 51 Android[] androids(); 52 Android[] resolverWillThrow(); 53 GQLDCustomLeaf!(DateTime, dtToString) currentTime(); 54 int currentTime(); 55 } 56 57 unittest { 58 Query d; 59 } 60 61 @GQLDUda(TypeKind.INPUT_OBJECT) 62 struct AddCrewmanData { 63 string name; 64 long shipId; 65 Series[] series; 66 } 67 68 /*@GQLDUda(TypeKind.INPUT_OBJECT) 69 struct AddCrewmanComplexInput { 70 Character crewman; 71 Starship starship; 72 }*/ 73 74 interface Mutation { 75 Character addCrewman(AddCrewmanData input); 76 //Starship addCrewmanCompley(AddCrewmanComplexInput input); 77 } 78 79 interface Subscription { 80 Starship[] starships(); 81 } 82 83 class Schema { 84 Query queryType; 85 Mutation mutationType; 86 Subscription subscriptionType; 87 DefaultDirectives directives; 88 } 89 90 enum Series { 91 TheOriginalSeries, 92 TheNextGeneration, 93 DeepSpaceNine, 94 Voyager, 95 Enterprise, 96 Discovery 97 } 98 99 @GQLDUda(TypeKind.INTERFACE) 100 abstract class Character { 101 long id; 102 string name; 103 Series[] series; 104 Character[] commands; 105 Nullable!Starship ship; 106 NullableStore!Starship ships; 107 Character[] commanders; 108 Nullable!Starship allwaysNull; 109 Nullable!int alsoAllwaysNull; 110 111 //NullableStore!AddCrewmanData data; 112 } 113 114 abstract class Humanoid : Character { 115 string species; 116 GQLDCustomLeaf!Date dateOfBirth; 117 } 118 119 abstract class Android : Character { 120 string primaryFunction; 121 } 122 123 @GQLDUda( 124 GQLDDescription("The thing Chracters fly around in") 125 ) 126 class Starship { 127 long id; 128 string name; 129 @GQLDUda( 130 GQLDDescription("The name used when speaking about the ship") 131 ) 132 string designation; 133 double size; 134 135 Character commander; 136 Nullable!(Series)[] series; 137 Character[] crew; 138 139 this(long id, string designation, double size, string name) { 140 this.id = id; 141 this.designation = designation; 142 this.size = size; 143 this.name = name; 144 } 145 146 override string toString() const @safe { 147 return format!("Ship(id(%d), designation(%s), size(%.2f), name(%s)" 148 ~ "commander(%s), series[%(%s,%)], crew[%(%s,%)])") 149 ( 150 id, designation, size, name, commander.name, series, 151 crew.map!(a => a.name) 152 ); 153 } 154 }