Skip to content

Commit

Permalink
it works!? it actually does
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Aug 4, 2023
1 parent fadd394 commit 540d0a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
52 changes: 30 additions & 22 deletions source/graphql/graphql.d
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,17 @@ class GraphQLD(T, QContext = DefaultContext) {
);
if(tmp.type == Json.Type.object) {
if("data" in tmp) {
writefln("toRun before %s %s", ret, tmp);
insertPayload(ret, tmp);
writefln("toRun after %s", ret);
//ret["data"] = tmp["data"];
}
//foreach(err; tmp[Constants.errors]) {
// ret[Constants.errors] = err;
//}
foreach(err; tmp[Constants.errors]) {
ret[Constants.errors] = err;
}
} else if(!tmp.dataIsEmpty() && tmp.isScalar()) {
ret["data"] = tmp;
insertPayload(ret, tmp);
//ret["data"] = tmp;
}
}

Expand All @@ -474,11 +477,14 @@ class GraphQLD(T, QContext = DefaultContext) {
Json tmp = this.executeSelectionSet(ss, elemType, t, variables,
doc, context, ec
);
/*
tmp = tmp.type == Json.Type.object && "data" in tmp
? tmp["data"]
: tmp;
writefln("join %s\n%s", tmp.toPrettyString(), ret.toPrettyString());
if(tmp.type == Json.Type.object) {
*/

writefln("join tmp %s\n ret %s", tmp.toPrettyString(), ret.toPrettyString());
/*if(tmp.type == Json.Type.object) {
if("data" in tmp) {
ret["data"][fieldName] = tmp["data"];
//insertPayload(ret["data"], fieldName, tmp["data"]);
Expand All @@ -489,17 +495,19 @@ class GraphQLD(T, QContext = DefaultContext) {
//}
} else if(!tmp.dataIsEmpty() && tmp.isScalar()) {
ret["data"][fieldName] = tmp;
}
//writefln("%s\n%s", elemType, item.toPrettyString());
/*
}*/
elemType = elemType.unpackNonList();
writefln("elemType %s", elemType);
if(GQLDList l = elemType.toList()) {
enforce(item.type == Json.Type.array, "Expected Array got "
~ item.toPrettyString());
foreach(it; item) {
Json tmp = this.executeSelectionSet(ss, l.elementType, it, variables,
doc, context, ec
);
insertPayload(ret, fieldName, tmp);
enforce(tmp.type == Json.Type.object, "Expected Object got "
~ tmp.toPrettyString());
writefln("before %s %s", ret, tmp);
insertPayload(ret, fieldName, tmp);
writefln("after %s", ret);
/*
foreach(it; "data" in tmp ? tmp["data"] : tmp) {
insertPayload(ret, fieldName, it);
writefln("after %s", ret);
//if("data" in tmp) {
// ret["data"] ~= tmp["data"];
//}
Expand All @@ -508,19 +516,18 @@ class GraphQLD(T, QContext = DefaultContext) {
// //ret[Constants.errors] ~= err;
//}
}
*/
} else {
Json tmp = this.executeSelectionSet(ss, elemType, item, variables,
doc, context, ec
);
writefln("o before %s %s", ret, tmp);
insertPayload(ret, fieldName, tmp);
writefln("o after %s", ret);
//if("data" in tmp) {
// ret["data"] ~= tmp["data"];
//}
//foreach(err; tmp[Constants.errors]) {
// ret[Constants.errors] ~= err;
//}
}
*/
}

Json executeList(SelectionSet ss, GQLDList objectType,
Expand Down Expand Up @@ -622,7 +629,7 @@ class GraphQLD(T, QContext = DefaultContext) {
}
}
writefln("already handled %s", fieldsHandledByArrayResolver);
writeln(Json(results).toPrettyString());
writefln("after ArrayResolver %s", Json(results).toPrettyString());

if(this.options.asyncList == AsyncList.yes) {
Task[] tasks;
Expand Down Expand Up @@ -660,12 +667,13 @@ class GraphQLD(T, QContext = DefaultContext) {
}
}
foreach(idx, ref it; results) {
writefln("%s %s", idx, it.toPrettyString());
writefln("final join %s %s", idx, it.toPrettyString());
ret["data"] ~= it["data"];
if(it["errors"].length > 0) {
ret["errors"] ~= it["errors"];
}
}
writefln("return %s", ret.toPrettyString());
return ret;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/graphql/helper.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void insertPayload(ref Json result, Json data) @trusted {
result[d] = Json.emptyObject();
}
enforce(result[d].type == Json.Type.object);
foreach(string key, ref Json value; data) {
foreach(string key, ref Json value; data[d]) {
Json* df = key in result[d];
if(df) {
result[d][key] = joinJson(*df, value);
Expand Down

0 comments on commit 540d0a2

Please sign in to comment.