src/schema_compiler.h

filter: Statementstmt 89.7% 447 / 498 Branchbran 64.0% 223 / 348 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 79.2% 670 / 846 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/validation.h ↑ Summary src/parser_graphqlperl_runtime.h »
1 /*
2 * Responsibility: compile graphql-perl schema/type/directive objects into
3 * a normalized internal representation that future XS validation and
4 * execution layers can consume directly.
5 */
6  
7 static const char *
8 22073 gql_schema_class_name(SV *sv) {
9 22073 ▶ if (!sv || !SvROK(sv) || !SvOBJECT(SvRV(sv))) {
Branch: 3 branches
BranchTrueFalseTotal
if (!sv || !SvROK(sv) || !SvOBJECT(SvRV(sv))) { 22073 0 22073
if (!sv || !SvROK(sv) || !SvOBJECT(SvRV(sv))) { 22073 0 22073
if (!sv || !SvROK(sv) || !SvOBJECT(SvRV(sv))) { 0 22073 22073
10 0 return "";
11 }
12 22073 ▶ return HvNAME(SvSTASH(SvRV(sv)));
Branch: 6 branches
BranchTrueFalseTotal
return HvNAME(SvSTASH(SvRV(sv))); 22073 0 22073
return HvNAME(SvSTASH(SvRV(sv))); 22073 0 22073
return HvNAME(SvSTASH(SvRV(sv))); 0 22073 22073
return HvNAME(SvSTASH(SvRV(sv))); 0 0 0
return HvNAME(SvSTASH(SvRV(sv))); 22073 0 22073
return HvNAME(SvSTASH(SvRV(sv))); 0 22073 22073
13 }
14  
15 static UV
16 124397 gql_schema_refaddr(SV *sv) {
17 124397 ▶ if (!sv || !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvROK(sv)) { 124397 0 124397
if (!sv || !SvROK(sv)) { 0 124397 124397
18 0 return 0;
19 }
20 124397 return PTR2UV(SvRV(sv));
21 }
22  
23 static SV *
24 359900 gql_schema_call_method0(pTHX_ SV *invocant, const char *method) {
25 359900 dSP;
26 int count;
27 SV *ret;
28  
29 359900 ENTER;
30 359900 SAVETMPS;
31 359900 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 359900 359900
32 359900 ▶ XPUSHs(sv_2mortal(newSVsv(invocant)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(invocant))); 0 359900 359900
33 359900 PUTBACK;
34 359900 count = call_method(method, G_SCALAR);
35 359900 SPAGAIN;
36 359900 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 359900 359900
37 0 PUTBACK;
38 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
39 0 LEAVE;
40 0 croak("Method %s did not return a scalar", method);
41 }
42 359900 ret = newSVsv(POPs);
43 359900 PUTBACK;
44 359900 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 359900 0 359900
45 359900 LEAVE;
46  
47 359900 return ret;
48 }
49  
50 static SV *
51 77209 gql_schema_call_method1(pTHX_ SV *invocant, const char *method, SV *arg) {
52 77209 dSP;
53 int count;
54 SV *ret;
55  
56 77209 ENTER;
57 77209 SAVETMPS;
58 77209 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 77209 77209
59 77209 ▶ XPUSHs(sv_2mortal(newSVsv(invocant)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(invocant))); 0 77209 77209
60 77209 ▶ XPUSHs(sv_2mortal(arg));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(arg)); 0 77209 77209
61 77209 PUTBACK;
62 77209 count = call_method(method, G_SCALAR);
63 77209 SPAGAIN;
64 77209 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 77209 77209
65 0 PUTBACK;
66 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
67 0 LEAVE;
68 0 croak("Method %s did not return a scalar", method);
69 }
70 77209 ret = newSVsv(POPs);
71 77209 PUTBACK;
72 77209 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 77209 0 77209
73 77209 LEAVE;
74  
75 77209 return ret;
76 }
77  
78 static int
79 76914 gql_schema_does_role(pTHX_ SV *obj, const char *role) {
80 76914 SV *ret = gql_schema_call_method1(aTHX_ obj, "DOES", newSVpv(role, 0));
81 76914 int truth = SvTRUE(ret) ? 1 : 0;
82 76914 SvREFCNT_dec(ret);
83 76914 return truth;
84 }
85  
86 static int
87 50340 gql_schema_does_any_role(pTHX_ SV *obj, const char **roles, Size_t count) {
88 Size_t i;
89  
90 103166 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 76753 26413 103166
91 76753 ▶ if (gql_schema_does_role(aTHX_ obj, roles[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_schema_does_role(aTHX_ obj, roles[i])) { 23927 52826 76753
92 23927 return 1;
93 }
94 }
95  
96 26413 return 0;
97 }
98  
99 static SV *
100 10 gql_schema_clone_hashref_shallow(pTHX_ SV *hashref_sv) {
101 HV *src_hv;
102 HV *dst_hv;
103 I32 count;
104 I32 i;
105 SV **keys;
106  
107 10 ▶ if (!hashref_sv || !SvROK(hashref_sv) || SvTYPE(SvRV(hashref_sv)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!hashref_sv || !SvROK(hashref_sv) || SvTYPE(SvRV(hashref_sv)) != SVt_PVHV) { 10 0 10
if (!hashref_sv || !SvROK(hashref_sv) || SvTYPE(SvRV(hashref_sv)) != SVt_PVHV) { 10 0 10
if (!hashref_sv || !SvROK(hashref_sv) || SvTYPE(SvRV(hashref_sv)) != SVt_PVHV) { 0 10 10
108 0 return newRV_noinc((SV *)newHV());
109 }
110  
111 10 src_hv = (HV *)SvRV(hashref_sv);
112 10 dst_hv = newHV();
113 10 keys = gql_parser_sorted_hash_keys(aTHX_ src_hv, &count);
114 10 ▶ if (!keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keys) { 0 10 10
115 0 return newRV_noinc((SV *)dst_hv);
116 }
117  
118 10 hv_ksplit(dst_hv, count > 1 ? count : 1);
119 20 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 10 10 20
120 10 HE *he = hv_fetch_ent(src_hv, keys[i], 0, 0);
121 SV *value_sv;
122 10 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 10 10
123 0 continue;
124 }
125 10 value_sv = HeVAL(he);
126 10 gql_parser_store_hash_key_sv(dst_hv, keys[i], newSVsv(value_sv));
127 }
128 10 gql_parser_free_sorted_hash_keys(keys, count);
129  
130 10 return newRV_noinc((SV *)dst_hv);
131 }
132  
133 static SV *
134 5293 gql_schema_clone_arrayref_shallow(pTHX_ SV *arrayref_sv) {
135 5293 AV *dst_av = newAV();
136 AV *src_av;
137 I32 i;
138  
139 5293 ▶ if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 5293 0 5293
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 5293 0 5293
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 0 5293 5293
140 0 return newRV_noinc((SV *)dst_av);
141 }
142  
143 5293 src_av = (AV *)SvRV(arrayref_sv);
144 5293 ▶ if (av_len(src_av) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(src_av) >= 0) { 5293 0 5293
145 5293 av_extend(dst_av, av_len(src_av));
146 }
147 17716 ▶ for (i = 0; i <= av_len(src_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(src_av); i++) { 12423 5293 17716
148 12423 SV **svp = av_fetch(src_av, i, 0);
149 12423 ▶ if (!svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) { 0 12423 12423
150 0 av_push(dst_av, newSV(0));
151 0 continue;
152 }
153 12423 av_push(dst_av, newSVsv(*svp));
154 }
155  
156 5293 return newRV_noinc((SV *)dst_av);
157 }
158  
159 static const char *
160 80113 gql_schema_named_type_kind(SV *type_sv) {
161 80113 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Scalar")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Scalar") 80113 0 80113
162 80113 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Scalar")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Scalar")) { 46072 34041 80113
163 46072 return "SCALAR";
164 }
165 34041 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Object")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Object") 34041 0 34041
166 34041 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Object")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Object")) { 28534 5507 34041
167 28534 return "OBJECT";
168 }
169 5507 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Interface")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Interface") 5507 0 5507
170 5507 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Interface")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Interface")) { 563 4944 5507
171 563 return "INTERFACE";
172 }
173 4944 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Union")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Union") 4944 0 4944
174 4944 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Union")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Union")) { 176 4768 4944
175 176 return "UNION";
176 }
177 4768 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Enum")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Enum") 4768 0 4768
178 4768 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Enum")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Enum")) { 4090 678 4768
179 4090 return "ENUM";
180 }
181 678 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::InputObject")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::InputObject") 678 0 678
182 678 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::InputObject")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::InputObject")) { 678 0 678
183 678 return "INPUT_OBJECT";
184 }
185  
186 0 croak("unknown GraphQL named type class %s", gql_schema_class_name(type_sv));
187 return "";
188 }
189  
190 static SV *gql_schema_compile_type_ref(pTHX_ SV *type_sv);
191 static SV *gql_schema_compile_input_fields(pTHX_ SV *fields_sv);
192 static SV *gql_schema_compile_directive_instances(pTHX_ SV *directives_sv);
193  
194 static SV *
195 9882 gql_schema_compile_type_name_array(pTHX_ SV *arrayref_sv) {
196 9882 AV *out_av = newAV();
197 AV *src_av;
198 I32 i;
199  
200 9882 ▶ if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 9882 0 9882
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 9882 0 9882
if (!arrayref_sv || !SvROK(arrayref_sv) || SvTYPE(SvRV(arrayref_sv)) != SVt_PVAV) { 0 9882 9882
201 0 return newRV_noinc((SV *)out_av);
202 }
203  
204 9882 src_av = (AV *)SvRV(arrayref_sv);
205 9882 ▶ if (av_len(src_av) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(src_av) >= 0) { 799 9083 9882
206 799 av_extend(out_av, av_len(src_av));
207 }
208 10980 ▶ for (i = 0; i <= av_len(src_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(src_av); i++) { 1098 9882 10980
209 1098 SV **item_svp = av_fetch(src_av, i, 0);
210 SV *name_sv;
211 1098 ▶ if (!item_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!item_svp) { 0 1098 1098
212 0 continue;
213 }
214 1098 name_sv = gql_schema_call_method0(aTHX_ *item_svp, "name");
215 1098 av_push(out_av, name_sv);
216 }
217  
218 9882 return newRV_noinc((SV *)out_av);
219 }
220  
221 static SV *
222 75 gql_schema_compile_directive_instances(pTHX_ SV *directives_sv) {
223 75 AV *out_av = newAV();
224 AV *src_av;
225 I32 i;
226  
227 75 ▶ if (!directives_sv || !SvOK(directives_sv) || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!directives_sv || !SvOK(directives_sv) || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 75 0 75
if (!directives_sv || !SvOK(directives_sv) || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 75 0 75
if (!directives_sv || !SvOK(directives_sv) || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 75 0 75
if (!directives_sv || !SvOK(directives_sv) || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 0 75 75
228 0 return newRV_noinc((SV *)out_av);
229 }
230  
231 75 src_av = (AV *)SvRV(directives_sv);
232 75 ▶ if (av_len(src_av) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(src_av) >= 0) { 10 65 75
233 10 av_extend(out_av, av_len(src_av));
234 }
235 85 ▶ for (i = 0; i <= av_len(src_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(src_av); i++) { 10 75 85
236 10 SV **dir_svp = av_fetch(src_av, i, 0);
237 HV *compiled_hv;
238 HV *dir_hv;
239 SV **name_svp;
240 SV **args_svp;
241 10 ▶ if (!dir_svp || !SvROK(*dir_svp) || SvTYPE(SvRV(*dir_svp)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!dir_svp || !SvROK(*dir_svp) || SvTYPE(SvRV(*dir_svp)) != SVt_PVHV) { 10 0 10
if (!dir_svp || !SvROK(*dir_svp) || SvTYPE(SvRV(*dir_svp)) != SVt_PVHV) { 10 0 10
if (!dir_svp || !SvROK(*dir_svp) || SvTYPE(SvRV(*dir_svp)) != SVt_PVHV) { 0 10 10
242 0 continue;
243 }
244 10 dir_hv = (HV *)SvRV(*dir_svp);
245 10 compiled_hv = newHV();
246 10 hv_ksplit(compiled_hv, 3);
247  
248 10 name_svp = hv_fetch(dir_hv, "name", 4, 0);
249 10 args_svp = hv_fetch(dir_hv, "arguments", 9, 0);
250  
251 10 ▶ gql_store_sv(compiled_hv, "name", name_svp ? newSVsv(*name_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "name", name_svp ? newSVsv(*name_svp) : newSV(0)); 10 0 10
252 20 ▶ gql_store_sv(
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv( 10 0 10
253 compiled_hv,
254 "arguments",
255 10 args_svp ? gql_schema_clone_hashref_shallow(aTHX_ *args_svp) : newRV_noinc((SV *)newHV())
256 );
257 10 gql_store_sv(compiled_hv, "source_directive", newSVsv(*dir_svp));
258 10 av_push(out_av, newRV_noinc((SV *)compiled_hv));
259 }
260  
261 75 return newRV_noinc((SV *)out_av);
262 }
263  
264 static SV *
265 107617 gql_schema_compile_type_ref(pTHX_ SV *type_sv) {
266 HV *compiled_hv;
267 SV *type_string_sv;
268  
269 107617 ▶ if (!type_sv || !SvOK(type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_sv || !SvOK(type_sv)) { 107617 0 107617
if (!type_sv || !SvOK(type_sv)) { 0 107617 107617
270 0 croak("cannot compile undefined GraphQL type reference");
271 }
272  
273 107617 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::NonNull")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::NonNull") 107617 0 107617
274 107617 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::NonNull")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::NonNull")) { 32011 75606 107617
275 32011 SV *inner_sv = gql_schema_call_method0(aTHX_ type_sv, "of");
276 32011 compiled_hv = newHV();
277 32011 hv_ksplit(compiled_hv, 5);
278 32011 type_string_sv = gql_schema_call_method0(aTHX_ type_sv, "to_string");
279 32011 gql_store_sv(compiled_hv, "kind", newSVpv("NON_NULL", 0));
280 32011 gql_store_sv(compiled_hv, "of", gql_schema_compile_type_ref(aTHX_ inner_sv));
281 32011 gql_store_sv(compiled_hv, "type_string", type_string_sv);
282 32011 gql_store_sv(compiled_hv, "source_type", newSVsv(type_sv));
283 32011 gql_store_sv(compiled_hv, "source_type_id", newSVuv(gql_schema_refaddr(type_sv)));
284 32011 SvREFCNT_dec(inner_sv);
285 32011 return newRV_noinc((SV *)compiled_hv);
286 }
287  
288 75606 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::List")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::List") 75606 0 75606
289 75606 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::List")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::List")) { 12273 63333 75606
290 12273 SV *inner_sv = gql_schema_call_method0(aTHX_ type_sv, "of");
291 12273 compiled_hv = newHV();
292 12273 hv_ksplit(compiled_hv, 5);
293 12273 type_string_sv = gql_schema_call_method0(aTHX_ type_sv, "to_string");
294 12273 gql_store_sv(compiled_hv, "kind", newSVpv("LIST", 0));
295 12273 gql_store_sv(compiled_hv, "of", gql_schema_compile_type_ref(aTHX_ inner_sv));
296 12273 gql_store_sv(compiled_hv, "type_string", type_string_sv);
297 12273 gql_store_sv(compiled_hv, "source_type", newSVsv(type_sv));
298 12273 gql_store_sv(compiled_hv, "source_type_id", newSVuv(gql_schema_refaddr(type_sv)));
299 12273 SvREFCNT_dec(inner_sv);
300 12273 return newRV_noinc((SV *)compiled_hv);
301 }
302  
303 63333 compiled_hv = newHV();
304 63333 hv_ksplit(compiled_hv, 6);
305 63333 gql_store_sv(compiled_hv, "kind", newSVpv("NAMED", 0));
306 63333 gql_store_sv(compiled_hv, "name", gql_schema_call_method0(aTHX_ type_sv, "name"));
307 63333 gql_store_sv(compiled_hv, "named_kind", newSVpv(gql_schema_named_type_kind(type_sv), 0));
308 63333 gql_store_sv(compiled_hv, "type_string", gql_schema_call_method0(aTHX_ type_sv, "to_string"));
309 63333 gql_store_sv(compiled_hv, "source_type", newSVsv(type_sv));
310 63333 gql_store_sv(compiled_hv, "source_type_id", newSVuv(gql_schema_refaddr(type_sv)));
311 63333 return newRV_noinc((SV *)compiled_hv);
312 }
313  
314 static SV *
315 12458 gql_schema_compile_input_fields(pTHX_ SV *fields_sv) {
316 12458 HV *out_hv = newHV();
317 HV *fields_hv;
318 I32 count;
319 I32 i;
320 SV **keys;
321  
322 12458 ▶ if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 12458 0 12458
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 12458 0 12458
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 12458 0 12458
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 0 12458 12458
323 0 return newRV_noinc((SV *)out_hv);
324 }
325  
326 12458 fields_hv = (HV *)SvRV(fields_sv);
327 12458 keys = gql_parser_sorted_hash_keys(aTHX_ fields_hv, &count);
328 12458 ▶ if (!keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keys) { 1034 11424 12458
329 1034 return newRV_noinc((SV *)out_hv);
330 }
331  
332 11424 hv_ksplit(out_hv, count > 1 ? count : 1);
333 25829 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 14405 11424 25829
334 14405 HE *he = hv_fetch_ent(fields_hv, keys[i], 0, 0);
335 SV *field_sv;
336 HV *field_hv;
337 HV *compiled_hv;
338 SV **type_svp;
339 SV **description_svp;
340 SV **directives_svp;
341 SV **deprecated_svp;
342 SV **deprecated_reason_svp;
343  
344 14405 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 14405 14405
345 0 continue;
346 }
347 14405 field_sv = HeVAL(he);
348 14405 ▶ if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) { 14405 0 14405
if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) { 0 14405 14405
349 0 continue;
350 }
351  
352 14405 field_hv = (HV *)SvRV(field_sv);
353 14405 type_svp = hv_fetch(field_hv, "type", 4, 0);
354 14405 ▶ if (!type_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!type_svp) { 0 14405 14405
355 0 croak("schema compiler expected input field type");
356 }
357  
358 14405 compiled_hv = newHV();
359 14405 hv_ksplit(compiled_hv, 8);
360 14405 gql_store_sv(compiled_hv, "name", newSVsv(keys[i]));
361 14405 gql_store_sv(compiled_hv, "type", gql_schema_compile_type_ref(aTHX_ *type_svp));
362  
363 14405 description_svp = hv_fetch(field_hv, "description", 11, 0);
364 14405 ▶ if (description_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (description_svp) { 3770 10635 14405
365 3770 gql_store_sv(compiled_hv, "description", newSVsv(*description_svp));
366 } else {
367 10635 gql_store_sv(compiled_hv, "description", newSV(0));
368 }
369  
370 14405 ▶ if (hv_exists(field_hv, "default_value", 13)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(field_hv, "default_value", 13)) { 5733 8672 14405
371 5733 SV **default_svp = hv_fetch(field_hv, "default_value", 13, 0);
372 5733 ▶ gql_store_sv(compiled_hv, "default_value", default_svp ? newSVsv(*default_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "default_value", default_svp ? newSVsv(*default_svp) : newSV(0)); 5733 0 5733
373 5733 gql_store_sv(compiled_hv, "has_default_value", newSViv(1));
374 } else {
375 8672 gql_store_sv(compiled_hv, "default_value", newSV(0));
376 8672 gql_store_sv(compiled_hv, "has_default_value", newSViv(0));
377 }
378  
379 14405 directives_svp = hv_fetch(field_hv, "directives", 10, 0);
380 28810 ▶ gql_store_sv(
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv( 0 14405 14405
381 compiled_hv,
382 "directives",
383 14405 directives_svp ? gql_schema_compile_directive_instances(aTHX_ *directives_svp) : newRV_noinc((SV *)newAV())
384 );
385  
386 14405 deprecated_reason_svp = hv_fetch(field_hv, "deprecation_reason", 18, 0);
387 14405 ▶ if (deprecated_reason_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (deprecated_reason_svp) { 44 14361 14405
388 44 gql_store_sv(compiled_hv, "deprecation_reason", newSVsv(*deprecated_reason_svp));
389 } else {
390 14361 gql_store_sv(compiled_hv, "deprecation_reason", newSV(0));
391 }
392  
393 14405 deprecated_svp = hv_fetch(field_hv, "is_deprecated", 13, 0);
394 14405 ▶ gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 44 14361 14405
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 44 0 44
395 14405 gql_store_sv(compiled_hv, "source_field", newSVsv(field_sv));
396  
397 14405 gql_parser_store_hash_key_sv(out_hv, keys[i], newRV_noinc((SV *)compiled_hv));
398 }
399  
400 11424 gql_parser_free_sorted_hash_keys(keys, count);
401 11424 return newRV_noinc((SV *)out_hv);
402 }
403  
404 static SV *
405 9497 gql_schema_compile_fields(pTHX_ SV *fields_sv) {
406 9497 HV *out_hv = newHV();
407 HV *fields_hv;
408 I32 count;
409 I32 i;
410 SV **keys;
411  
412 9497 ▶ if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 9497 0 9497
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 9497 0 9497
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 9497 0 9497
if (!fields_sv || !SvOK(fields_sv) || !SvROK(fields_sv) || SvTYPE(SvRV(fields_sv)) != SVt_PVHV) { 0 9497 9497
413 0 return newRV_noinc((SV *)out_hv);
414 }
415  
416 9497 fields_hv = (HV *)SvRV(fields_sv);
417 9497 keys = gql_parser_sorted_hash_keys(aTHX_ fields_hv, &count);
418 9497 ▶ if (!keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keys) { 0 9497 9497
419 0 return newRV_noinc((SV *)out_hv);
420 }
421  
422 9497 hv_ksplit(out_hv, count > 1 ? count : 1);
423 58415 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 48918 9497 58415
424 48918 HE *he = hv_fetch_ent(fields_hv, keys[i], 0, 0);
425 SV *field_sv;
426 HV *field_hv;
427 HV *compiled_hv;
428 SV **type_svp;
429 SV **description_svp;
430 SV **directives_svp;
431 SV **deprecated_svp;
432 SV **deprecated_reason_svp;
433 SV **args_svp;
434 SV **resolve_svp;
435 SV **subscribe_svp;
436 SV **cost_svp;
437 SV **list_size_svp;
438  
439 48918 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 48918 48918
440 0 continue;
441 }
442 48918 field_sv = HeVAL(he);
443 48918 ▶ if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) { 48918 0 48918
if (!SvROK(field_sv) || SvTYPE(SvRV(field_sv)) != SVt_PVHV) { 0 48918 48918
444 0 continue;
445 }
446  
447 48918 field_hv = (HV *)SvRV(field_sv);
448 48918 type_svp = hv_fetch(field_hv, "type", 4, 0);
449 48918 ▶ if (!type_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!type_svp) { 0 48918 48918
450 0 croak("schema compiler expected field type");
451 }
452  
453 48918 compiled_hv = newHV();
454 48918 hv_ksplit(compiled_hv, 12);
455 48918 gql_store_sv(compiled_hv, "name", newSVsv(keys[i]));
456 48918 gql_store_sv(compiled_hv, "type", gql_schema_compile_type_ref(aTHX_ *type_svp));
457  
458 48918 description_svp = hv_fetch(field_hv, "description", 11, 0);
459 48918 ▶ gql_store_sv(compiled_hv, "description", description_svp ? newSVsv(*description_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "description", description_svp ? newSVsv(*description_svp) : newSV(0)); 12916 36002 48918
460  
461 48918 deprecated_reason_svp = hv_fetch(field_hv, "deprecation_reason", 18, 0);
462 48918 ▶ gql_store_sv(compiled_hv, "deprecation_reason", deprecated_reason_svp ? newSVsv(*deprecated_reason_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "deprecation_reason", deprecated_reason_svp ? newSVsv(*deprecated_reason_svp) : newSV(0)); 0 48918 48918
463  
464 48918 deprecated_svp = hv_fetch(field_hv, "is_deprecated", 13, 0);
465 48918 ▶ gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 0 48918 48918
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 0 0 0
466  
467 48918 directives_svp = hv_fetch(field_hv, "directives", 10, 0);
468 97836 ▶ gql_store_sv(
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv( 75 48843 48918
469 compiled_hv,
470 "directives",
471 48918 directives_svp ? gql_schema_compile_directive_instances(aTHX_ *directives_svp) : newRV_noinc((SV *)newAV())
472 );
473  
474 48918 args_svp = hv_fetch(field_hv, "args", 4, 0);
475 97836 ▶ gql_store_sv(
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv( 6824 42094 48918
476 compiled_hv,
477 "args",
478 48918 args_svp ? gql_schema_compile_input_fields(aTHX_ *args_svp) : newRV_noinc((SV *)newHV())
479 );
480  
481 48918 resolve_svp = hv_fetch(field_hv, "resolve", 7, 0);
482 48918 ▶ if (resolve_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolve_svp) { 33782 15136 48918
483 33782 gql_store_sv(compiled_hv, "resolve", newSVsv(*resolve_svp));
484 }
485  
486 48918 subscribe_svp = hv_fetch(field_hv, "subscribe", 9, 0);
487 48918 ▶ if (subscribe_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (subscribe_svp) { 0 48918 48918
488 0 gql_store_sv(compiled_hv, "subscribe", newSVsv(*subscribe_svp));
489 }
490  
491 48918 cost_svp = hv_fetch(field_hv, "cost", 4, 0);
492 48918 ▶ if (cost_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (cost_svp) { 195 48723 48918
493 195 ▶ if (!SvIOK(*cost_svp) || SvIV(*cost_svp) < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIOK(*cost_svp) || SvIV(*cost_svp) < 0) { 195 0 195
if (!SvIOK(*cost_svp) || SvIV(*cost_svp) < 0) { 0 195 195
494 0 croak("field cost must be a non-negative integer");
495 }
496 195 gql_store_sv(compiled_hv, "cost", newSVuv(SvUV(*cost_svp)));
497 }
498  
499 48918 list_size_svp = hv_fetch(field_hv, "list_size", 9, 0);
500 48918 ▶ if (list_size_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (list_size_svp) { 130 48788 48918
501 130 ▶ if (!SvIOK(*list_size_svp) || SvIV(*list_size_svp) < 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIOK(*list_size_svp) || SvIV(*list_size_svp) < 1) { 130 0 130
if (!SvIOK(*list_size_svp) || SvIV(*list_size_svp) < 1) { 0 130 130
502 0 croak("field list_size must be a positive integer");
503 }
504 130 gql_store_sv(compiled_hv, "list_size", newSVuv(SvUV(*list_size_svp)));
505 }
506  
507 48918 gql_store_sv(compiled_hv, "source_field", newSVsv(field_sv));
508 48918 gql_parser_store_hash_key_sv(out_hv, keys[i], newRV_noinc((SV *)compiled_hv));
509 }
510  
511 9497 gql_parser_free_sorted_hash_keys(keys, count);
512 9497 return newRV_noinc((SV *)out_hv);
513 }
514  
515 static SV *
516 1981 gql_schema_compile_enum_values(pTHX_ SV *values_sv) {
517 1981 HV *out_hv = newHV();
518 HV *values_hv;
519 I32 count;
520 I32 i;
521 SV **keys;
522  
523 1981 ▶ if (!values_sv || !SvOK(values_sv) || !SvROK(values_sv) || SvTYPE(SvRV(values_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!values_sv || !SvOK(values_sv) || !SvROK(values_sv) || SvTYPE(SvRV(values_sv)) != SVt_PVHV) { 1981 0 1981
if (!values_sv || !SvOK(values_sv) || !SvROK(values_sv) || SvTYPE(SvRV(values_sv)) != SVt_PVHV) { 1981 0 1981
if (!values_sv || !SvOK(values_sv) || !SvROK(values_sv) || SvTYPE(SvRV(values_sv)) != SVt_PVHV) { 1981 0 1981
if (!values_sv || !SvOK(values_sv) || !SvROK(values_sv) || SvTYPE(SvRV(values_sv)) != SVt_PVHV) { 0 1981 1981
524 0 return newRV_noinc((SV *)out_hv);
525 }
526  
527 1981 values_hv = (HV *)SvRV(values_sv);
528 1981 keys = gql_parser_sorted_hash_keys(aTHX_ values_hv, &count);
529 1981 ▶ if (!keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keys) { 0 1981 1981
530 0 return newRV_noinc((SV *)out_hv);
531 }
532  
533 1981 hv_ksplit(out_hv, count > 1 ? count : 1);
534 27461 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 25480 1981 27461
535 25480 HE *he = hv_fetch_ent(values_hv, keys[i], 0, 0);
536 SV *value_sv;
537 HV *value_hv;
538 HV *compiled_hv;
539 SV **actual_value_svp;
540 SV **description_svp;
541 SV **deprecated_svp;
542 SV **deprecated_reason_svp;
543  
544 25480 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 25480 25480
545 0 continue;
546 }
547 25480 value_sv = HeVAL(he);
548 25480 ▶ if (!SvROK(value_sv) || SvTYPE(SvRV(value_sv)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(value_sv) || SvTYPE(SvRV(value_sv)) != SVt_PVHV) { 25480 0 25480
if (!SvROK(value_sv) || SvTYPE(SvRV(value_sv)) != SVt_PVHV) { 0 25480 25480
549 0 continue;
550 }
551  
552 25480 value_hv = (HV *)SvRV(value_sv);
553 25480 compiled_hv = newHV();
554 25480 hv_ksplit(compiled_hv, 6);
555 25480 gql_store_sv(compiled_hv, "name", newSVsv(keys[i]));
556  
557 25480 actual_value_svp = hv_fetch(value_hv, "value", 5, 0);
558 25480 ▶ gql_store_sv(compiled_hv, "value", actual_value_svp ? newSVsv(*actual_value_svp) : newSVsv(keys[i]));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "value", actual_value_svp ? newSVsv(*actual_value_svp) : newSVsv(keys[i])); 25480 0 25480
559  
560 25480 description_svp = hv_fetch(value_hv, "description", 11, 0);
561 25480 ▶ gql_store_sv(compiled_hv, "description", description_svp ? newSVsv(*description_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "description", description_svp ? newSVsv(*description_svp) : newSV(0)); 25220 260 25480
562  
563 25480 deprecated_reason_svp = hv_fetch(value_hv, "deprecation_reason", 18, 0);
564 25480 ▶ gql_store_sv(compiled_hv, "deprecation_reason", deprecated_reason_svp ? newSVsv(*deprecated_reason_svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "deprecation_reason", deprecated_reason_svp ? newSVsv(*deprecated_reason_svp) : newSV(0)); 2 25478 25480
565  
566 25480 deprecated_svp = hv_fetch(value_hv, "is_deprecated", 13, 0);
567 25480 ▶ gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 2 25478 25480
gql_store_sv(compiled_hv, "is_deprecated", newSViv(deprecated_svp && SvTRUE(*deprecated_svp) ? 1 : 0)); 2 0 2
568 25480 gql_store_sv(compiled_hv, "source_value", newSVsv(value_sv));
569  
570 25480 gql_parser_store_hash_key_sv(out_hv, keys[i], newRV_noinc((SV *)compiled_hv));
571 }
572  
573 1981 gql_parser_free_sorted_hash_keys(keys, count);
574 1981 return newRV_noinc((SV *)out_hv);
575 }
576  
577 static SV *
578 5293 gql_schema_compile_directive(pTHX_ SV *directive_sv) {
579 5293 HV *compiled_hv = newHV();
580 SV *args_sv;
581 SV *locations_sv;
582  
583 5293 hv_ksplit(compiled_hv, 6);
584 5293 gql_store_sv(compiled_hv, "name", gql_schema_call_method0(aTHX_ directive_sv, "name"));
585 5293 gql_store_sv(compiled_hv, "class", newSVpv(gql_schema_class_name(directive_sv), 0));
586 5293 gql_store_sv(compiled_hv, "description", gql_schema_call_method0(aTHX_ directive_sv, "description"));
587 5293 gql_store_sv(compiled_hv, "repeatable", gql_schema_call_method0(aTHX_ directive_sv, "repeatable"));
588  
589 5293 locations_sv = gql_schema_call_method0(aTHX_ directive_sv, "locations");
590 5293 gql_store_sv(compiled_hv, "locations", gql_schema_clone_arrayref_shallow(aTHX_ locations_sv));
591 5293 SvREFCNT_dec(locations_sv);
592  
593 5293 args_sv = gql_schema_call_method0(aTHX_ directive_sv, "args");
594 5293 gql_store_sv(compiled_hv, "args", gql_schema_compile_input_fields(aTHX_ args_sv));
595 5293 SvREFCNT_dec(args_sv);
596  
597 5293 gql_store_sv(compiled_hv, "source_directive", newSVsv(directive_sv));
598 5293 return newRV_noinc((SV *)compiled_hv);
599 }
600  
601 static SV *
602 16780 gql_schema_compile_named_type(pTHX_ SV *type_sv) {
603 16780 HV *compiled_hv = newHV();
604 16780 const char *kind = gql_schema_named_type_kind(type_sv);
605 SV *fields_sv;
606 static const char *input_roles[] = {
607 "GraphQL::Houtou::Role::Input",
608 "GraphQL::Role::Input",
609 };
610 static const char *output_roles[] = {
611 "GraphQL::Houtou::Role::Output",
612 "GraphQL::Role::Output",
613 };
614 static const char *abstract_roles[] = {
615 "GraphQL::Houtou::Role::Abstract",
616 "GraphQL::Role::Abstract",
617 };
618  
619 16780 hv_ksplit(compiled_hv, 12);
620 16780 gql_store_sv(compiled_hv, "kind", newSVpv(kind, 0));
621 16780 gql_store_sv(compiled_hv, "name", gql_schema_call_method0(aTHX_ type_sv, "name"));
622 16780 gql_store_sv(compiled_hv, "class", newSVpv(gql_schema_class_name(type_sv), 0));
623 16780 gql_store_sv(compiled_hv, "description", gql_schema_call_method0(aTHX_ type_sv, "description"));
624 16780 gql_store_sv(compiled_hv, "type_string", gql_schema_call_method0(aTHX_ type_sv, "to_string"));
625 16780 gql_store_sv(compiled_hv, "source_type", newSVsv(type_sv));
626 16780 gql_store_sv(compiled_hv, "source_type_id", newSVuv(gql_schema_refaddr(type_sv)));
627 16780 gql_store_sv(compiled_hv, "is_input", newSViv(gql_schema_does_any_role(aTHX_ type_sv, input_roles, 2)));
628 16780 gql_store_sv(compiled_hv, "is_output", newSViv(gql_schema_does_any_role(aTHX_ type_sv, output_roles, 2)));
629 16780 gql_store_sv(compiled_hv, "is_abstract", newSViv(gql_schema_does_any_role(aTHX_ type_sv, abstract_roles, 2)));
630  
631 33560 ▶ if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) { 16780 0 16780
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) { 16780 0 16780
632 16780 HV *type_hv = (HV *)SvRV(type_sv);
633 16780 SV **introspection_svp = hv_fetch(type_hv, "is_introspection", 16, 0);
634 16780 ▶ gql_store_sv(compiled_hv, "is_introspection", newSViv(introspection_svp && SvTRUE(*introspection_svp) ? 1 : 0));
Branch: 2 branches
BranchTrueFalseTotal
gql_store_sv(compiled_hv, "is_introspection", newSViv(introspection_svp && SvTRUE(*introspection_svp) ? 1 : 0)); 16780 0 16780
gql_store_sv(compiled_hv, "is_introspection", newSViv(introspection_svp && SvTRUE(*introspection_svp) ? 1 : 0)); 7472 9308 16780
635 } else {
636 0 gql_store_sv(compiled_hv, "is_introspection", newSViv(0));
637 }
638  
639 16780 ▶ if (strEQ(kind, "OBJECT")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(kind, "OBJECT")) { 9292 7488 16780
640 9292 SV *interfaces_sv = gql_schema_call_method0(aTHX_ type_sv, "interfaces");
641 9292 fields_sv = gql_schema_call_method0(aTHX_ type_sv, "fields");
642 9292 gql_store_sv(compiled_hv, "interfaces", gql_schema_compile_type_name_array(aTHX_ interfaces_sv));
643 9292 gql_store_sv(compiled_hv, "fields", gql_schema_compile_fields(aTHX_ fields_sv));
644 9292 SvREFCNT_dec(interfaces_sv);
645 9292 SvREFCNT_dec(fields_sv);
646 {
647 9292 SV *is_type_of_sv = gql_schema_call_method0(aTHX_ type_sv, "is_type_of");
648 9292 ▶ if (SvOK(is_type_of_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(is_type_of_sv)) { 0 9292 9292
649 0 gql_store_sv(compiled_hv, "is_type_of", is_type_of_sv);
650 } else {
651 9292 SvREFCNT_dec(is_type_of_sv);
652 }
653 }
654 7488 ▶ } else if (strEQ(kind, "INTERFACE")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(kind, "INTERFACE")) { 205 7283 7488
655 205 SV *interfaces_sv = gql_schema_call_method0(aTHX_ type_sv, "interfaces");
656 205 fields_sv = gql_schema_call_method0(aTHX_ type_sv, "fields");
657 205 gql_store_sv(compiled_hv, "interfaces", gql_schema_compile_type_name_array(aTHX_ interfaces_sv));
658 205 gql_store_sv(compiled_hv, "fields", gql_schema_compile_fields(aTHX_ fields_sv));
659 205 SvREFCNT_dec(interfaces_sv);
660 205 SvREFCNT_dec(fields_sv);
661 {
662 205 SV *resolve_type_sv = gql_schema_call_method0(aTHX_ type_sv, "resolve_type");
663 205 ▶ if (SvOK(resolve_type_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(resolve_type_sv)) { 71 134 205
664 71 gql_store_sv(compiled_hv, "resolve_type", resolve_type_sv);
665 } else {
666 134 SvREFCNT_dec(resolve_type_sv);
667 }
668 }
669 7283 ▶ } else if (strEQ(kind, "UNION")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(kind, "UNION")) { 90 7193 7283
670 90 SV *types_sv = gql_schema_call_method0(aTHX_ type_sv, "get_types");
671 90 gql_store_sv(compiled_hv, "types", gql_schema_compile_type_name_array(aTHX_ types_sv));
672 90 SvREFCNT_dec(types_sv);
673 {
674 90 SV *resolve_type_sv = gql_schema_call_method0(aTHX_ type_sv, "resolve_type");
675 90 ▶ if (SvOK(resolve_type_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(resolve_type_sv)) { 14 76 90
676 14 gql_store_sv(compiled_hv, "resolve_type", resolve_type_sv);
677 } else {
678 76 SvREFCNT_dec(resolve_type_sv);
679 }
680 }
681 7193 ▶ } else if (strEQ(kind, "INPUT_OBJECT")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(kind, "INPUT_OBJECT")) { 341 6852 7193
682 341 fields_sv = gql_schema_call_method0(aTHX_ type_sv, "fields");
683 341 gql_store_sv(compiled_hv, "fields", gql_schema_compile_input_fields(aTHX_ fields_sv));
684 341 SvREFCNT_dec(fields_sv);
685 {
686 341 SV *one_of_sv = gql_schema_call_method0(aTHX_ type_sv, "is_one_of");
687 341 ▶ if (SvTRUE(one_of_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(one_of_sv)) { 37 304 341
688 37 gql_store_sv(compiled_hv, "is_one_of", newSViv(1));
689 }
690 341 SvREFCNT_dec(one_of_sv);
691 }
692 6852 ▶ } else if (strEQ(kind, "ENUM")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(kind, "ENUM")) { 1981 4871 6852
693 1981 SV *values_sv = gql_schema_call_method0(aTHX_ type_sv, "values");
694 1981 gql_store_sv(compiled_hv, "values", gql_schema_compile_enum_values(aTHX_ values_sv));
695 1981 SvREFCNT_dec(values_sv);
696 4871 ▶ } else if (strEQ(kind, "SCALAR")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(kind, "SCALAR")) { 4871 0 4871
697 4871 SV *serialize_sv = gql_schema_call_method0(aTHX_ type_sv, "serialize");
698 4871 SV *parse_value_sv = gql_schema_call_method0(aTHX_ type_sv, "parse_value");
699 4871 SV *specified_by_url_sv = gql_schema_call_method0(aTHX_ type_sv, "specified_by_url");
700 4871 ▶ if (SvOK(serialize_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(serialize_sv)) { 4871 0 4871
701 4871 gql_store_sv(compiled_hv, "serialize", serialize_sv);
702 } else {
703 0 SvREFCNT_dec(serialize_sv);
704 }
705 4871 ▶ if (SvOK(parse_value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(parse_value_sv)) { 4871 0 4871
706 4871 gql_store_sv(compiled_hv, "parse_value", parse_value_sv);
707 } else {
708 0 SvREFCNT_dec(parse_value_sv);
709 }
710 4871 ▶ if (SvOK(specified_by_url_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(specified_by_url_sv)) { 34 4837 4871
711 34 gql_store_sv(compiled_hv, "specified_by_url", specified_by_url_sv);
712 } else {
713 4837 SvREFCNT_dec(specified_by_url_sv);
714 }
715 }
716  
717 16780 return newRV_noinc((SV *)compiled_hv);
718 }
719  
720 static SV *
721 934 gql_schema_compile_schema(pTHX_ SV *schema_sv) {
722 HV *compiled_hv;
723 HV *roots_hv;
724 HV *types_hv;
725 HV *directives_hv;
726 HV *interface_implementations_hv;
727 HV *possible_types_hv;
728 SV *name2type_sv;
729 HV *name2type_hv;
730 I32 type_count;
731 I32 i;
732 SV **type_keys;
733 SV *directives_sv;
734 AV *directives_av;
735  
736 934 ▶ if (!sv_derived_from(schema_sv, "GraphQL::Schema")
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_derived_from(schema_sv, "GraphQL::Schema") 934 0 934
737 934 ▶ && !sv_derived_from(schema_sv, "GraphQL::Houtou::Schema")) {
Branch: 1 branch
BranchTrueFalseTotal
&& !sv_derived_from(schema_sv, "GraphQL::Houtou::Schema")) { 0 934 934
738 0 croak("compile_schema_xs expects a GraphQL::Houtou::Schema or GraphQL::Schema instance");
739 }
740  
741 934 compiled_hv = newHV();
742 934 roots_hv = newHV();
743 934 types_hv = newHV();
744 934 directives_hv = newHV();
745 934 interface_implementations_hv = newHV();
746 934 possible_types_hv = newHV();
747  
748 {
749 934 const char *root_names[] = { "query", "mutation", "subscription" };
750 I32 root_i;
751 934 hv_ksplit(roots_hv, 3);
752 3736 ▶ for (root_i = 0; root_i < 3; root_i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (root_i = 0; root_i < 3; root_i++) { 2802 934 3736
753 2802 SV *root_type_sv = gql_schema_call_method0(aTHX_ schema_sv, root_names[root_i]);
754 3917 ▶ if (SvOK(root_type_sv) && SvROK(root_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(root_type_sv) && SvROK(root_type_sv)) { 1115 1687 2802
if (SvOK(root_type_sv) && SvROK(root_type_sv)) { 1115 0 1115
755 1115 SV *root_name_sv = gql_schema_call_method0(aTHX_ root_type_sv, "name");
756 1115 gql_store_sv(roots_hv, root_names[root_i], root_name_sv);
757 } else {
758 1687 gql_store_sv(roots_hv, root_names[root_i], newSV(0));
759 }
760 2802 SvREFCNT_dec(root_type_sv);
761 }
762 }
763  
764 934 name2type_sv = gql_schema_call_method0(aTHX_ schema_sv, "name2type");
765 934 ▶ if (!SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 934 0 934
if (!SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 0 934 934
766 0 SvREFCNT_dec(name2type_sv);
767 0 croak("GraphQL::Schema->name2type did not return a hash reference");
768 }
769 934 name2type_hv = (HV *)SvRV(name2type_sv);
770 934 type_keys = gql_parser_sorted_hash_keys(aTHX_ name2type_hv, &type_count);
771 934 ▶ if (type_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (type_keys) { 934 0 934
772 934 hv_ksplit(types_hv, type_count > 1 ? type_count : 1);
773 17714 ▶ for (i = 0; i < type_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < type_count; i++) { 16780 934 17714
774 16780 HE *he = hv_fetch_ent(name2type_hv, type_keys[i], 0, 0);
775 SV *type_sv;
776 16780 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 16780 16780
777 0 continue;
778 }
779 16780 type_sv = HeVAL(he);
780 16780 gql_parser_store_hash_key_sv(types_hv, type_keys[i], gql_schema_compile_named_type(aTHX_ type_sv));
781 }
782  
783 17714 ▶ for (i = 0; i < type_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < type_count; i++) { 16780 934 17714
784 16780 HE *he = hv_fetch_ent(name2type_hv, type_keys[i], 0, 0);
785 SV *type_sv;
786 16780 ▶ if (!he) {
Branch: 1 branch
BranchTrueFalseTotal
if (!he) { 0 16780 16780
787 0 continue;
788 }
789 16780 type_sv = HeVAL(he);
790  
791 16780 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Object")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Object") 16780 0 16780
792 16780 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Object")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Object")) { 9292 7488 16780
793 9292 SV *interfaces_sv = gql_schema_call_method0(aTHX_ type_sv, "interfaces");
794 9292 ▶ if (SvROK(interfaces_sv) && SvTYPE(SvRV(interfaces_sv)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(interfaces_sv) && SvTYPE(SvRV(interfaces_sv)) == SVt_PVAV) { 9292 0 9292
if (SvROK(interfaces_sv) && SvTYPE(SvRV(interfaces_sv)) == SVt_PVAV) { 9292 0 9292
795 9292 AV *interfaces_av = (AV *)SvRV(interfaces_sv);
796 I32 j;
797 9738 ▶ for (j = 0; j <= av_len(interfaces_av); j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j <= av_len(interfaces_av); j++) { 446 9292 9738
798 446 SV **iface_svp = av_fetch(interfaces_av, j, 0);
799 SV *iface_name_sv;
800 HE *existing_he;
801 446 SV *existing_sv = NULL;
802 AV *existing_av;
803 446 ▶ if (!iface_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!iface_svp) { 0 446 446
804 0 continue;
805 }
806 446 iface_name_sv = gql_schema_call_method0(aTHX_ *iface_svp, "name");
807 446 existing_he = hv_fetch_ent(interface_implementations_hv, iface_name_sv, 0, 0);
808 446 ▶ if (existing_he) {
Branch: 1 branch
BranchTrueFalseTotal
if (existing_he) { 273 173 446
809 273 existing_sv = HeVAL(existing_he);
810 }
811 446 ▶ if (existing_sv && SvROK(existing_sv) && SvTYPE(SvRV(existing_sv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (existing_sv && SvROK(existing_sv) && SvTYPE(SvRV(existing_sv)) == SVt_PVAV) { 273 173 446
if (existing_sv && SvROK(existing_sv) && SvTYPE(SvRV(existing_sv)) == SVt_PVAV) { 273 0 273
if (existing_sv && SvROK(existing_sv) && SvTYPE(SvRV(existing_sv)) == SVt_PVAV) { 273 0 273
812 273 existing_av = (AV *)SvRV(existing_sv);
813 } else {
814 173 existing_av = newAV();
815 173 gql_parser_store_hash_key_sv(interface_implementations_hv, iface_name_sv, newRV_noinc((SV *)existing_av));
816 }
817 446 av_push(existing_av, newSVsv(type_keys[i]));
818 446 SvREFCNT_dec(iface_name_sv);
819 }
820 }
821 9292 SvREFCNT_dec(interfaces_sv);
822 }
823  
824 16780 ▶ if (sv_derived_from(type_sv, "GraphQL::Type::Interface")
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(type_sv, "GraphQL::Type::Interface") 16780 0 16780
825 16780 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Interface")
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Interface") 16575 205 16780
826 16575 ▶ || sv_derived_from(type_sv, "GraphQL::Type::Union")
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Type::Union") 16575 0 16575
827 16575 ▶ || sv_derived_from(type_sv, "GraphQL::Houtou::Type::Union")) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(type_sv, "GraphQL::Houtou::Type::Union")) { 90 16485 16575
828 295 SV *possible_sv = gql_schema_call_method1(aTHX_ schema_sv, "get_possible_types", newSVsv(type_sv));
829 295 gql_parser_store_hash_key_sv(possible_types_hv, type_keys[i], gql_schema_compile_type_name_array(aTHX_ possible_sv));
830 295 SvREFCNT_dec(possible_sv);
831 }
832 }
833 934 gql_parser_free_sorted_hash_keys(type_keys, type_count);
834 }
835 934 SvREFCNT_dec(name2type_sv);
836  
837 934 directives_sv = gql_schema_call_method0(aTHX_ schema_sv, "directives");
838 934 ▶ if (!SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 934 0 934
if (!SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV) { 0 934 934
839 0 SvREFCNT_dec(directives_sv);
840 0 croak("GraphQL::Schema->directives did not return an array reference");
841 }
842 934 directives_av = (AV *)SvRV(directives_sv);
843 934 ▶ if (av_len(directives_av) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(directives_av) >= 0) { 934 0 934
844 934 hv_ksplit(directives_hv, av_len(directives_av) + 1);
845 }
846 6227 ▶ for (i = 0; i <= av_len(directives_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(directives_av); i++) { 5293 934 6227
847 5293 SV **directive_svp = av_fetch(directives_av, i, 0);
848 SV *name_sv;
849 5293 ▶ if (!directive_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!directive_svp) { 0 5293 5293
850 0 continue;
851 }
852 5293 name_sv = gql_schema_call_method0(aTHX_ *directive_svp, "name");
853 5293 gql_parser_store_hash_key_sv(directives_hv, name_sv, gql_schema_compile_directive(aTHX_ *directive_svp));
854 5293 SvREFCNT_dec(name_sv);
855 }
856 934 SvREFCNT_dec(directives_sv);
857  
858 934 hv_ksplit(compiled_hv, 6);
859 934 gql_store_sv(compiled_hv, "roots", newRV_noinc((SV *)roots_hv));
860 934 gql_store_sv(compiled_hv, "types", newRV_noinc((SV *)types_hv));
861 934 gql_store_sv(compiled_hv, "directives", newRV_noinc((SV *)directives_hv));
862 934 gql_store_sv(compiled_hv, "interface_implementations", newRV_noinc((SV *)interface_implementations_hv));
863 934 gql_store_sv(compiled_hv, "possible_types", newRV_noinc((SV *)possible_types_hv));
864 934 gql_store_sv(compiled_hv, "source_schema", newSVsv(schema_sv));
865  
866 934 return newRV_noinc((SV *)compiled_hv);
867 }
« src/validation.h ↑ Summary src/parser_graphqlperl_runtime.h »