Skip to content

Commit

Permalink
a lot more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schadek authored and burner committed Apr 4, 2019
1 parent 2917e8d commit 17bde31
Showing 6 changed files with 345 additions and 52 deletions.
4 changes: 2 additions & 2 deletions source/graphql/schema/types.d
Original file line number Diff line number Diff line change
@@ -475,8 +475,8 @@ class GQLDSchema(Type) : GQLDMap {
} else if(field in map.member) {
ret = map.member[field];
} else if(field == "__typename") {
assert(false, format("%s %s", field, t.toString()));
//ret = this.types["string"];
// the type of the field __typename is always a string
ret = this.types["string"];
} else {
// if we couldn't find it in the passed map, maybe it is in some
// of its derivatives
1 change: 1 addition & 0 deletions source/graphql/uda.d
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ enum IsDeprecated {
struct GQLDCustomLeaf(T) {
alias Type = T;
Type value;
alias value this;
}

unittest {
2 changes: 1 addition & 1 deletion test/dub.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"burner"
],
"copyright": "Copyright © 2019, burner",
"dflags" : ["-v"],
"dflags" : ["-v", "-cov"],
"dependencies": {
"vibe-d": "~>0.8.2",
"vibe-d:tls": "~>0.8.2",
47 changes: 41 additions & 6 deletions test/source/app.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import core.time : seconds;
import std.array;
import std.stdio;
import std.traits;
@@ -96,18 +97,21 @@ void main() {
ref CustomContext con) @trusted
{
logf("args %s", args);
assert("shipId" in args);
long shipId = args["shipId"].get!long();
assert("name" in args);
string nname = args["name"].get!string();
logf("%s %s", shipId, nname);
long shipId;
bool ok = hasPathTo(args, "input.shipId", shipId);
writefln("%s %s", ok, shipId);
string nname;
ok = hasPathTo(args, "input.name", nname);
writefln("%s %s", ok, nname);
logf("%s %s %s", shipId, nname);

Json ret;

auto theShip = database.ships.find!(s => shipId == s.id);
if(!theShip.empty) {
Starship ship = theShip.front;
auto nh = new HumanoidImpl(database.i++, nname, "Human");
auto nh = new HumanoidImpl(database.i++, nname, "Human",
Date(1986, 7, 2));
ship.crew ~= nh;
nh.ship = nullable(ship);
ret = characterToJson(nh);
@@ -207,7 +211,33 @@ void main() {
listenHTTP(settings, &hello);

logInfo("Please open http://127.0.0.1:8080/ in your browser.");
Task t = runTask({
import std.exception : enforce;
import testqueries;
foreach(q; queries) {
sleep(1.seconds);
Task qt = runTask({
requestHTTP("http://127.0.0.1:8080",
(scope req) {
req.method = HTTPMethod.POST;
Json b = Json.emptyObject();
b["query"] = Json(q);
req.writeJsonBody(b);
},
(scope res) {
Json ret = parseJsonString(
res.bodyReader.readAllUTF8()
);
enforce("error" in ret && ret["error"].length == 0);
enforce("data" in ret && ret["data"].length != 0);
}
);
});
qt.join();
}
});
runApplication();
t.join();
}

void hello(HTTPServerRequest req, HTTPServerResponse res) {
@@ -247,7 +277,12 @@ void hello(HTTPServerRequest req, HTTPServerResponse res) {

Document d;
try {
import graphql.validation.querybased;
d = p.parseDocument();
StaticValidator fv = new StaticValidator(d);
fv.accept(d);
noCylces(fv.fragmentChildren);
allFragmentsReached(fv);
} catch(Throwable e) {
auto app = appender!string();
while(e) {
97 changes: 54 additions & 43 deletions test/source/testdata.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module testdata;

import std.stdio;
import std.datetime : DateTime;
import std.datetime : DateTime, Date;
import std.conv : to;
import std.array : array, back;
import std.format : format;
@@ -103,6 +103,7 @@ abstract class Character {

abstract class Humanoid : Character {
string species;
GQLDCustomLeaf!Date dateOfBirth;
}

abstract class Android : Character {
@@ -178,6 +179,7 @@ Json characterToJson(Character c) {
if(Humanoid h = cast(Humanoid)c) {
ret["data"]["species"] = h.species;
ret["data"]["__typename"] = "Humanoid";
ret["data"]["dateOfBirth"] = Json(h.dateOfBirth.toISOExtString());
}

if(Android a = cast(Android)c) {
@@ -197,10 +199,11 @@ class CharacterImpl : Character {
}

class HumanoidImpl : Humanoid {
this(long id, string name, string species) {
this(long id, string name, string species, Date dob) {
this.id = id;
this.name = name;
this.species = species;
this.dateOfBirth = dob;
}

override string toString() const @safe {
@@ -264,17 +267,19 @@ class Data {
long i;

this() @trusted {
auto picard = new HumanoidImpl(i++, "Jean-Luc Picard", "Human");
auto worf = new HumanoidImpl(i++, "Worf", "Klingon");
auto picard = new HumanoidImpl(i++, "Jean-Luc Picard", "Human",
Date(2305, 7, 13));
auto worf = new HumanoidImpl(i++, "Worf", "Klingon", Date(2340, 5, 23));
picard.series ~= Series.TheNextGeneration;
auto tng = [
new HumanoidImpl(i++, "William Riker", "Human"),
new HumanoidImpl(i++, "Deanna Troi", "Betazoid "),
new HumanoidImpl(i++, "Dr. Beverly Crusher", "Human"),
new HumanoidImpl(i++, "William Riker", "Human", Date(2335, 8, 19)),
new HumanoidImpl(i++, "Deanna Troi", "Betazoid", Date(2336, 3, 29)),
new HumanoidImpl(i++, "Dr. Beverly Crusher", "Human",
Date(2324, 10, 13)),
worf,
new AndroidImpl(i++, "Data", "Becoming Human"),
new HumanoidImpl(i++, "Geordi La Forge", "Human"),
new HumanoidImpl(i++, "Miles O'Brien", "Human")
new HumanoidImpl(i++, "Geordi La Forge", "Human", Date(2335, 2, 16)),
new HumanoidImpl(i++, "Miles O'Brien", "Human", Date(2328, 9, 1))
];
picard.commands = tng;
picard.series ~= Series.DeepSpaceNine;
@@ -286,68 +291,74 @@ class Data {
tng[3].series ~= Series.DeepSpaceNine;
tng[6].series ~= Series.DeepSpaceNine;

auto sisko = new HumanoidImpl(i++, "Benjamin Sisko", "Human");
auto sisko = new HumanoidImpl(i++, "Benjamin Sisko", "Human",
Date(2332, 1, 1));
sisko.series ~= Series.DeepSpaceNine;
auto ds9 = [
new HumanoidImpl(i++, "Odo", "Changeling"),
new HumanoidImpl(i++, "Jadzia Dax", "Trill"),
new HumanoidImpl(i++, "Dr. Julian Bashir", "Human"),
new HumanoidImpl(i++, "Odo", "Changeling", Date(1970, 1, 1)),
new HumanoidImpl(i++, "Jadzia Dax", "Trill", Date(2346, 8, 20)),
new HumanoidImpl(i++, "Dr. Julian Bashir", "Human", Date(2341, 1, 1)),
worf,
new HumanoidImpl(i++, "Kira Nerys", "Bajoran"),
new HumanoidImpl(i++, "Elim Garak", "Cardassian")
new HumanoidImpl(i++, "Kira Nerys", "Bajoran", Date(2343, 1, 1)),
new HumanoidImpl(i++, "Elim Garak", "Cardassian", Date(2320, 1, 1))
];
sisko.commands = cast(Character[])ds9;
ds9.map!(a => a.series ~= Series.DeepSpaceNine).each;
ds9.map!(a => a.commanders ~= sisko).each;

tng[6].commanders ~= sisko;

auto janeway = new HumanoidImpl(i++, "Kathryn Janeway", "Human");
auto janeway = new HumanoidImpl(i++, "Kathryn Janeway", "Human",
Date(2330, 5, 20));
auto voyager = [
new HumanoidImpl(i++, "Chakotay", "Human"),
new HumanoidImpl(i++, "Tuvok", "Vulcan"),
new HumanoidImpl(i++, "Neelix", "Talaxian"),
new HumanoidImpl(i++, "Seven of Nine", "Human"),
new HumanoidImpl(i++, "B'Elanna Torres", "Klingon"),
new HumanoidImpl(i++, "Tom Paris", "Human"),
new HumanoidImpl(i++, "Harry Kim", "Human"),
new HumanoidImpl(i++, "Chakotay", "Human", Date(2329, 1, 1)),
new HumanoidImpl(i++, "Tuvok", "Vulcan", Date(2361, 10, 10)),
new HumanoidImpl(i++, "Neelix", "Talaxian", Date(2340, 1, 1)),
new HumanoidImpl(i++, "Seven of Nine", "Human", Date(2348, 6, 24)),
new HumanoidImpl(i++, "B'Elanna Torres", "Klingon", Date(2349, 2, 1)),
new HumanoidImpl(i++, "Tom Paris", "Human", Date(2346, 2, 1)),
new HumanoidImpl(i++, "Harry Kim", "Human", Date(2349, 2, 1)),
];
janeway.commands = cast(Character[])voyager;
voyager.map!(a => a.series ~= Series.Voyager).each;
voyager.map!(a => a.commanders ~= janeway).each;

auto archer = new HumanoidImpl(i++, "Jonathan Archer", "Human");
auto archer = new HumanoidImpl(i++, "Jonathan Archer", "Human",
Date(2112, 10, 9));
auto enterprise = [
new HumanoidImpl(i++, "Charles Tucer III", "Human"),
new HumanoidImpl(i++, "Hoshi Sato", "Human"),
new HumanoidImpl(i++, "Dr. Phlox", "Denobulan"),
new HumanoidImpl(i++, "Malcolm Reed", "Human"),
new HumanoidImpl(i++, "Travis Mayweather", "Human"),
new HumanoidImpl(i++, "T'Pol", "Vulcan")
new HumanoidImpl(i++, "Charles Tucker III", "Human", Date(2121, 2,
1)),
new HumanoidImpl(i++, "Hoshi Sato", "Human", Date(2129, 7, 9)),
new HumanoidImpl(i++, "Dr. Phlox", "Denobulan", Date(2080, 2, 1)),
new HumanoidImpl(i++, "Malcolm Reed", "Human", Date(2117, 9, 2)),
new HumanoidImpl(i++, "Travis Mayweather", "Human", Date(2121, 2, 1)),
new HumanoidImpl(i++, "T'Pol", "Vulcan", Date(2088, 2, 1))
];
archer.commands = cast(Character[])enterprise;
enterprise.map!(a => a.series ~= Series.Enterprise).each;

auto kirk = new HumanoidImpl(i++, "James T. Kirk", "Human");
auto kirk = new HumanoidImpl(i++, "James T. Kirk", "Human",
Date(2202, 2, 1));
auto tos = [
new HumanoidImpl(i++, "Hikaru Sulu", "Human"),
new HumanoidImpl(i++, "Uhura", "Human"),
new HumanoidImpl(i++, "Montgomery Scott", "Human"),
new HumanoidImpl(i++, "Dr. Leonard McCoy", "Human"),
new HumanoidImpl(i++, "Spock", "Vulcan"),
new HumanoidImpl(i++, "Hikaru Sulu", "Human", Date(2237, 2, 1)),
new HumanoidImpl(i++, "Uhura", "Human", Date(2239, 2, 1)),
new HumanoidImpl(i++, "Montgomery Scott", "Human", Date(2222, 2, 1)),
new HumanoidImpl(i++, "Dr. Leonard McCoy", "Human", Date(2227, 2, 1)),
new HumanoidImpl(i++, "Spock", "Vulcan", Date(2230, 2, 1)),
];
kirk.commands = cast(Character[])tos;
tos.map!(a => a.series ~= Series.TheOriginalSeries).each;
tos.map!(a => a.commanders ~= kirk).each;

auto georgiou = new HumanoidImpl(i++, "Philippa Georgiou", "Human");
auto georgiou = new HumanoidImpl(i++, "Philippa Georgiou", "Human",
Date(2202, 2, 1));
auto discovery = [
new HumanoidImpl(i++, "Michael Burnham", "Human"),
new HumanoidImpl(i++, "Paum Stamets", "Human"),
new HumanoidImpl(i++, "Sylvia Tilly", "Human"),
new HumanoidImpl(i++, "Ash Tyler", "Klingon"),
new HumanoidImpl(i++, "Saru", "Kelpien"),
new HumanoidImpl(i++, "Hugh Culber", "Human"),
new HumanoidImpl(i++, "Michael Burnham", "Human", Date(2226, 2, 1)),
new HumanoidImpl(i++, "Paul Stamets", "Human", Date(2225, 2, 1)),
new HumanoidImpl(i++, "Sylvia Tilly", "Human", Date(2230, 2, 1)),
new HumanoidImpl(i++, "Ash Tyler", "Klingon", Date(2230, 2, 1)),
new HumanoidImpl(i++, "Saru", "Kelpien", Date(2230, 2, 1)),
new HumanoidImpl(i++, "Hugh Culber", "Human", Date(2227, 2, 1)),
];
georgiou.commands = cast(Character[])discovery;
discovery.map!(a => a.series ~= Series.Discovery).each;
Loading

0 comments on commit 17bde31

Please sign in to comment.