1 module graphql.argumentextractortests;
2 
3 import std.format : format;
4 
5 import vibe.data.json;
6 
7 import graphql.ast;
8 import graphql.astselector;
9 import graphql.helper : lexAndParse;
10 import graphql.argumentextractor;
11 import graphql.testschema;
12 import graphql.graphql;
13 
14 unittest {
15 	string q = `
16 query a($s: boolean) {
17 	starships(overSize: 10) {
18 		name
19 		crew @skip(if: $s) {
20 			...hyooman
21 			...robot
22 			...charac
23 		}
24 	}
25 }
26 
27 fragment hyooman on Humanoid {
28 	species
29 	dateOfBirth
30 }
31 
32 fragment robot on Android {
33 	primaryFunction
34 }
35 
36 fragment charac on Character {
37 	...robot
38 	id
39 	...hyooman
40 	name(get: $s)
41 	series
42 }`;
43 
44 	Json vars = parseJsonString(`{ "s": false }`);
45 
46 	Document doc = cast()lexAndParse(q);
47 	assert(doc !is null);
48 
49 	{
50 		auto startships = astSelect!Field(doc, "a.starships");
51 		assert(startships !is null);
52 
53 		Json args = getArguments(cast()startships, vars);
54 		assert(args == parseJsonString(`{"overSize" : 10}`),
55 				format("%s", args)
56 			);
57 	}
58 
59 	{
60 		auto crew = astSelect!Field(doc, "a.starships.crew");
61 		assert(crew !is null);
62 
63 		Json args = getArguments(cast()crew, vars);
64 		assert(args == parseJsonString(`{"if" : false}`), format("%s", args));
65 	}
66 
67 	{
68 		auto name = astSelect!Field(doc, "a.starships.crew.name");
69 		assert(name !is null);
70 
71 		Json args = getArguments(cast()name, vars);
72 		assert(args == parseJsonString(`{"get" : false}`), format("%s", args));
73 	}
74 }