Skip to content

Commit

Permalink
Fix #47 and vibe upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Aug 10, 2020
1 parent 1a07ea3 commit bf65d8b
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ gen:
-u "graphql" -s "graphql" \
--safe

cat exeexcp >> source/graphql/exception.d

style_lint:
#@echo "Enforce braces on the same line"
#grep -nrE '^[\t ]*{' $$(find source -name '*.d'); test $$? -eq 1
Expand Down
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"dependencies" : {
"fixedsizearray": ">=1.2.0",
"vibe-d": "~>0.8.6",
"vibe-d": ">=0.8.6",
"darser": ">=0.3.0",
"nullablestore": ">=2.1.0"
},
Expand Down
6 changes: 6 additions & 0 deletions exeexcp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class GQLDExecutionException : Exception {
this(string msg, string f = __FILE__, size_t l = __LINE__) {
super(msg, f, l);
this.line = l;
}
}
7 changes: 4 additions & 3 deletions graphql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Value:
ARR: [Array#arr]
O: [ObjectType#obj]
E: [name#tok]
N: [null_#tok]

Type:
TN: [name#tname, exclamation]
Expand All @@ -144,9 +145,9 @@ Array:
Value: [lbrack, Values#vals, rbrack]

ObjectValues:
V: [name#name, colon, Value#val]
Vsc: [name#name, colon, Value#val, comma, ObjectValues#follow]
Vs: [name#name, colon, Value#val, ObjectValues#follow]
V: [name#name, colon, ValueOrVariable#val]
Vsc: [name#name, colon, ValueOrVariable#val, comma, ObjectValues#follow]
Vs: [name#name, colon, ValueOrVariable#val, ObjectValues#follow]

ObjectType:
Var: [lcurly, ObjectValues#vals, rcurly]
Expand Down
3 changes: 3 additions & 0 deletions source/graphql/argumentextractor.d
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class ArgumentExtractor : ConstVisitor {
case ValueEnum.E:
this.assign(Json(val.tok.value));
break;
case ValueEnum.N:
this.assign(Json(null));
break;
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions source/graphql/argumentextractortests.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import graphql.graphql;

unittest {
string q = `
query a($s: boolean) {
query a($s: boolean, $after: String) {
starships(overSize: 10) {
name
crew @skip(if: $s) {
Expand All @@ -22,6 +22,13 @@ query a($s: boolean) {
...charac
}
}
numberBetween(searchInput:
{ first: 10
, after: $after
}
) {
id
}
}
fragment hyooman on Humanoid {
Expand All @@ -41,7 +48,7 @@ fragment charac on Character {
series
}`;

Json vars = parseJsonString(`{ "s": false }`);
Json vars = parseJsonString(`{ "s": false, "after": "Hello World" }`);

Document doc = cast()lexAndParse(q);
assert(doc !is null);
Expand Down Expand Up @@ -71,4 +78,14 @@ fragment charac on Character {
Json args = getArguments(cast()name, vars);
assert(args == parseJsonString(`{"get" : false}`), format("%s", args));
}

{
auto searchInput = astSelect!Field(doc, "a.numberBetween");
assert(searchInput !is null);

Json args = getArguments(cast()searchInput, vars);
assert(args == parseJsonString(
`{ "searchInput": {"first" : 10, "after": "Hello World"}}`),
format("%s", args));
}
}
7 changes: 4 additions & 3 deletions source/graphql/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ enum ValueEnum {
ARR,
O,
E,
N,
}

class Value : Node {
Expand Down Expand Up @@ -1221,17 +1222,17 @@ enum ObjectValuesEnum {

class ObjectValues : Node {
ObjectValuesEnum ruleSelection;
Value val;
ValueOrVariable val;
ObjectValues follow;
Token name;

this(ObjectValuesEnum ruleSelection, Token name, Value val) {
this(ObjectValuesEnum ruleSelection, Token name, ValueOrVariable val) {
this.ruleSelection = ruleSelection;
this.name = name;
this.val = val;
}

this(ObjectValuesEnum ruleSelection, Token name, Value val, ObjectValues follow) {
this(ObjectValuesEnum ruleSelection, Token name, ValueOrVariable val, ObjectValues follow) {
this.ruleSelection = ruleSelection;
this.name = name;
this.val = val;
Expand Down
3 changes: 1 addition & 2 deletions source/graphql/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module graphql.exception;

@safe:


class ParseException : Exception {
int line;
string[] subRules;
Expand Down Expand Up @@ -31,11 +32,9 @@ class ParseException : Exception {
this.line = l;
}
}

class GQLDExecutionException : Exception {
this(string msg, string f = __FILE__, size_t l = __LINE__) {
super(msg, f, l);
this.line = l;
}
}

11 changes: 11 additions & 0 deletions source/graphql/helper.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ import graphql.exception;

@safe:

/** dmd and ldc have problems with generation all functions
This functions call functions that were undefined.
*/
private void undefinedFunctions() {
static import core.internal.hash;

const(graphql.schema.introspectiontypes.__Type)[] tmp;
core.internal.hash.hashOf!(const(graphql.schema.introspectiontypes.__Type)[])
(tmp, 0);
}

enum d = "data";
enum e = Constants.errors;

Expand Down
30 changes: 19 additions & 11 deletions source/graphql/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["dollar -> Variable","false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","stringValue -> Value","true_ -> Value"]
["dollar -> Variable","false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","null_ -> Value","stringValue -> Value","true_ -> Value"]
);

}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","stringValue","true_"]
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","null_","stringValue","true_"]
);

}
Expand Down Expand Up @@ -1783,7 +1783,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","stringValue","true_","dollar"]
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","null_","stringValue","true_","dollar"]
);

}
Expand All @@ -1796,7 +1796,8 @@ struct Parser {
|| this.lex.front.type == TokenType.false_
|| this.firstArray()
|| this.firstObjectType()
|| this.lex.front.type == TokenType.name;
|| this.lex.front.type == TokenType.name
|| this.lex.front.type == TokenType.null_;
}

Value parseValue() {
Expand Down Expand Up @@ -1867,6 +1868,13 @@ struct Parser {
return new Value(ValueEnum.E
, tok
);
} else if(this.lex.front.type == TokenType.null_) {
Token tok = this.lex.front;
this.lex.popFront();

return new Value(ValueEnum.N
, tok
);
}
auto app = appender!string();
formattedWrite(app,
Expand All @@ -1876,7 +1884,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["stringValue","intValue","floatValue","true_","false_","lbrack","lcurly","name"]
["stringValue","intValue","floatValue","true_","false_","lbrack","lcurly","name","null_"]
);

}
Expand Down Expand Up @@ -2049,7 +2057,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","stringValue -> Value","true_ -> Value"]
["false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","null_ -> Value","stringValue -> Value","true_ -> Value"]
);

}
Expand All @@ -2065,7 +2073,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","stringValue","true_"]
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","null_","stringValue","true_"]
);

}
Expand Down Expand Up @@ -2126,7 +2134,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["rbrack","false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","stringValue -> Value","true_ -> Value"]
["rbrack","false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","null_ -> Value","stringValue -> Value","true_ -> Value"]
);

}
Expand Down Expand Up @@ -2168,8 +2176,8 @@ struct Parser {
if(this.lex.front.type == TokenType.colon) {
this.lex.popFront();
subRules = ["V", "Vs", "Vsc"];
if(this.firstValue()) {
Value val = this.parseValue();
if(this.firstValueOrVariable()) {
ValueOrVariable val = this.parseValueOrVariable();
subRules = ["Vsc"];
if(this.lex.front.type == TokenType.comma) {
this.lex.popFront();
Expand Down Expand Up @@ -2216,7 +2224,7 @@ struct Parser {
throw new ParseException(app.data,
__FILE__, __LINE__,
subRules,
["false_","floatValue","intValue","lbrack -> Array","lcurly -> ObjectType","name","stringValue","true_"]
["dollar -> Variable","false_ -> Value","floatValue -> Value","intValue -> Value","lbrack -> Value","lcurly -> Value","name -> Value","null_ -> Value","stringValue -> Value","true_ -> Value"]
);

}
Expand Down
32 changes: 16 additions & 16 deletions source/graphql/starwars/validation.d
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,28 @@ void test(string s) {

@safe unittest {
assertNotThrown(test(`
query DroidFieldInFragment {
hero {
name
...DroidFields
}
}
query DroidFieldInFragment {
hero {
name
...DroidFields
}
}
fragment DroidFields on Droid {
primaryFunction
}
fragment DroidFields on Droid {
primaryFunction
}
`));
}

@safe unittest {
assertNotThrown(test(`
query DroidFieldInFragment {
hero {
name
... on Droid {
primaryFunction
}
}
query DroidFieldInFragment {
hero {
name
... on Droid {
primaryFunction
}
}
}
`));
}
7 changes: 7 additions & 0 deletions source/graphql/testschema.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ DateTime stringToDT(string s) {
return DateTime.fromISOExtString(s);
}

struct Input {
size_t first;
@optional
Nullable!string after;
}

@GQLDUda(TypeKind.OBJECT)
struct Query {
@GQLDUda(
Expand All @@ -56,6 +62,7 @@ struct Query {
Android[] resolverWillThrow();
GQLDCustomLeaf!(DateTime, dtToString, stringToDT) currentTime();
int currentTime();
Starship numberBetween(Input searchInput);

@GQLDUda(Ignore.yes)
void ignoreMe() {
Expand Down
30 changes: 30 additions & 0 deletions source/graphql/validation/schemabased.d
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,33 @@ query q($cw: Int!) {

test!ArgumentDoesNotExist(str);
}

unittest {
string str = `
query {
numberBetween(searchInput:
{ first: 10
, after: null
}
) {
id
}
}
`;
test!void(str);
}

unittest {
string str = `
query foo($after: String) {
numberBetween(searchInput:
{ first: 10
, after: $after
}
) {
id
}
}
`;
test!void(str);
}
6 changes: 6 additions & 0 deletions source/graphql/visitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ class Visitor : ConstVisitor {
case ValueEnum.E:
obj.tok.visit(this);
break;
case ValueEnum.N:
obj.tok.visit(this);
break;
}
exit(obj);
}
Expand Down Expand Up @@ -1658,6 +1661,9 @@ class ConstVisitor {
case ValueEnum.E:
obj.tok.visit(this);
break;
case ValueEnum.N:
obj.tok.visit(this);
break;
}
exit(obj);
}
Expand Down
Loading

0 comments on commit bf65d8b

Please sign in to comment.