| 1 |
|
| /* |
| 2 |
|
| * Responsibility: provide the initial XS validation entrypoint so the public |
| 3 |
|
| * validation facade can route through XS while rule implementations migrate |
| 4 |
|
| * from PP to C incrementally. |
| 5 |
|
| */ |
| 6 |
|
| |
| 7 |
|
| static SV * |
| 8 |
487 |
| gql_validation_parse_ast(pTHX_ SV *document, SV *options, AV *errors_av) { |
| 9 |
487 |
▶ | if (document && SvROK(document)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (document && SvROK(document)) { |
487 |
0 |
487 |
| if (document && SvROK(document)) { |
427 |
60 |
487 |
|
| 10 |
427 |
| return newSVsv(document); |
| 11 |
|
| } |
| 12 |
|
| |
| 13 |
|
| /* Validation owns an internal parser mode so duplicate arguments, |
| 14 |
|
| * variables, and input fields can be diagnosed before the canonical hash |
| 15 |
|
| * AST overwrites the earlier entry. Public parse() remains compatible. */ |
| 16 |
|
| { |
| 17 |
60 |
| SV *no_location_sv = &PL_sv_undef; |
| 18 |
60 |
▶ | if (options && SvROK(options) && SvTYPE(SvRV(options)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (options && SvROK(options) && SvTYPE(SvRV(options)) == SVt_PVHV) { |
0 |
60 |
60 |
| if (options && SvROK(options) && SvTYPE(SvRV(options)) == SVt_PVHV) { |
0 |
0 |
0 |
| if (options && SvROK(options) && SvTYPE(SvRV(options)) == SVt_PVHV) { |
0 |
0 |
0 |
|
| 19 |
0 |
| SV **svp = hv_fetch((HV *)SvRV(options), "no_location", 11, 0); |
| 20 |
0 |
▶ | if (!svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svp) { |
0 |
0 |
0 |
|
| 21 |
0 |
| svp = hv_fetch((HV *)SvRV(options), "noLocation", 10, 0); |
| 22 |
|
| } |
| 23 |
0 |
▶ | if (svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) { |
0 |
0 |
0 |
|
| 24 |
0 |
| no_location_sv = *svp; |
| 25 |
|
| } |
| 26 |
|
| } |
| 27 |
60 |
| return gql_parse_document_for_validation( |
| 28 |
|
| aTHX_ document, no_location_sv, errors_av |
| 29 |
|
| ); |
| 30 |
|
| } |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
|
| static SV * |
| 34 |
160 |
| gql_validation_schema_name2type_sv(pTHX_ SV *schema) { |
| 35 |
160 |
| dSP; |
| 36 |
|
| int count; |
| 37 |
|
| SV *ret; |
| 38 |
|
| |
| 39 |
160 |
| ENTER; |
| 40 |
160 |
| SAVETMPS; |
| 41 |
160 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
160 |
160 |
|
| 42 |
160 |
▶ | XPUSHs(sv_2mortal(newSVsv(schema))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVsv(schema))); |
0 |
160 |
160 |
|
| 43 |
160 |
| PUTBACK; |
| 44 |
|
| |
| 45 |
160 |
| count = call_method("name2type", G_SCALAR); |
| 46 |
160 |
| SPAGAIN; |
| 47 |
160 |
▶ | if (count != 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) { |
0 |
160 |
160 |
|
| 48 |
0 |
| PUTBACK; |
| 49 |
0 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
0 |
0 |
0 |
|
| 50 |
0 |
| LEAVE; |
| 51 |
0 |
| croak("schema->name2type did not return a scalar"); |
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
160 |
| ret = newSVsv(POPs); |
| 55 |
160 |
| PUTBACK; |
| 56 |
160 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
160 |
0 |
160 |
|
| 57 |
160 |
| LEAVE; |
| 58 |
|
| |
| 59 |
160 |
| return ret; |
| 60 |
|
| } |
| 61 |
|
| |
| 62 |
|
| static SV * |
| 63 |
160 |
| gql_validation_lookup_type_sv(pTHX_ SV *schema, SV *type_ref) { |
| 64 |
160 |
| dSP; |
| 65 |
|
| int count; |
| 66 |
|
| SV *ret; |
| 67 |
|
| SV *name2type_sv; |
| 68 |
|
| |
| 69 |
160 |
| eval_pv("require GraphQL::Houtou::Schema; 1;", TRUE); |
| 70 |
160 |
| name2type_sv = gql_validation_schema_name2type_sv(aTHX_ schema); |
| 71 |
|
| |
| 72 |
160 |
| ENTER; |
| 73 |
160 |
| SAVETMPS; |
| 74 |
160 |
▶ | sv_setsv(ERRSV, &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, &PL_sv_undef); |
160 |
0 |
160 |
|
| 75 |
160 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
160 |
160 |
|
| 76 |
160 |
▶ | XPUSHs(sv_2mortal(newSVsv(type_ref))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVsv(type_ref))); |
0 |
160 |
160 |
|
| 77 |
160 |
▶ | XPUSHs(sv_2mortal(name2type_sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(name2type_sv)); |
0 |
160 |
160 |
|
| 78 |
160 |
| PUTBACK; |
| 79 |
|
| |
| 80 |
160 |
| count = call_pv("GraphQL::Houtou::Schema::lookup_type", G_SCALAR | G_EVAL); |
| 81 |
160 |
| SPAGAIN; |
| 82 |
160 |
▶ | if (count != 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) { |
0 |
160 |
160 |
|
| 83 |
0 |
| PUTBACK; |
| 84 |
0 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
0 |
0 |
0 |
|
| 85 |
0 |
| LEAVE; |
| 86 |
0 |
| croak("GraphQL::Houtou::Schema::lookup_type did not return a scalar"); |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
160 |
| ret = newSVsv(POPs); |
| 90 |
160 |
| PUTBACK; |
| 91 |
160 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
160 |
0 |
160 |
|
| 92 |
160 |
| LEAVE; |
| 93 |
|
| |
| 94 |
160 |
| return ret; |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
|
| static SV * |
| 98 |
120 |
| gql_validation_error(pTHX_ const char *message, SV *location) { |
| 99 |
120 |
| HV *error_hv = newHV(); |
| 100 |
120 |
| gql_store_sv(error_hv, "message", newSVpv(message, 0)); |
| 101 |
120 |
▶ | if (location && SvOK(location)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (location && SvOK(location)) { |
105 |
15 |
120 |
| if (location && SvOK(location)) { |
105 |
0 |
105 |
|
| 102 |
105 |
| AV *locations_av = newAV(); |
| 103 |
105 |
| av_push(locations_av, newSVsv(location)); |
| 104 |
105 |
| gql_store_sv(error_hv, "locations", newRV_noinc((SV *)locations_av)); |
| 105 |
|
| } |
| 106 |
120 |
| return newRV_noinc((SV *)error_hv); |
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
|
| static void |
| 110 |
487 |
| gql_validation_push_operation_errors(pTHX_ AV *errors_av, AV *operations_av) { |
| 111 |
487 |
| HV *seen_hv = newHV(); |
| 112 |
487 |
| I32 operation_len = av_len(operations_av); |
| 113 |
|
| I32 i; |
| 114 |
487 |
| int operation_count = operation_len >= 0 ? operation_len + 1 : 0; |
| 115 |
|
| |
| 116 |
487 |
▶ | if (operation_count == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (operation_count == 0) { |
0 |
487 |
487 |
|
| 117 |
0 |
| av_push(errors_av, gql_validation_error(aTHX_ "No operations supplied.", NULL)); |
| 118 |
0 |
| SvREFCNT_dec((SV *)seen_hv); |
| 119 |
0 |
| return; |
| 120 |
|
| } |
| 121 |
|
| |
| 122 |
977 |
▶ | for (i = 0; i <= operation_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= operation_len; i++) { |
490 |
487 |
977 |
|
| 123 |
490 |
| SV **operation_svp = av_fetch(operations_av, i, 0); |
| 124 |
|
| HV *operation_hv; |
| 125 |
|
| SV **name_svp; |
| 126 |
|
| SV **location_svp; |
| 127 |
|
| STRLEN name_len; |
| 128 |
|
| const char *name; |
| 129 |
|
| |
| 130 |
490 |
▶ | if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
490 |
0 |
490 |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
490 |
0 |
490 |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
0 |
490 |
490 |
|
| 131 |
336 |
| continue; |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
490 |
| operation_hv = (HV *)SvRV(*operation_svp); |
| 135 |
490 |
| location_svp = hv_fetch(operation_hv, "location", 8, 0); |
| 136 |
490 |
| name_svp = hv_fetch(operation_hv, "name", 4, 0); |
| 137 |
|
| |
| 138 |
490 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
155 |
335 |
490 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
155 |
155 |
|
| 139 |
335 |
▶ | if (operation_count > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (operation_count > 1) { |
1 |
334 |
335 |
|
| 140 |
1 |
▶ | av_push( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push( |
1 |
0 |
1 |
|
| 141 |
|
| errors_av, |
| 142 |
|
| gql_validation_error( |
| 143 |
|
| aTHX_ "Anonymous operations must be the only operation in the document.", |
| 144 |
|
| location_svp ? *location_svp : NULL |
| 145 |
|
| ) |
| 146 |
|
| ); |
| 147 |
|
| } |
| 148 |
335 |
| continue; |
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
155 |
| name = SvPV(*name_svp, name_len); |
| 152 |
155 |
▶ | if (hv_exists(seen_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(seen_hv, name, (I32)name_len)) { |
1 |
154 |
155 |
|
| 153 |
1 |
| SV *message = newSVpvf("Operation '%s' is defined more than once.", name); |
| 154 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
1 |
0 |
1 |
|
| 155 |
1 |
| SvREFCNT_dec(message); |
| 156 |
1 |
| continue; |
| 157 |
|
| } |
| 158 |
|
| |
| 159 |
154 |
| (void)hv_store(seen_hv, name, (I32)name_len, newSViv(1), 0); |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
487 |
| SvREFCNT_dec((SV *)seen_hv); |
| 163 |
|
| } |
| 164 |
|
| |
| 165 |
|
| static HV * |
| 166 |
934 |
| gql_validation_build_fragments_map(pTHX_ AV *ast_av) { |
| 167 |
934 |
| HV *fragments_hv = newHV(); |
| 168 |
934 |
| I32 ast_len = av_len(ast_av); |
| 169 |
|
| I32 i; |
| 170 |
|
| |
| 171 |
1913 |
▶ | for (i = 0; i <= ast_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= ast_len; i++) { |
979 |
934 |
1913 |
|
| 172 |
979 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 173 |
|
| HV *node_hv; |
| 174 |
|
| SV **kind_svp; |
| 175 |
|
| SV **name_svp; |
| 176 |
|
| STRLEN name_len; |
| 177 |
|
| const char *name; |
| 178 |
|
| |
| 179 |
979 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
979 |
0 |
979 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
979 |
0 |
979 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
0 |
979 |
979 |
|
| 180 |
940 |
| continue; |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
979 |
| node_hv = (HV *)SvRV(*node_svp); |
| 184 |
979 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 185 |
1958 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
979 |
0 |
979 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
979 |
0 |
979 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
979 |
0 |
979 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
940 |
39 |
979 |
|
| 186 |
940 |
| continue; |
| 187 |
|
| } |
| 188 |
|
| |
| 189 |
39 |
| name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 190 |
39 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
39 |
0 |
39 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
39 |
39 |
|
| 191 |
0 |
| continue; |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
39 |
| name = SvPV(*name_svp, name_len); |
| 195 |
39 |
| (void)hv_store(fragments_hv, name, (I32)name_len, newSVsv(*node_svp), 0); |
| 196 |
|
| } |
| 197 |
|
| |
| 198 |
934 |
| return fragments_hv; |
| 199 |
|
| } |
| 200 |
|
| |
| 201 |
|
| static void |
| 202 |
487 |
| gql_validation_push_fragment_name_errors(pTHX_ AV *errors_av, AV *ast_av) { |
| 203 |
487 |
| HV *seen_hv = newHV(); |
| 204 |
|
| I32 i; |
| 205 |
|
| |
| 206 |
1006 |
▶ | for (i = 0; i <= av_len(ast_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(ast_av); i++) { |
519 |
487 |
1006 |
|
| 207 |
519 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 208 |
|
| HV *node_hv; |
| 209 |
|
| SV **kind_svp; |
| 210 |
|
| SV **name_svp; |
| 211 |
|
| SV **location_svp; |
| 212 |
|
| STRLEN name_len; |
| 213 |
|
| const char *name; |
| 214 |
|
| |
| 215 |
519 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
0 |
519 |
519 |
|
| 216 |
491 |
| continue; |
| 217 |
|
| } |
| 218 |
519 |
| node_hv = (HV *)SvRV(*node_svp); |
| 219 |
519 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 220 |
519 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
|
| 221 |
1038 |
▶ | || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
491 |
28 |
519 |
|
| 222 |
491 |
| continue; |
| 223 |
|
| } |
| 224 |
28 |
| name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 225 |
28 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
28 |
0 |
28 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
28 |
28 |
|
| 226 |
0 |
| continue; |
| 227 |
|
| } |
| 228 |
28 |
| name = SvPV(*name_svp, name_len); |
| 229 |
28 |
▶ | if (hv_exists(seen_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(seen_hv, name, (I32)name_len)) { |
1 |
27 |
28 |
|
| 230 |
1 |
| SV *message = newSVpvf("Fragment '%s' is defined more than once.", name); |
| 231 |
1 |
| location_svp = hv_fetch(node_hv, "location", 8, 0); |
| 232 |
2 |
▶ | av_push(errors_av, gql_validation_error( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error( |
1 |
0 |
1 |
|
| 233 |
|
| aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL |
| 234 |
|
| )); |
| 235 |
1 |
| SvREFCNT_dec(message); |
| 236 |
|
| } else { |
| 237 |
27 |
| (void)hv_store(seen_hv, name, (I32)name_len, newSViv(1), 0); |
| 238 |
|
| } |
| 239 |
|
| } |
| 240 |
487 |
| SvREFCNT_dec((SV *)seen_hv); |
| 241 |
487 |
| } |
| 242 |
|
| |
| 243 |
|
| static void |
| 244 |
20761 |
| gql_validation_collect_usage( |
| 245 |
|
| pTHX_ SV *node_sv, |
| 246 |
|
| HV *fragments_hv, |
| 247 |
|
| HV *variables_hv, |
| 248 |
|
| HV *spreads_hv, |
| 249 |
|
| HV *visited_hv |
| 250 |
|
| ) { |
| 251 |
|
| SV *inner_sv; |
| 252 |
|
| |
| 253 |
20761 |
▶ | if (!node_sv || !SvROK(node_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!node_sv || !SvROK(node_sv)) { |
20761 |
0 |
20761 |
| if (!node_sv || !SvROK(node_sv)) { |
12794 |
7967 |
20761 |
|
| 254 |
12794 |
| return; |
| 255 |
|
| } |
| 256 |
7967 |
| inner_sv = SvRV(node_sv); |
| 257 |
7967 |
▶ | if (SvTYPE(inner_sv) != SVt_PVAV && SvTYPE(inner_sv) != SVt_PVHV |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(inner_sv) != SVt_PVAV && SvTYPE(inner_sv) != SVt_PVHV |
5867 |
2100 |
7967 |
| if (SvTYPE(inner_sv) != SVt_PVAV && SvTYPE(inner_sv) != SVt_PVHV |
198 |
5669 |
5867 |
|
| 258 |
198 |
▶ | && !SvROK(inner_sv) && !sv_isobject(node_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| && !SvROK(inner_sv) && !sv_isobject(node_sv)) { |
193 |
5 |
198 |
| && !SvROK(inner_sv) && !sv_isobject(node_sv)) { |
163 |
30 |
193 |
|
| 259 |
|
| STRLEN name_len; |
| 260 |
163 |
| const char *name = SvPV(inner_sv, name_len); |
| 261 |
163 |
| (void)hv_store(variables_hv, name, (I32)name_len, newSViv(1), 0); |
| 262 |
163 |
| return; |
| 263 |
|
| } |
| 264 |
7804 |
▶ | if (SvTYPE(inner_sv) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(inner_sv) == SVt_PVAV) { |
2100 |
5704 |
7804 |
|
| 265 |
2100 |
| AV *items_av = (AV *)inner_sv; |
| 266 |
|
| I32 i; |
| 267 |
6883 |
▶ | for (i = 0; i <= av_len(items_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(items_av); i++) { |
4783 |
2100 |
6883 |
|
| 268 |
4783 |
| SV **item_svp = av_fetch(items_av, i, 0); |
| 269 |
4783 |
▶ | if (item_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (item_svp) { |
4783 |
0 |
4783 |
|
| 270 |
4783 |
| gql_validation_collect_usage( |
| 271 |
|
| aTHX_ *item_svp, fragments_hv, variables_hv, spreads_hv, visited_hv |
| 272 |
|
| ); |
| 273 |
|
| } |
| 274 |
|
| } |
| 275 |
2100 |
| return; |
| 276 |
|
| } |
| 277 |
5704 |
▶ | if (SvTYPE(inner_sv) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(inner_sv) == SVt_PVHV) { |
5669 |
35 |
5704 |
|
| 278 |
5669 |
| HV *node_hv = (HV *)inner_sv; |
| 279 |
5669 |
| SV **kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 280 |
5669 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
5225 |
444 |
5669 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
5225 |
0 |
5225 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
5225 |
0 |
5225 |
|
| 281 |
10450 |
▶ | && strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
37 |
5188 |
5225 |
|
| 282 |
37 |
| SV **name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 283 |
37 |
▶ | if (name_svp && SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name_svp && SvOK(*name_svp)) { |
37 |
0 |
37 |
| if (name_svp && SvOK(*name_svp)) { |
37 |
0 |
37 |
|
| 284 |
|
| STRLEN name_len; |
| 285 |
37 |
| const char *name = SvPV(*name_svp, name_len); |
| 286 |
37 |
| (void)hv_store(spreads_hv, name, (I32)name_len, newSViv(1), 0); |
| 287 |
37 |
▶ | if (!hv_exists(visited_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(visited_hv, name, (I32)name_len)) { |
25 |
12 |
37 |
|
| 288 |
|
| HE *fragment_he; |
| 289 |
25 |
| (void)hv_store(visited_hv, name, (I32)name_len, newSViv(1), 0); |
| 290 |
25 |
| fragment_he = hv_fetch_ent(fragments_hv, *name_svp, 0, 0); |
| 291 |
25 |
▶ | if (fragment_he && SvROK(HeVAL(fragment_he)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (fragment_he && SvROK(HeVAL(fragment_he)) |
25 |
0 |
25 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) |
25 |
0 |
25 |
|
| 292 |
25 |
▶ | && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
25 |
0 |
25 |
|
| 293 |
25 |
| SV **selections_svp = hv_fetch( |
| 294 |
|
| (HV *)SvRV(HeVAL(fragment_he)), "selections", 10, 0 |
| 295 |
|
| ); |
| 296 |
25 |
▶ | if (selections_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (selections_svp) { |
25 |
0 |
25 |
|
| 297 |
25 |
| gql_validation_collect_usage( |
| 298 |
|
| aTHX_ *selections_svp, fragments_hv, variables_hv, |
| 299 |
|
| spreads_hv, visited_hv |
| 300 |
|
| ); |
| 301 |
|
| } |
| 302 |
|
| } |
| 303 |
|
| } |
| 304 |
|
| } |
| 305 |
|
| } |
| 306 |
|
| { |
| 307 |
|
| HE *he; |
| 308 |
5669 |
| hv_iterinit(node_hv); |
| 309 |
26484 |
▶ | while ((he = hv_iternext(node_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(node_hv))) { |
20815 |
5669 |
26484 |
|
| 310 |
|
| STRLEN key_len; |
| 311 |
20815 |
▶ | const char *key = HePV(he, key_len); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *key = HePV(he, key_len); |
0 |
20815 |
20815 |
|
| 312 |
20815 |
▶ | if ((key_len == 9 && memEQ(key, "variables", 9)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((key_len == 9 && memEQ(key, "variables", 9)) |
475 |
20340 |
20815 |
| if ((key_len == 9 && memEQ(key, "variables", 9)) |
348 |
127 |
475 |
|
| 313 |
20688 |
▶ | || (key_len == 8 && memEQ(key, "location", 8))) { |
Branch: 2 branches
| Branch | True | False | Total |
| || (key_len == 8 && memEQ(key, "location", 8))) { |
5230 |
15458 |
20688 |
| || (key_len == 8 && memEQ(key, "location", 8))) { |
5225 |
5 |
5230 |
|
| 314 |
5352 |
| continue; |
| 315 |
|
| } |
| 316 |
15463 |
| gql_validation_collect_usage( |
| 317 |
|
| aTHX_ HeVAL(he), fragments_hv, variables_hv, spreads_hv, visited_hv |
| 318 |
|
| ); |
| 319 |
|
| } |
| 320 |
|
| } |
| 321 |
|
| } |
| 322 |
|
| } |
| 323 |
|
| |
| 324 |
|
| static void |
| 325 |
487 |
| gql_validation_push_usage_errors( |
| 326 |
|
| pTHX_ AV *errors_av, AV *ast_av, AV *operations_av, HV *fragments_hv |
| 327 |
|
| ) { |
| 328 |
487 |
| HV *reachable_hv = newHV(); |
| 329 |
|
| I32 i; |
| 330 |
|
| |
| 331 |
977 |
▶ | for (i = 0; i <= av_len(operations_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(operations_av); i++) { |
490 |
487 |
977 |
|
| 332 |
490 |
| SV **operation_svp = av_fetch(operations_av, i, 0); |
| 333 |
|
| HV *operation_hv; |
| 334 |
490 |
| HV *used_variables_hv = newHV(); |
| 335 |
490 |
| HV *spreads_hv = newHV(); |
| 336 |
490 |
| HV *visited_hv = newHV(); |
| 337 |
|
| SV **variable_defs_svp; |
| 338 |
|
| HE *he; |
| 339 |
|
| |
| 340 |
490 |
▶ | if (!operation_svp || !SvROK(*operation_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!operation_svp || !SvROK(*operation_svp) |
490 |
0 |
490 |
| if (!operation_svp || !SvROK(*operation_svp) |
490 |
0 |
490 |
|
| 341 |
490 |
▶ | || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
0 |
490 |
490 |
|
| 342 |
0 |
| SvREFCNT_dec((SV *)used_variables_hv); |
| 343 |
0 |
| SvREFCNT_dec((SV *)spreads_hv); |
| 344 |
0 |
| SvREFCNT_dec((SV *)visited_hv); |
| 345 |
0 |
| continue; |
| 346 |
|
| } |
| 347 |
490 |
| operation_hv = (HV *)SvRV(*operation_svp); |
| 348 |
490 |
| gql_validation_collect_usage( |
| 349 |
|
| aTHX_ *operation_svp, fragments_hv, used_variables_hv, spreads_hv, visited_hv |
| 350 |
|
| ); |
| 351 |
490 |
| hv_iterinit(spreads_hv); |
| 352 |
515 |
▶ | while ((he = hv_iternext(spreads_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(spreads_hv))) { |
25 |
490 |
515 |
|
| 353 |
|
| STRLEN name_len; |
| 354 |
25 |
▶ | const char *name = HePV(he, name_len); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *name = HePV(he, name_len); |
0 |
25 |
25 |
|
| 355 |
25 |
| (void)hv_store(reachable_hv, name, (I32)name_len, newSViv(1), 0); |
| 356 |
|
| } |
| 357 |
|
| |
| 358 |
490 |
| variable_defs_svp = hv_fetch(operation_hv, "variables", 9, 0); |
| 359 |
490 |
▶ | if (variable_defs_svp && SvROK(*variable_defs_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (variable_defs_svp && SvROK(*variable_defs_svp) |
127 |
363 |
490 |
| if (variable_defs_svp && SvROK(*variable_defs_svp) |
127 |
0 |
127 |
|
| 360 |
127 |
▶ | && SvTYPE(SvRV(*variable_defs_svp)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*variable_defs_svp)) == SVt_PVHV) { |
127 |
0 |
127 |
|
| 361 |
127 |
| HV *defs_hv = (HV *)SvRV(*variable_defs_svp); |
| 362 |
127 |
| hv_iterinit(defs_hv); |
| 363 |
287 |
▶ | while ((he = hv_iternext(defs_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(defs_hv))) { |
160 |
127 |
287 |
|
| 364 |
|
| STRLEN name_len; |
| 365 |
160 |
▶ | const char *name = HePV(he, name_len); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *name = HePV(he, name_len); |
0 |
160 |
160 |
|
| 366 |
160 |
▶ | if (!hv_exists(used_variables_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(used_variables_hv, name, (I32)name_len)) { |
3 |
157 |
160 |
|
| 367 |
3 |
| SV **operation_name_svp = hv_fetch(operation_hv, "name", 4, 0); |
| 368 |
3 |
| SV **location_svp = hv_fetch(operation_hv, "location", 8, 0); |
| 369 |
3 |
▶ | const char *operation_name = operation_name_svp && SvOK(*operation_name_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| const char *operation_name = operation_name_svp && SvOK(*operation_name_svp) |
3 |
0 |
3 |
|
| 370 |
9 |
▶ | ? SvPV_nolen(*operation_name_svp) : "<anonymous>"; |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvPV_nolen(*operation_name_svp) : "<anonymous>"; |
3 |
0 |
3 |
|
| 371 |
3 |
| SV *message = newSVpvf( |
| 372 |
|
| "Variable '$%s' is never used in operation '%s'.", name, operation_name |
| 373 |
|
| ); |
| 374 |
6 |
▶ | av_push(errors_av, gql_validation_error( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error( |
3 |
0 |
3 |
|
| 375 |
|
| aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL |
| 376 |
|
| )); |
| 377 |
3 |
| SvREFCNT_dec(message); |
| 378 |
|
| } |
| 379 |
|
| } |
| 380 |
|
| } |
| 381 |
490 |
| SvREFCNT_dec((SV *)used_variables_hv); |
| 382 |
490 |
| SvREFCNT_dec((SV *)spreads_hv); |
| 383 |
490 |
| SvREFCNT_dec((SV *)visited_hv); |
| 384 |
|
| } |
| 385 |
|
| |
| 386 |
1006 |
▶ | for (i = 0; i <= av_len(ast_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(ast_av); i++) { |
519 |
487 |
1006 |
|
| 387 |
519 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 388 |
|
| HV *node_hv; |
| 389 |
|
| SV **kind_svp; |
| 390 |
|
| SV **name_svp; |
| 391 |
|
| SV **location_svp; |
| 392 |
|
| STRLEN name_len; |
| 393 |
|
| const char *name; |
| 394 |
519 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
0 |
519 |
519 |
|
| 395 |
491 |
| continue; |
| 396 |
|
| } |
| 397 |
519 |
| node_hv = (HV *)SvRV(*node_svp); |
| 398 |
519 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 399 |
519 |
| name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 400 |
519 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) |
519 |
0 |
519 |
|
| 401 |
1038 |
▶ | || !strEQ(SvPV_nolen(*kind_svp), "fragment") |
Branch: 1 branch
| Branch | True | False | Total |
| || !strEQ(SvPV_nolen(*kind_svp), "fragment") |
28 |
491 |
519 |
|
| 402 |
28 |
▶ | || !name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| || !name_svp || !SvOK(*name_svp)) { |
28 |
0 |
28 |
| || !name_svp || !SvOK(*name_svp)) { |
0 |
28 |
28 |
|
| 403 |
491 |
| continue; |
| 404 |
|
| } |
| 405 |
28 |
| name = SvPV(*name_svp, name_len); |
| 406 |
28 |
▶ | if (!hv_exists(reachable_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(reachable_hv, name, (I32)name_len)) { |
2 |
26 |
28 |
|
| 407 |
2 |
| SV *message = newSVpvf("Fragment '%s' is never used.", name); |
| 408 |
2 |
| location_svp = hv_fetch(node_hv, "location", 8, 0); |
| 409 |
4 |
▶ | av_push(errors_av, gql_validation_error( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error( |
2 |
0 |
2 |
|
| 410 |
|
| aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL |
| 411 |
|
| )); |
| 412 |
2 |
| SvREFCNT_dec(message); |
| 413 |
|
| } |
| 414 |
|
| } |
| 415 |
487 |
| SvREFCNT_dec((SV *)reachable_hv); |
| 416 |
487 |
| } |
| 417 |
|
| |
| 418 |
|
| static void |
| 419 |
4 |
| gql_validation_collect_subscription_fields(pTHX_ HV *fields_hv, SV *selections_sv, HV *fragments_hv, HV *visited_hv) { |
| 420 |
|
| AV *selections_av; |
| 421 |
|
| I32 selection_len; |
| 422 |
|
| I32 i; |
| 423 |
|
| |
| 424 |
4 |
▶ | if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
4 |
0 |
4 |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
4 |
0 |
4 |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
0 |
4 |
4 |
|
| 425 |
0 |
| return; |
| 426 |
|
| } |
| 427 |
|
| |
| 428 |
4 |
| selections_av = (AV *)SvRV(selections_sv); |
| 429 |
4 |
| selection_len = av_len(selections_av); |
| 430 |
10 |
▶ | for (i = 0; i <= selection_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= selection_len; i++) { |
6 |
4 |
10 |
|
| 431 |
6 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 432 |
|
| HV *selection_hv; |
| 433 |
|
| SV **kind_svp; |
| 434 |
|
| |
| 435 |
6 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
6 |
0 |
6 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
6 |
0 |
6 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
0 |
6 |
6 |
|
| 436 |
0 |
| continue; |
| 437 |
|
| } |
| 438 |
|
| |
| 439 |
6 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 440 |
6 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 441 |
6 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
6 |
0 |
6 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
6 |
0 |
6 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
6 |
6 |
|
| 442 |
0 |
| continue; |
| 443 |
|
| } |
| 444 |
|
| |
| 445 |
12 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
6 |
0 |
6 |
|
| 446 |
6 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 447 |
6 |
▶ | if (name_svp && SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name_svp && SvOK(*name_svp)) { |
6 |
0 |
6 |
| if (name_svp && SvOK(*name_svp)) { |
6 |
0 |
6 |
|
| 448 |
6 |
| SV **alias_svp = hv_fetch(selection_hv, "alias", 5, 0); |
| 449 |
6 |
▶ | SV *response_name_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *response_name_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
2 |
4 |
6 |
| SV *response_name_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
2 |
0 |
2 |
|
| 450 |
6 |
| (void)hv_store_ent(fields_hv, response_name_sv, newSVsv(*name_svp), 0); |
| 451 |
|
| } |
| 452 |
6 |
| continue; |
| 453 |
|
| } |
| 454 |
|
| |
| 455 |
0 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
0 |
0 |
0 |
|
| 456 |
0 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 457 |
|
| STRLEN name_len; |
| 458 |
|
| const char *name; |
| 459 |
|
| HE *fragment_he; |
| 460 |
|
| SV *fragment_sv; |
| 461 |
|
| HV *fragment_hv; |
| 462 |
|
| SV **fragment_selections_svp; |
| 463 |
|
| |
| 464 |
0 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
0 |
0 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
0 |
0 |
|
| 465 |
0 |
| continue; |
| 466 |
|
| } |
| 467 |
|
| |
| 468 |
0 |
| name = SvPV(*name_svp, name_len); |
| 469 |
0 |
▶ | if (hv_exists(visited_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(visited_hv, name, (I32)name_len)) { |
0 |
0 |
0 |
|
| 470 |
0 |
| continue; |
| 471 |
|
| } |
| 472 |
|
| |
| 473 |
0 |
| fragment_he = hv_fetch_ent(fragments_hv, *name_svp, 0, 0); |
| 474 |
0 |
▶ | if (!fragment_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fragment_he) { |
0 |
0 |
0 |
|
| 475 |
0 |
| continue; |
| 476 |
|
| } |
| 477 |
|
| |
| 478 |
0 |
| fragment_sv = HeVAL(fragment_he); |
| 479 |
0 |
▶ | if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 480 |
0 |
| continue; |
| 481 |
|
| } |
| 482 |
|
| |
| 483 |
0 |
| (void)hv_store(visited_hv, name, (I32)name_len, newSViv(1), 0); |
| 484 |
0 |
| fragment_hv = (HV *)SvRV(fragment_sv); |
| 485 |
0 |
| fragment_selections_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 486 |
0 |
▶ | gql_validation_collect_subscription_fields( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_collect_subscription_fields( |
0 |
0 |
0 |
|
| 487 |
|
| aTHX_ fields_hv, |
| 488 |
|
| fragment_selections_svp ? *fragment_selections_svp : NULL, |
| 489 |
|
| fragments_hv, |
| 490 |
|
| visited_hv |
| 491 |
|
| ); |
| 492 |
0 |
| (void)hv_delete(visited_hv, name, (I32)name_len, G_DISCARD); |
| 493 |
0 |
| continue; |
| 494 |
|
| } |
| 495 |
|
| |
| 496 |
0 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
0 |
0 |
0 |
|
| 497 |
0 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 498 |
0 |
▶ | gql_validation_collect_subscription_fields( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_collect_subscription_fields( |
0 |
0 |
0 |
|
| 499 |
|
| aTHX_ fields_hv, |
| 500 |
|
| nested_svp ? *nested_svp : NULL, |
| 501 |
|
| fragments_hv, |
| 502 |
|
| visited_hv |
| 503 |
|
| ); |
| 504 |
|
| } |
| 505 |
|
| } |
| 506 |
|
| } |
| 507 |
|
| |
| 508 |
|
| static void |
| 509 |
150 |
| gql_validation_collect_fragment_spreads(pTHX_ AV *names_av, SV *selections_sv) { |
| 510 |
|
| AV *selections_av; |
| 511 |
|
| I32 selection_len; |
| 512 |
|
| I32 i; |
| 513 |
|
| |
| 514 |
150 |
▶ | if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
62 |
88 |
150 |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
62 |
0 |
62 |
| if (!selections_sv || !SvROK(selections_sv) || SvTYPE(SvRV(selections_sv)) != SVt_PVAV) { |
0 |
62 |
62 |
|
| 515 |
88 |
| return; |
| 516 |
|
| } |
| 517 |
|
| |
| 518 |
62 |
| selections_av = (AV *)SvRV(selections_sv); |
| 519 |
62 |
| selection_len = av_len(selections_av); |
| 520 |
200 |
▶ | for (i = 0; i <= selection_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= selection_len; i++) { |
138 |
62 |
200 |
|
| 521 |
138 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 522 |
|
| HV *selection_hv; |
| 523 |
|
| SV **kind_svp; |
| 524 |
|
| |
| 525 |
138 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
138 |
0 |
138 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
138 |
0 |
138 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
0 |
138 |
138 |
|
| 526 |
0 |
| continue; |
| 527 |
|
| } |
| 528 |
|
| |
| 529 |
138 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 530 |
138 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 531 |
138 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
138 |
0 |
138 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
138 |
0 |
138 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
138 |
138 |
|
| 532 |
0 |
| continue; |
| 533 |
|
| } |
| 534 |
|
| |
| 535 |
276 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
15 |
123 |
138 |
|
| 536 |
15 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 537 |
15 |
▶ | if (name_svp && SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name_svp && SvOK(*name_svp)) { |
15 |
0 |
15 |
| if (name_svp && SvOK(*name_svp)) { |
15 |
0 |
15 |
|
| 538 |
15 |
| av_push(names_av, newSVsv(*name_svp)); |
| 539 |
|
| } |
| 540 |
15 |
| continue; |
| 541 |
|
| } |
| 542 |
|
| |
| 543 |
246 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "field") || strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "field") || strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
0 |
123 |
123 |
| if (strEQ(SvPV_nolen(*kind_svp), "field") || strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
0 |
0 |
0 |
|
| 544 |
123 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 545 |
123 |
▶ | gql_validation_collect_fragment_spreads(aTHX_ names_av, nested_svp ? *nested_svp : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_collect_fragment_spreads(aTHX_ names_av, nested_svp ? *nested_svp : NULL); |
35 |
88 |
123 |
|
| 546 |
|
| } |
| 547 |
|
| } |
| 548 |
|
| } |
| 549 |
|
| |
| 550 |
|
| static void |
| 551 |
42 |
| gql_validation_visit_fragment_cycles(pTHX_ AV *errors_av, HV *fragments_hv, HV *state_hv, SV *name_key_sv) { |
| 552 |
|
| STRLEN name_len; |
| 553 |
|
| const char *name; |
| 554 |
|
| HE *fragment_he; |
| 555 |
|
| SV *fragment_sv; |
| 556 |
|
| HV *fragment_hv; |
| 557 |
|
| HE *state_he; |
| 558 |
|
| const char *state; |
| 559 |
|
| SV **selections_svp; |
| 560 |
42 |
| AV *spreads_av = newAV(); |
| 561 |
|
| I32 spread_len; |
| 562 |
|
| I32 i; |
| 563 |
|
| SV **location_svp; |
| 564 |
|
| |
| 565 |
42 |
▶ | if (!name_key_sv || !SvOK(name_key_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_key_sv || !SvOK(name_key_sv)) { |
42 |
0 |
42 |
| if (!name_key_sv || !SvOK(name_key_sv)) { |
0 |
42 |
42 |
|
| 566 |
0 |
| SvREFCNT_dec((SV *)spreads_av); |
| 567 |
15 |
| return; |
| 568 |
|
| } |
| 569 |
|
| |
| 570 |
42 |
| name = SvPV(name_key_sv, name_len); |
| 571 |
42 |
| fragment_he = hv_fetch_ent(fragments_hv, name_key_sv, 0, 0); |
| 572 |
42 |
▶ | if (!fragment_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fragment_he) { |
0 |
42 |
42 |
|
| 573 |
0 |
| SvREFCNT_dec((SV *)spreads_av); |
| 574 |
0 |
| return; |
| 575 |
|
| } |
| 576 |
|
| |
| 577 |
42 |
| state_he = hv_fetch_ent(state_hv, name_key_sv, 0, 0); |
| 578 |
42 |
▶ | if (state_he && SvOK(HeVAL(state_he))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_he && SvOK(HeVAL(state_he))) { |
15 |
27 |
42 |
| if (state_he && SvOK(HeVAL(state_he))) { |
15 |
0 |
15 |
|
| 579 |
15 |
| state = SvPV_nolen(HeVAL(state_he)); |
| 580 |
15 |
▶ | if (strEQ(state, "done")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(state, "done")) { |
14 |
1 |
15 |
|
| 581 |
14 |
| SvREFCNT_dec((SV *)spreads_av); |
| 582 |
14 |
| return; |
| 583 |
|
| } |
| 584 |
1 |
▶ | if (strEQ(state, "visiting")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(state, "visiting")) { |
1 |
0 |
1 |
|
| 585 |
1 |
| fragment_sv = HeVAL(fragment_he); |
| 586 |
1 |
▶ | if (SvROK(fragment_sv) && SvTYPE(SvRV(fragment_sv)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(fragment_sv) && SvTYPE(SvRV(fragment_sv)) == SVt_PVHV) { |
1 |
0 |
1 |
| if (SvROK(fragment_sv) && SvTYPE(SvRV(fragment_sv)) == SVt_PVHV) { |
1 |
0 |
1 |
|
| 587 |
1 |
| fragment_hv = (HV *)SvRV(fragment_sv); |
| 588 |
1 |
| location_svp = hv_fetch(fragment_hv, "location", 8, 0); |
| 589 |
|
| { |
| 590 |
1 |
| SV *message = newSVpvf("Fragment '%s' participates in a cycle.", name); |
| 591 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
1 |
0 |
1 |
|
| 592 |
1 |
| SvREFCNT_dec(message); |
| 593 |
|
| } |
| 594 |
|
| } |
| 595 |
1 |
| SvREFCNT_dec((SV *)spreads_av); |
| 596 |
1 |
| return; |
| 597 |
|
| } |
| 598 |
|
| } |
| 599 |
|
| |
| 600 |
27 |
| (void)hv_store(state_hv, name, (I32)name_len, newSVpv("visiting", 0), 0); |
| 601 |
27 |
| fragment_sv = HeVAL(fragment_he); |
| 602 |
27 |
▶ | if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
27 |
0 |
27 |
| if (!SvROK(fragment_sv) || SvTYPE(SvRV(fragment_sv)) != SVt_PVHV) { |
0 |
27 |
27 |
|
| 603 |
0 |
| (void)hv_store(state_hv, name, (I32)name_len, newSVpv("done", 0), 0); |
| 604 |
0 |
| SvREFCNT_dec((SV *)spreads_av); |
| 605 |
0 |
| return; |
| 606 |
|
| } |
| 607 |
|
| |
| 608 |
27 |
| fragment_hv = (HV *)SvRV(fragment_sv); |
| 609 |
27 |
| selections_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 610 |
27 |
▶ | gql_validation_collect_fragment_spreads(aTHX_ spreads_av, selections_svp ? *selections_svp : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_collect_fragment_spreads(aTHX_ spreads_av, selections_svp ? *selections_svp : NULL); |
27 |
0 |
27 |
|
| 611 |
|
| |
| 612 |
27 |
| spread_len = av_len(spreads_av); |
| 613 |
42 |
▶ | for (i = 0; i <= spread_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= spread_len; i++) { |
15 |
27 |
42 |
|
| 614 |
15 |
| SV **spread_name_svp = av_fetch(spreads_av, i, 0); |
| 615 |
15 |
▶ | if (!spread_name_svp || !SvOK(*spread_name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!spread_name_svp || !SvOK(*spread_name_svp)) { |
15 |
0 |
15 |
| if (!spread_name_svp || !SvOK(*spread_name_svp)) { |
0 |
15 |
15 |
|
| 616 |
0 |
| continue; |
| 617 |
|
| } |
| 618 |
15 |
| gql_validation_visit_fragment_cycles(aTHX_ errors_av, fragments_hv, state_hv, *spread_name_svp); |
| 619 |
|
| } |
| 620 |
|
| |
| 621 |
27 |
| (void)hv_store(state_hv, name, (I32)name_len, newSVpv("done", 0), 0); |
| 622 |
27 |
| SvREFCNT_dec((SV *)spreads_av); |
| 623 |
|
| } |
| 624 |
|
| |
| 625 |
|
| static void |
| 626 |
487 |
| gql_validation_push_fragment_cycle_errors(pTHX_ AV *errors_av, HV *fragments_hv) { |
| 627 |
|
| I32 fragment_count; |
| 628 |
|
| I32 i; |
| 629 |
|
| SV **keys; |
| 630 |
487 |
| HV *state_hv = newHV(); |
| 631 |
|
| |
| 632 |
487 |
| keys = gql_parser_sorted_hash_keys(aTHX_ fragments_hv, &fragment_count); |
| 633 |
487 |
▶ | if (!keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!keys) { |
468 |
19 |
487 |
|
| 634 |
468 |
| SvREFCNT_dec((SV *)state_hv); |
| 635 |
468 |
| return; |
| 636 |
|
| } |
| 637 |
|
| |
| 638 |
46 |
▶ | for (i = 0; i < fragment_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < fragment_count; i++) { |
27 |
19 |
46 |
|
| 639 |
27 |
| gql_validation_visit_fragment_cycles(aTHX_ errors_av, fragments_hv, state_hv, keys[i]); |
| 640 |
|
| } |
| 641 |
|
| |
| 642 |
19 |
| gql_parser_free_sorted_hash_keys(keys, fragment_count); |
| 643 |
19 |
| SvREFCNT_dec((SV *)state_hv); |
| 644 |
|
| } |
| 645 |
|
| |
| 646 |
|
| static void |
| 647 |
487 |
| gql_validation_push_subscription_errors(pTHX_ AV *operation_errors_av, AV *operations_av, HV *fragments_hv) { |
| 648 |
487 |
| I32 operation_len = av_len(operations_av); |
| 649 |
|
| I32 i; |
| 650 |
|
| |
| 651 |
977 |
▶ | for (i = 0; i <= operation_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= operation_len; i++) { |
490 |
487 |
977 |
|
| 652 |
490 |
| SV **operation_svp = av_fetch(operations_av, i, 0); |
| 653 |
490 |
| AV *errors_av = newAV(); |
| 654 |
|
| HV *operation_hv; |
| 655 |
|
| SV **operation_type_svp; |
| 656 |
|
| |
| 657 |
490 |
| av_push(operation_errors_av, newRV_noinc((SV *)errors_av)); |
| 658 |
|
| |
| 659 |
490 |
▶ | if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
490 |
0 |
490 |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
490 |
0 |
490 |
| if (!operation_svp || !SvROK(*operation_svp) || SvTYPE(SvRV(*operation_svp)) != SVt_PVHV) { |
0 |
490 |
490 |
|
| 660 |
0 |
| continue; |
| 661 |
|
| } |
| 662 |
|
| |
| 663 |
490 |
| operation_hv = (HV *)SvRV(*operation_svp); |
| 664 |
490 |
| operation_type_svp = hv_fetch(operation_hv, "operationType", 13, 0); |
| 665 |
490 |
▶ | if (operation_type_svp && SvOK(*operation_type_svp) && SvPOK(*operation_type_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (operation_type_svp && SvOK(*operation_type_svp) && SvPOK(*operation_type_svp) |
164 |
326 |
490 |
| if (operation_type_svp && SvOK(*operation_type_svp) && SvPOK(*operation_type_svp) |
164 |
0 |
164 |
| if (operation_type_svp && SvOK(*operation_type_svp) && SvPOK(*operation_type_svp) |
164 |
0 |
164 |
|
| 666 |
328 |
▶ | && strEQ(SvPV_nolen(*operation_type_svp), "subscription")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*operation_type_svp), "subscription")) { |
4 |
160 |
164 |
|
| 667 |
4 |
| HV *fields_hv = newHV(); |
| 668 |
4 |
| HV *visited_hv = newHV(); |
| 669 |
4 |
| SV **selections_svp = hv_fetch(operation_hv, "selections", 10, 0); |
| 670 |
4 |
| SV **location_svp = hv_fetch(operation_hv, "location", 8, 0); |
| 671 |
|
| I32 field_count; |
| 672 |
|
| |
| 673 |
4 |
▶ | gql_validation_collect_subscription_fields( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_collect_subscription_fields( |
4 |
0 |
4 |
|
| 674 |
|
| aTHX_ fields_hv, |
| 675 |
|
| selections_svp ? *selections_svp : NULL, |
| 676 |
|
| fragments_hv, |
| 677 |
|
| visited_hv |
| 678 |
|
| ); |
| 679 |
4 |
▶ | field_count = (I32)HvUSEDKEYS(fields_hv); |
Branch: 1 branch
| Branch | True | False | Total |
| field_count = (I32)HvUSEDKEYS(fields_hv); |
0 |
4 |
4 |
|
| 680 |
4 |
▶ | if (field_count != 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (field_count != 1) { |
1 |
3 |
4 |
|
| 681 |
1 |
| SV *message = newSVpv("Subscription needs to have only one field; got (", 0); |
| 682 |
1 |
| I32 sorted_count = 0; |
| 683 |
1 |
| SV **keys = gql_parser_sorted_hash_keys(aTHX_ fields_hv, &sorted_count); |
| 684 |
|
| I32 j; |
| 685 |
3 |
▶ | for (j = 0; j < sorted_count; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < sorted_count; j++) { |
2 |
1 |
3 |
|
| 686 |
2 |
▶ | if (j > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (j > 0) { |
1 |
1 |
2 |
|
| 687 |
1 |
| sv_catpvn(message, " ", 1); |
| 688 |
|
| } |
| 689 |
2 |
| sv_catsv(message, keys[j]); |
| 690 |
|
| } |
| 691 |
1 |
| sv_catpvn(message, ")", 1); |
| 692 |
2 |
▶ | av_push( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push( |
1 |
0 |
1 |
|
| 693 |
|
| errors_av, |
| 694 |
|
| gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL) |
| 695 |
|
| ); |
| 696 |
1 |
| SvREFCNT_dec(message); |
| 697 |
1 |
| gql_parser_free_sorted_hash_keys(keys, sorted_count); |
| 698 |
|
| } else { |
| 699 |
|
| HE *field_he; |
| 700 |
3 |
| hv_iterinit(fields_hv); |
| 701 |
3 |
| field_he = hv_iternext(fields_hv); |
| 702 |
3 |
▶ | if (field_he && HeVAL(field_he) && SvOK(HeVAL(field_he)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (field_he && HeVAL(field_he) && SvOK(HeVAL(field_he)) |
3 |
0 |
3 |
| if (field_he && HeVAL(field_he) && SvOK(HeVAL(field_he)) |
3 |
0 |
3 |
| if (field_he && HeVAL(field_he) && SvOK(HeVAL(field_he)) |
3 |
0 |
3 |
|
| 703 |
6 |
▶ | && strnEQ(SvPV_nolen(HeVAL(field_he)), "__", 2)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strnEQ(SvPV_nolen(HeVAL(field_he)), "__", 2)) { |
1 |
2 |
3 |
|
| 704 |
1 |
| SV *message = newSVpv("Subscription root field must not be an introspection field.", 0); |
| 705 |
2 |
▶ | av_push( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push( |
1 |
0 |
1 |
|
| 706 |
|
| errors_av, |
| 707 |
|
| gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL) |
| 708 |
|
| ); |
| 709 |
1 |
| SvREFCNT_dec(message); |
| 710 |
|
| } |
| 711 |
|
| } |
| 712 |
|
| |
| 713 |
4 |
| SvREFCNT_dec((SV *)visited_hv); |
| 714 |
4 |
| SvREFCNT_dec((SV *)fields_hv); |
| 715 |
|
| } |
| 716 |
|
| } |
| 717 |
487 |
| } |
| 718 |
|
| |
| 719 |
|
| static HV * |
| 720 |
27314 |
| gql_validation_compiled_hv_from_sv(SV *compiled_sv) { |
| 721 |
27314 |
▶ | if (!compiled_sv || !SvROK(compiled_sv) || SvTYPE(SvRV(compiled_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!compiled_sv || !SvROK(compiled_sv) || SvTYPE(SvRV(compiled_sv)) != SVt_PVHV) { |
27314 |
0 |
27314 |
| if (!compiled_sv || !SvROK(compiled_sv) || SvTYPE(SvRV(compiled_sv)) != SVt_PVHV) { |
27314 |
0 |
27314 |
| if (!compiled_sv || !SvROK(compiled_sv) || SvTYPE(SvRV(compiled_sv)) != SVt_PVHV) { |
0 |
27314 |
27314 |
|
| 722 |
0 |
| return NULL; |
| 723 |
|
| } |
| 724 |
27314 |
| return (HV *)SvRV(compiled_sv); |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
|
| static HV * |
| 728 |
20887 |
| gql_validation_compiled_type_hv(pTHX_ SV *compiled_sv, SV *type_name_sv) { |
| 729 |
20887 |
| HV *compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 730 |
|
| SV **types_svp; |
| 731 |
|
| HE *type_he; |
| 732 |
|
| |
| 733 |
20887 |
▶ | if (!compiled_hv || !type_name_sv || !SvOK(type_name_sv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!compiled_hv || !type_name_sv || !SvOK(type_name_sv)) { |
20887 |
0 |
20887 |
| if (!compiled_hv || !type_name_sv || !SvOK(type_name_sv)) { |
20887 |
0 |
20887 |
| if (!compiled_hv || !type_name_sv || !SvOK(type_name_sv)) { |
0 |
20887 |
20887 |
|
| 734 |
0 |
| return NULL; |
| 735 |
|
| } |
| 736 |
|
| |
| 737 |
20887 |
| types_svp = hv_fetch(compiled_hv, "types", 5, 0); |
| 738 |
20887 |
▶ | if (!types_svp || !SvROK(*types_svp) || SvTYPE(SvRV(*types_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!types_svp || !SvROK(*types_svp) || SvTYPE(SvRV(*types_svp)) != SVt_PVHV) { |
20887 |
0 |
20887 |
| if (!types_svp || !SvROK(*types_svp) || SvTYPE(SvRV(*types_svp)) != SVt_PVHV) { |
20887 |
0 |
20887 |
| if (!types_svp || !SvROK(*types_svp) || SvTYPE(SvRV(*types_svp)) != SVt_PVHV) { |
0 |
20887 |
20887 |
|
| 739 |
0 |
| return NULL; |
| 740 |
|
| } |
| 741 |
|
| |
| 742 |
20887 |
| type_he = hv_fetch_ent((HV *)SvRV(*types_svp), type_name_sv, 0, 0); |
| 743 |
20887 |
▶ | if (!type_he || !SvROK(HeVAL(type_he)) || SvTYPE(SvRV(HeVAL(type_he))) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_he || !SvROK(HeVAL(type_he)) || SvTYPE(SvRV(HeVAL(type_he))) != SVt_PVHV) { |
20884 |
3 |
20887 |
| if (!type_he || !SvROK(HeVAL(type_he)) || SvTYPE(SvRV(HeVAL(type_he))) != SVt_PVHV) { |
20884 |
0 |
20884 |
| if (!type_he || !SvROK(HeVAL(type_he)) || SvTYPE(SvRV(HeVAL(type_he))) != SVt_PVHV) { |
0 |
20884 |
20884 |
|
| 744 |
3 |
| return NULL; |
| 745 |
|
| } |
| 746 |
|
| |
| 747 |
20884 |
| return (HV *)SvRV(HeVAL(type_he)); |
| 748 |
|
| } |
| 749 |
|
| |
| 750 |
|
| static SV * |
| 751 |
7632 |
| gql_validation_named_type_name_sv(SV *type_ref_sv) { |
| 752 |
|
| HV *type_ref_hv; |
| 753 |
|
| SV **kind_svp; |
| 754 |
|
| SV **name_svp; |
| 755 |
|
| SV **of_svp; |
| 756 |
|
| |
| 757 |
7632 |
▶ | if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
7632 |
0 |
7632 |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
7632 |
0 |
7632 |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
0 |
7632 |
7632 |
|
| 758 |
0 |
| return NULL; |
| 759 |
|
| } |
| 760 |
|
| |
| 761 |
7632 |
| type_ref_hv = (HV *)SvRV(type_ref_sv); |
| 762 |
7632 |
| kind_svp = hv_fetch(type_ref_hv, "kind", 4, 0); |
| 763 |
15264 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NAMED")) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NAMED")) { |
7632 |
0 |
7632 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NAMED")) { |
7632 |
0 |
7632 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NAMED")) { |
7632 |
0 |
7632 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NAMED")) { |
6112 |
1520 |
7632 |
|
| 764 |
6112 |
| name_svp = hv_fetch(type_ref_hv, "name", 4, 0); |
| 765 |
6112 |
▶ | return name_svp ? *name_svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return name_svp ? *name_svp : NULL; |
6112 |
0 |
6112 |
|
| 766 |
|
| } |
| 767 |
|
| |
| 768 |
1520 |
| of_svp = hv_fetch(type_ref_hv, "of", 2, 0); |
| 769 |
1520 |
▶ | return of_svp ? gql_validation_named_type_name_sv(*of_svp) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return of_svp ? gql_validation_named_type_name_sv(*of_svp) : NULL; |
1520 |
0 |
1520 |
|
| 770 |
|
| } |
| 771 |
|
| |
| 772 |
|
| static int |
| 773 |
408 |
| gql_validation_type_is_non_null(SV *type_ref_sv) { |
| 774 |
|
| HV *type_ref_hv; |
| 775 |
|
| SV **kind_svp; |
| 776 |
|
| |
| 777 |
408 |
▶ | if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
408 |
0 |
408 |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
408 |
0 |
408 |
| if (!type_ref_sv || !SvROK(type_ref_sv) || SvTYPE(SvRV(type_ref_sv)) != SVt_PVHV) { |
0 |
408 |
408 |
|
| 778 |
0 |
| return 0; |
| 779 |
|
| } |
| 780 |
|
| |
| 781 |
408 |
| type_ref_hv = (HV *)SvRV(type_ref_sv); |
| 782 |
408 |
| kind_svp = hv_fetch(type_ref_hv, "kind", 4, 0); |
| 783 |
816 |
▶ | return kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NON_NULL"); |
Branch: 4 branches
| Branch | True | False | Total |
| return kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NON_NULL"); |
408 |
0 |
408 |
| return kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NON_NULL"); |
408 |
0 |
408 |
| return kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NON_NULL"); |
408 |
0 |
408 |
| return kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "NON_NULL"); |
56 |
352 |
408 |
|
| 784 |
|
| } |
| 785 |
|
| |
| 786 |
|
| static void |
| 787 |
144 |
| gql_validation_add_possible_object_names(pTHX_ HV *out_hv, SV *compiled_sv, SV *type_name_sv) { |
| 788 |
144 |
| HV *type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, type_name_sv); |
| 789 |
|
| SV **kind_svp; |
| 790 |
|
| |
| 791 |
144 |
▶ | if (!type_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!type_hv) { |
0 |
144 |
144 |
|
| 792 |
0 |
| return; |
| 793 |
|
| } |
| 794 |
|
| |
| 795 |
144 |
| kind_svp = hv_fetch(type_hv, "kind", 4, 0); |
| 796 |
144 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
144 |
0 |
144 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
144 |
0 |
144 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
144 |
144 |
|
| 797 |
0 |
| return; |
| 798 |
|
| } |
| 799 |
|
| |
| 800 |
288 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "OBJECT")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "OBJECT")) { |
113 |
31 |
144 |
|
| 801 |
|
| STRLEN len; |
| 802 |
113 |
| const char *name = SvPV(type_name_sv, len); |
| 803 |
113 |
| (void)hv_store(out_hv, name, (I32)len, newSViv(1), 0); |
| 804 |
113 |
| return; |
| 805 |
|
| } |
| 806 |
|
| |
| 807 |
80 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "INTERFACE") || strEQ(SvPV_nolen(*kind_svp), "UNION")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "INTERFACE") || strEQ(SvPV_nolen(*kind_svp), "UNION")) { |
18 |
13 |
31 |
| if (strEQ(SvPV_nolen(*kind_svp), "INTERFACE") || strEQ(SvPV_nolen(*kind_svp), "UNION")) { |
18 |
0 |
18 |
|
| 808 |
31 |
| HV *compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 809 |
|
| SV **possible_types_svp; |
| 810 |
|
| HE *possible_he; |
| 811 |
|
| AV *possible_av; |
| 812 |
|
| I32 i; |
| 813 |
|
| |
| 814 |
31 |
▶ | if (!compiled_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!compiled_hv) { |
0 |
31 |
31 |
|
| 815 |
0 |
| return; |
| 816 |
|
| } |
| 817 |
|
| |
| 818 |
31 |
| possible_types_svp = hv_fetch(compiled_hv, "possible_types", 14, 0); |
| 819 |
31 |
▶ | if (!possible_types_svp || !SvROK(*possible_types_svp) || SvTYPE(SvRV(*possible_types_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!possible_types_svp || !SvROK(*possible_types_svp) || SvTYPE(SvRV(*possible_types_svp)) != SVt_PVHV) { |
31 |
0 |
31 |
| if (!possible_types_svp || !SvROK(*possible_types_svp) || SvTYPE(SvRV(*possible_types_svp)) != SVt_PVHV) { |
31 |
0 |
31 |
| if (!possible_types_svp || !SvROK(*possible_types_svp) || SvTYPE(SvRV(*possible_types_svp)) != SVt_PVHV) { |
0 |
31 |
31 |
|
| 820 |
0 |
| return; |
| 821 |
|
| } |
| 822 |
|
| |
| 823 |
31 |
| possible_he = hv_fetch_ent((HV *)SvRV(*possible_types_svp), type_name_sv, 0, 0); |
| 824 |
31 |
▶ | if (!possible_he || !SvROK(HeVAL(possible_he)) || SvTYPE(SvRV(HeVAL(possible_he))) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!possible_he || !SvROK(HeVAL(possible_he)) || SvTYPE(SvRV(HeVAL(possible_he))) != SVt_PVAV) { |
31 |
0 |
31 |
| if (!possible_he || !SvROK(HeVAL(possible_he)) || SvTYPE(SvRV(HeVAL(possible_he))) != SVt_PVAV) { |
31 |
0 |
31 |
| if (!possible_he || !SvROK(HeVAL(possible_he)) || SvTYPE(SvRV(HeVAL(possible_he))) != SVt_PVAV) { |
0 |
31 |
31 |
|
| 825 |
0 |
| return; |
| 826 |
|
| } |
| 827 |
|
| |
| 828 |
31 |
| possible_av = (AV *)SvRV(HeVAL(possible_he)); |
| 829 |
91 |
▶ | for (i = 0; i <= av_len(possible_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(possible_av); i++) { |
60 |
31 |
91 |
|
| 830 |
60 |
| SV **possible_name_svp = av_fetch(possible_av, i, 0); |
| 831 |
60 |
▶ | if (possible_name_svp && SvOK(*possible_name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (possible_name_svp && SvOK(*possible_name_svp)) { |
60 |
0 |
60 |
| if (possible_name_svp && SvOK(*possible_name_svp)) { |
60 |
0 |
60 |
|
| 832 |
60 |
| gql_validation_add_possible_object_names(aTHX_ out_hv, compiled_sv, *possible_name_svp); |
| 833 |
|
| } |
| 834 |
|
| } |
| 835 |
|
| } |
| 836 |
|
| } |
| 837 |
|
| |
| 838 |
|
| static int |
| 839 |
3079 |
| gql_validation_selection_types_overlap(pTHX_ SV *compiled_sv, SV *left_name_sv, SV *right_name_sv) { |
| 840 |
3079 |
| HV *left_objects_hv = newHV(); |
| 841 |
3079 |
| int overlap = 0; |
| 842 |
3079 |
| HV *right_objects_hv = newHV(); |
| 843 |
|
| HE *he; |
| 844 |
|
| |
| 845 |
3079 |
▶ | if (!left_name_sv || !right_name_sv || !SvOK(left_name_sv) || !SvOK(right_name_sv)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!left_name_sv || !right_name_sv || !SvOK(left_name_sv) || !SvOK(right_name_sv)) { |
3079 |
0 |
3079 |
| if (!left_name_sv || !right_name_sv || !SvOK(left_name_sv) || !SvOK(right_name_sv)) { |
3079 |
0 |
3079 |
| if (!left_name_sv || !right_name_sv || !SvOK(left_name_sv) || !SvOK(right_name_sv)) { |
3079 |
0 |
3079 |
| if (!left_name_sv || !right_name_sv || !SvOK(left_name_sv) || !SvOK(right_name_sv)) { |
0 |
3079 |
3079 |
|
| 846 |
0 |
| SvREFCNT_dec((SV *)left_objects_hv); |
| 847 |
0 |
| SvREFCNT_dec((SV *)right_objects_hv); |
| 848 |
0 |
| return 0; |
| 849 |
|
| } |
| 850 |
|
| |
| 851 |
3079 |
▶ | if (sv_eq(left_name_sv, right_name_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_eq(left_name_sv, right_name_sv)) { |
3037 |
42 |
3079 |
|
| 852 |
3037 |
| SvREFCNT_dec((SV *)left_objects_hv); |
| 853 |
3037 |
| SvREFCNT_dec((SV *)right_objects_hv); |
| 854 |
3037 |
| return 1; |
| 855 |
|
| } |
| 856 |
|
| |
| 857 |
42 |
| gql_validation_add_possible_object_names(aTHX_ left_objects_hv, compiled_sv, left_name_sv); |
| 858 |
42 |
| gql_validation_add_possible_object_names(aTHX_ right_objects_hv, compiled_sv, right_name_sv); |
| 859 |
|
| |
| 860 |
42 |
| hv_iterinit(right_objects_hv); |
| 861 |
53 |
▶ | while ((he = hv_iternext(right_objects_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(right_objects_hv))) { |
42 |
11 |
53 |
|
| 862 |
|
| STRLEN key_len; |
| 863 |
42 |
▶ | const char *key = HePV(he, key_len); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *key = HePV(he, key_len); |
0 |
42 |
42 |
|
| 864 |
42 |
▶ | if (hv_exists(left_objects_hv, key, (I32)key_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(left_objects_hv, key, (I32)key_len)) { |
31 |
11 |
42 |
|
| 865 |
31 |
| overlap = 1; |
| 866 |
31 |
| break; |
| 867 |
|
| } |
| 868 |
|
| } |
| 869 |
|
| |
| 870 |
42 |
| SvREFCNT_dec((SV *)left_objects_hv); |
| 871 |
42 |
| SvREFCNT_dec((SV *)right_objects_hv); |
| 872 |
42 |
| return overlap; |
| 873 |
|
| } |
| 874 |
|
| |
| 875 |
|
| static void gql_validation_validate_value( |
| 876 |
|
| pTHX_ AV *errors_av, |
| 877 |
|
| SV *schema, |
| 878 |
|
| SV *compiled_sv, |
| 879 |
|
| SV *value_sv, |
| 880 |
|
| SV *expected_type_sv, |
| 881 |
|
| HV *variables_hv, |
| 882 |
|
| SV *location_sv |
| 883 |
|
| ); |
| 884 |
|
| |
| 885 |
|
| static int |
| 886 |
458 |
| gql_validation_variable_type_is_kind(SV *type_sv, const char *wanted) { |
| 887 |
458 |
▶ | if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
458 |
0 |
458 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
131 |
327 |
458 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
0 |
131 |
131 |
|
| 888 |
327 |
| return 0; |
| 889 |
|
| } |
| 890 |
|
| { |
| 891 |
131 |
| SV **kind_svp = av_fetch((AV *)SvRV(type_sv), 0, 0); |
| 892 |
262 |
▶ | return kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), wanted); |
Branch: 3 branches
| Branch | True | False | Total |
| return kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), wanted); |
131 |
0 |
131 |
| return kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), wanted); |
131 |
0 |
131 |
| return kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), wanted); |
103 |
28 |
131 |
|
| 893 |
|
| } |
| 894 |
|
| } |
| 895 |
|
| |
| 896 |
|
| static SV * |
| 897 |
69 |
| gql_validation_variable_type_inner(SV *type_sv) { |
| 898 |
|
| SV **wrapper_svp; |
| 899 |
|
| SV **inner_svp; |
| 900 |
69 |
▶ | if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
69 |
0 |
69 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
69 |
0 |
69 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVAV) { |
0 |
69 |
69 |
|
| 901 |
0 |
| return NULL; |
| 902 |
|
| } |
| 903 |
69 |
| wrapper_svp = av_fetch((AV *)SvRV(type_sv), 1, 0); |
| 904 |
69 |
▶ | if (!wrapper_svp || !SvROK(*wrapper_svp) || SvTYPE(SvRV(*wrapper_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!wrapper_svp || !SvROK(*wrapper_svp) || SvTYPE(SvRV(*wrapper_svp)) != SVt_PVHV) { |
69 |
0 |
69 |
| if (!wrapper_svp || !SvROK(*wrapper_svp) || SvTYPE(SvRV(*wrapper_svp)) != SVt_PVHV) { |
69 |
0 |
69 |
| if (!wrapper_svp || !SvROK(*wrapper_svp) || SvTYPE(SvRV(*wrapper_svp)) != SVt_PVHV) { |
0 |
69 |
69 |
|
| 905 |
0 |
| return NULL; |
| 906 |
|
| } |
| 907 |
69 |
| inner_svp = hv_fetch((HV *)SvRV(*wrapper_svp), "type", 4, 0); |
| 908 |
69 |
▶ | return inner_svp ? *inner_svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return inner_svp ? *inner_svp : NULL; |
69 |
0 |
69 |
|
| 909 |
|
| } |
| 910 |
|
| |
| 911 |
|
| static int |
| 912 |
229 |
| gql_validation_variable_type_compatible(SV *variable_type, SV *location_type) { |
| 913 |
|
| HV *location_hv; |
| 914 |
|
| SV **kind_svp; |
| 915 |
|
| const char *kind; |
| 916 |
229 |
▶ | if (!variable_type || !location_type || !SvROK(location_type) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!variable_type || !location_type || !SvROK(location_type) |
229 |
0 |
229 |
| if (!variable_type || !location_type || !SvROK(location_type) |
229 |
0 |
229 |
| if (!variable_type || !location_type || !SvROK(location_type) |
229 |
0 |
229 |
|
| 917 |
229 |
▶ | || SvTYPE(SvRV(location_type)) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(location_type)) != SVt_PVHV) { |
0 |
229 |
229 |
|
| 918 |
0 |
| return 0; |
| 919 |
|
| } |
| 920 |
229 |
| location_hv = (HV *)SvRV(location_type); |
| 921 |
229 |
| kind_svp = hv_fetch(location_hv, "kind", 4, 0); |
| 922 |
229 |
▶ | if (!kind_svp || !SvOK(*kind_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp)) { |
229 |
0 |
229 |
| if (!kind_svp || !SvOK(*kind_svp)) { |
0 |
229 |
229 |
|
| 923 |
0 |
| return 0; |
| 924 |
|
| } |
| 925 |
229 |
| kind = SvPV_nolen(*kind_svp); |
| 926 |
229 |
▶ | if (strEQ(kind, "NON_NULL")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "NON_NULL")) { |
40 |
189 |
229 |
|
| 927 |
40 |
| SV **of_svp = hv_fetch(location_hv, "of", 2, 0); |
| 928 |
40 |
| return gql_validation_variable_type_is_kind(variable_type, "non_null") |
| 929 |
38 |
▶ | && of_svp |
Branch: 1 branch
| Branch | True | False | Total |
| && of_svp |
38 |
0 |
38 |
|
| 930 |
78 |
▶ | && gql_validation_variable_type_compatible( |
Branch: 2 branches
| Branch | True | False | Total |
| && gql_validation_variable_type_compatible( |
38 |
2 |
40 |
| && gql_validation_variable_type_compatible( |
38 |
0 |
38 |
|
| 931 |
|
| gql_validation_variable_type_inner(variable_type), *of_svp |
| 932 |
|
| ); |
| 933 |
|
| } |
| 934 |
189 |
▶ | if (gql_validation_variable_type_is_kind(variable_type, "non_null")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_variable_type_is_kind(variable_type, "non_null")) { |
3 |
186 |
189 |
|
| 935 |
3 |
| return gql_validation_variable_type_compatible( |
| 936 |
|
| gql_validation_variable_type_inner(variable_type), location_type |
| 937 |
|
| ); |
| 938 |
|
| } |
| 939 |
186 |
▶ | if (strEQ(kind, "LIST")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "LIST")) { |
28 |
158 |
186 |
|
| 940 |
28 |
| SV **of_svp = hv_fetch(location_hv, "of", 2, 0); |
| 941 |
28 |
| return gql_validation_variable_type_is_kind(variable_type, "list") |
| 942 |
28 |
▶ | && of_svp |
Branch: 1 branch
| Branch | True | False | Total |
| && of_svp |
28 |
0 |
28 |
|
| 943 |
56 |
▶ | && gql_validation_variable_type_compatible( |
Branch: 2 branches
| Branch | True | False | Total |
| && gql_validation_variable_type_compatible( |
28 |
0 |
28 |
| && gql_validation_variable_type_compatible( |
28 |
0 |
28 |
|
| 944 |
|
| gql_validation_variable_type_inner(variable_type), *of_svp |
| 945 |
|
| ); |
| 946 |
|
| } |
| 947 |
158 |
▶ | if (gql_validation_variable_type_is_kind(variable_type, "list")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_variable_type_is_kind(variable_type, "list")) { |
0 |
158 |
158 |
|
| 948 |
0 |
| return 0; |
| 949 |
|
| } |
| 950 |
158 |
▶ | if (strEQ(kind, "NAMED") && !SvROK(variable_type)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(kind, "NAMED") && !SvROK(variable_type)) { |
158 |
0 |
158 |
| if (strEQ(kind, "NAMED") && !SvROK(variable_type)) { |
158 |
0 |
158 |
|
| 951 |
158 |
| SV **name_svp = hv_fetch(location_hv, "name", 4, 0); |
| 952 |
158 |
▶ | return name_svp && SvOK(*name_svp) && sv_eq(variable_type, *name_svp); |
Branch: 3 branches
| Branch | True | False | Total |
| return name_svp && SvOK(*name_svp) && sv_eq(variable_type, *name_svp); |
158 |
0 |
158 |
| return name_svp && SvOK(*name_svp) && sv_eq(variable_type, *name_svp); |
158 |
0 |
158 |
| return name_svp && SvOK(*name_svp) && sv_eq(variable_type, *name_svp); |
155 |
3 |
158 |
|
| 953 |
|
| } |
| 954 |
0 |
| return 0; |
| 955 |
|
| } |
| 956 |
|
| |
| 957 |
|
| static void |
| 958 |
60 |
| gql_validation_validate_nested_variable_position( |
| 959 |
|
| pTHX_ AV *errors_av, SV *value_sv, SV *expected_type_sv, |
| 960 |
|
| HV *variables_hv, int location_has_default, const char *position, |
| 961 |
|
| SV *location_sv |
| 962 |
|
| ) { |
| 963 |
|
| SV *inner_sv; |
| 964 |
|
| HE *variable_he; |
| 965 |
|
| HV *variable_hv; |
| 966 |
|
| SV **variable_type_svp; |
| 967 |
60 |
| SV *location_type = expected_type_sv; |
| 968 |
|
| STRLEN name_len; |
| 969 |
|
| const char *name; |
| 970 |
|
| |
| 971 |
60 |
▶ | if (!value_sv || !expected_type_sv || !SvROK(value_sv) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!value_sv || !expected_type_sv || !SvROK(value_sv) |
60 |
0 |
60 |
| if (!value_sv || !expected_type_sv || !SvROK(value_sv) |
60 |
0 |
60 |
| if (!value_sv || !expected_type_sv || !SvROK(value_sv) |
38 |
22 |
60 |
|
| 972 |
38 |
▶ | || !SvOK(SvRV(value_sv)) || SvROK(SvRV(value_sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| || !SvOK(SvRV(value_sv)) || SvROK(SvRV(value_sv)) |
33 |
5 |
38 |
| || !SvOK(SvRV(value_sv)) || SvROK(SvRV(value_sv)) |
33 |
0 |
33 |
|
| 973 |
33 |
▶ | || sv_isobject(value_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| || sv_isobject(value_sv)) { |
13 |
20 |
33 |
|
| 974 |
57 |
| return; |
| 975 |
|
| } |
| 976 |
20 |
| inner_sv = SvRV(value_sv); |
| 977 |
20 |
▶ | variable_he = variables_hv ? hv_fetch_ent(variables_hv, inner_sv, 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| variable_he = variables_hv ? hv_fetch_ent(variables_hv, inner_sv, 0, 0) : NULL; |
20 |
0 |
20 |
|
| 978 |
20 |
▶ | if (!variable_he || !SvROK(HeVAL(variable_he)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!variable_he || !SvROK(HeVAL(variable_he)) |
20 |
0 |
20 |
| if (!variable_he || !SvROK(HeVAL(variable_he)) |
20 |
0 |
20 |
|
| 979 |
20 |
▶ | || SvTYPE(SvRV(HeVAL(variable_he))) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(HeVAL(variable_he))) != SVt_PVHV) { |
0 |
20 |
20 |
|
| 980 |
0 |
| return; |
| 981 |
|
| } |
| 982 |
20 |
| variable_hv = (HV *)SvRV(HeVAL(variable_he)); |
| 983 |
20 |
| variable_type_svp = hv_fetch(variable_hv, "type", 4, 0); |
| 984 |
20 |
▶ | if (gql_validation_type_is_non_null(location_type) && variable_type_svp |
Branch: 2 branches
| Branch | True | False | Total |
| if (gql_validation_type_is_non_null(location_type) && variable_type_svp |
14 |
6 |
20 |
| if (gql_validation_type_is_non_null(location_type) && variable_type_svp |
14 |
0 |
14 |
|
| 985 |
14 |
▶ | && !gql_validation_variable_type_is_kind(*variable_type_svp, "non_null")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !gql_validation_variable_type_is_kind(*variable_type_svp, "non_null")) { |
3 |
11 |
14 |
|
| 986 |
3 |
| SV **default_svp = hv_fetch(variable_hv, "default_value", 13, 0); |
| 987 |
3 |
▶ | if ((default_svp && SvOK(*default_svp)) || location_has_default) { |
Branch: 3 branches
| Branch | True | False | Total |
| if ((default_svp && SvOK(*default_svp)) || location_has_default) { |
3 |
0 |
3 |
| if ((default_svp && SvOK(*default_svp)) || location_has_default) { |
0 |
3 |
3 |
| if ((default_svp && SvOK(*default_svp)) || location_has_default) { |
0 |
0 |
0 |
|
| 988 |
3 |
| SV **of_svp = hv_fetch((HV *)SvRV(location_type), "of", 2, 0); |
| 989 |
3 |
▶ | if (of_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (of_svp) { |
3 |
0 |
3 |
|
| 990 |
3 |
| location_type = *of_svp; |
| 991 |
|
| } |
| 992 |
|
| } |
| 993 |
|
| } |
| 994 |
20 |
▶ | if (variable_type_svp |
Branch: 1 branch
| Branch | True | False | Total |
| if (variable_type_svp |
20 |
0 |
20 |
|
| 995 |
20 |
▶ | && gql_validation_variable_type_compatible(*variable_type_svp, location_type)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && gql_validation_variable_type_compatible(*variable_type_svp, location_type)) { |
17 |
3 |
20 |
|
| 996 |
17 |
| return; |
| 997 |
|
| } |
| 998 |
3 |
| name = SvPV(inner_sv, name_len); |
| 999 |
|
| { |
| 1000 |
3 |
| SV *message = newSVpvf( |
| 1001 |
|
| "Variable '$%s' cannot be used for %s because its type is incompatible.", |
| 1002 |
|
| name, position |
| 1003 |
|
| ); |
| 1004 |
3 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1005 |
3 |
| SvREFCNT_dec(message); |
| 1006 |
|
| } |
| 1007 |
|
| } |
| 1008 |
|
| |
| 1009 |
|
| static void |
| 1010 |
4535 |
| gql_validation_validate_arguments( |
| 1011 |
|
| pTHX_ AV *errors_av, |
| 1012 |
|
| SV *schema, |
| 1013 |
|
| SV *compiled_sv, |
| 1014 |
|
| HV *arguments_hv, |
| 1015 |
|
| HV *argument_defs_hv, |
| 1016 |
|
| HV *variables_hv, |
| 1017 |
|
| SV *location_sv |
| 1018 |
|
| ) { |
| 1019 |
4535 |
| I32 argument_count = 0; |
| 1020 |
|
| SV **argument_keys; |
| 1021 |
|
| I32 i; |
| 1022 |
|
| |
| 1023 |
4535 |
| argument_keys = gql_parser_sorted_hash_keys(aTHX_ arguments_hv, &argument_count); |
| 1024 |
4535 |
▶ | if (argument_keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (argument_keys) { |
302 |
4233 |
4535 |
|
| 1025 |
620 |
▶ | for (i = 0; i < argument_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < argument_count; i++) { |
318 |
302 |
620 |
|
| 1026 |
318 |
| HE *arg_he = hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0); |
| 1027 |
318 |
| HE *def_he = hv_fetch_ent(argument_defs_hv, argument_keys[i], 0, 0); |
| 1028 |
318 |
▶ | if (!def_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!def_he) { |
0 |
318 |
318 |
|
| 1029 |
0 |
| SV *message = newSVpvf("Unknown argument '%s'.", SvPV_nolen(argument_keys[i])); |
| 1030 |
0 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1031 |
0 |
| SvREFCNT_dec(message); |
| 1032 |
0 |
| continue; |
| 1033 |
|
| } |
| 1034 |
318 |
▶ | if (arg_he && SvROK(HeVAL(def_he)) && SvTYPE(SvRV(HeVAL(def_he))) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (arg_he && SvROK(HeVAL(def_he)) && SvTYPE(SvRV(HeVAL(def_he))) == SVt_PVHV) { |
318 |
0 |
318 |
| if (arg_he && SvROK(HeVAL(def_he)) && SvTYPE(SvRV(HeVAL(def_he))) == SVt_PVHV) { |
318 |
0 |
318 |
| if (arg_he && SvROK(HeVAL(def_he)) && SvTYPE(SvRV(HeVAL(def_he))) == SVt_PVHV) { |
318 |
0 |
318 |
|
| 1035 |
318 |
| SV **type_svp = hv_fetch((HV *)SvRV(HeVAL(def_he)), "type", 4, 0); |
| 1036 |
318 |
| SV *arg_value = HeVAL(arg_he); |
| 1037 |
318 |
▶ | if (type_svp && arg_value && SvROK(arg_value) |
Branch: 3 branches
| Branch | True | False | Total |
| if (type_svp && arg_value && SvROK(arg_value) |
318 |
0 |
318 |
| if (type_svp && arg_value && SvROK(arg_value) |
318 |
0 |
318 |
| if (type_svp && arg_value && SvROK(arg_value) |
237 |
81 |
318 |
|
| 1038 |
237 |
▶ | && SvOK(SvRV(arg_value)) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvOK(SvRV(arg_value)) |
164 |
73 |
237 |
|
| 1039 |
164 |
▶ | && !SvROK(SvRV(arg_value)) && !sv_isobject(arg_value)) { |
Branch: 2 branches
| Branch | True | False | Total |
| && !SvROK(SvRV(arg_value)) && !sv_isobject(arg_value)) { |
159 |
5 |
164 |
| && !SvROK(SvRV(arg_value)) && !sv_isobject(arg_value)) { |
146 |
13 |
159 |
|
| 1040 |
|
| STRLEN variable_name_len; |
| 1041 |
146 |
| const char *variable_name = SvPV(SvRV(arg_value), variable_name_len); |
| 1042 |
146 |
| HE *variable_he = variables_hv |
| 1043 |
146 |
▶ | ? hv_fetch_ent(variables_hv, SvRV(arg_value), 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? hv_fetch_ent(variables_hv, SvRV(arg_value), 0, 0) : NULL; |
143 |
3 |
146 |
|
| 1044 |
146 |
▶ | if (variable_he && SvROK(HeVAL(variable_he)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (variable_he && SvROK(HeVAL(variable_he)) |
140 |
6 |
146 |
| if (variable_he && SvROK(HeVAL(variable_he)) |
140 |
0 |
140 |
|
| 1045 |
140 |
▶ | && SvTYPE(SvRV(HeVAL(variable_he))) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(HeVAL(variable_he))) == SVt_PVHV) { |
140 |
0 |
140 |
|
| 1046 |
140 |
| HV *variable_hv = (HV *)SvRV(HeVAL(variable_he)); |
| 1047 |
140 |
| SV **variable_type_svp = hv_fetch(variable_hv, "type", 4, 0); |
| 1048 |
140 |
| SV *location_type = *type_svp; |
| 1049 |
|
| int compatible; |
| 1050 |
140 |
▶ | if (gql_validation_type_is_non_null(location_type) |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_type_is_non_null(location_type) |
29 |
111 |
140 |
|
| 1051 |
29 |
▶ | && variable_type_svp |
Branch: 1 branch
| Branch | True | False | Total |
| && variable_type_svp |
29 |
0 |
29 |
|
| 1052 |
29 |
▶ | && !gql_validation_variable_type_is_kind(*variable_type_svp, "non_null")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !gql_validation_variable_type_is_kind(*variable_type_svp, "non_null")) { |
6 |
23 |
29 |
|
| 1053 |
6 |
| SV **variable_default_svp = hv_fetch(variable_hv, "default_value", 13, 0); |
| 1054 |
6 |
| SV **location_default_svp = hv_fetch( |
| 1055 |
|
| (HV *)SvRV(HeVAL(def_he)), "has_default_value", 17, 0 |
| 1056 |
|
| ); |
| 1057 |
6 |
▶ | if ((variable_default_svp && SvOK(*variable_default_svp)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((variable_default_svp && SvOK(*variable_default_svp)) |
4 |
2 |
6 |
| if ((variable_default_svp && SvOK(*variable_default_svp)) |
0 |
4 |
4 |
|
| 1058 |
2 |
▶ | || (location_default_svp && SvTRUE(*location_default_svp))) { |
Branch: 2 branches
| Branch | True | False | Total |
| || (location_default_svp && SvTRUE(*location_default_svp))) { |
2 |
0 |
2 |
| || (location_default_svp && SvTRUE(*location_default_svp))) { |
0 |
2 |
2 |
|
| 1059 |
4 |
| SV **of_svp = hv_fetch((HV *)SvRV(location_type), "of", 2, 0); |
| 1060 |
4 |
▶ | if (of_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (of_svp) { |
4 |
0 |
4 |
|
| 1061 |
4 |
| location_type = *of_svp; |
| 1062 |
|
| } |
| 1063 |
|
| } |
| 1064 |
|
| } |
| 1065 |
140 |
| compatible = variable_type_svp |
| 1066 |
140 |
▶ | && gql_validation_variable_type_compatible(*variable_type_svp, location_type); |
Branch: 2 branches
| Branch | True | False | Total |
| && gql_validation_variable_type_compatible(*variable_type_svp, location_type); |
140 |
0 |
140 |
| && gql_validation_variable_type_compatible(*variable_type_svp, location_type); |
138 |
2 |
140 |
|
| 1067 |
140 |
▶ | if (!compatible) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!compatible) { |
2 |
138 |
140 |
|
| 1068 |
4 |
| SV *message = newSVpvf( |
| 1069 |
|
| "Variable '$%s' cannot be used for argument '%s' because its type is incompatible.", |
| 1070 |
|
| variable_name, SvPV_nolen(argument_keys[i]) |
| 1071 |
|
| ); |
| 1072 |
2 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1073 |
2 |
| SvREFCNT_dec(message); |
| 1074 |
|
| } |
| 1075 |
|
| } |
| 1076 |
|
| } |
| 1077 |
318 |
▶ | gql_validation_validate_value( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_value( |
318 |
0 |
318 |
|
| 1078 |
|
| aTHX_ errors_av, |
| 1079 |
|
| schema, |
| 1080 |
|
| compiled_sv, |
| 1081 |
|
| HeVAL(arg_he), |
| 1082 |
|
| type_svp ? *type_svp : NULL, |
| 1083 |
|
| variables_hv, |
| 1084 |
|
| location_sv |
| 1085 |
|
| ); |
| 1086 |
|
| } |
| 1087 |
|
| } |
| 1088 |
302 |
| gql_parser_free_sorted_hash_keys(argument_keys, argument_count); |
| 1089 |
|
| } |
| 1090 |
|
| |
| 1091 |
4535 |
| argument_keys = gql_parser_sorted_hash_keys(aTHX_ argument_defs_hv, &argument_count); |
| 1092 |
4535 |
▶ | if (argument_keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (argument_keys) { |
338 |
4197 |
4535 |
|
| 1093 |
828 |
▶ | for (i = 0; i < argument_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < argument_count; i++) { |
490 |
338 |
828 |
|
| 1094 |
490 |
| HE *def_he = hv_fetch_ent(argument_defs_hv, argument_keys[i], 0, 0); |
| 1095 |
|
| HV *def_hv; |
| 1096 |
|
| SV **type_svp; |
| 1097 |
|
| SV **has_default_svp; |
| 1098 |
490 |
▶ | if (hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0) || !def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0) || !def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
172 |
318 |
490 |
| if (hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0) || !def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
172 |
0 |
172 |
| if (hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0) || !def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
172 |
0 |
172 |
| if (hv_fetch_ent(arguments_hv, argument_keys[i], 0, 0) || !def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
0 |
172 |
172 |
|
| 1099 |
318 |
| continue; |
| 1100 |
|
| } |
| 1101 |
172 |
| def_hv = (HV *)SvRV(HeVAL(def_he)); |
| 1102 |
172 |
| type_svp = hv_fetch(def_hv, "type", 4, 0); |
| 1103 |
172 |
| has_default_svp = hv_fetch(def_hv, "has_default_value", 17, 0); |
| 1104 |
172 |
▶ | if (type_svp && gql_validation_type_is_non_null(*type_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (type_svp && gql_validation_type_is_non_null(*type_svp) |
172 |
0 |
172 |
| if (type_svp && gql_validation_type_is_non_null(*type_svp) |
2 |
170 |
172 |
|
| 1105 |
2 |
▶ | && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
Branch: 3 branches
| Branch | True | False | Total |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
2 |
0 |
2 |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
2 |
0 |
2 |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
2 |
0 |
2 |
|
| 1106 |
4 |
| SV *message = newSVpvf("Required argument '%s' was not provided.", SvPV_nolen(argument_keys[i])); |
| 1107 |
2 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1108 |
2 |
| SvREFCNT_dec(message); |
| 1109 |
|
| } |
| 1110 |
|
| } |
| 1111 |
338 |
| gql_parser_free_sorted_hash_keys(argument_keys, argument_count); |
| 1112 |
|
| } |
| 1113 |
4535 |
| } |
| 1114 |
|
| |
| 1115 |
|
| static void |
| 1116 |
388 |
| gql_validation_validate_value( |
| 1117 |
|
| pTHX_ AV *errors_av, |
| 1118 |
|
| SV *schema, |
| 1119 |
|
| SV *compiled_sv, |
| 1120 |
|
| SV *value_sv, |
| 1121 |
|
| SV *expected_type_sv, |
| 1122 |
|
| HV *variables_hv, |
| 1123 |
|
| SV *location_sv |
| 1124 |
|
| ) { |
| 1125 |
388 |
▶ | if (!value_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value_sv) { |
0 |
388 |
388 |
|
| 1126 |
0 |
| return; |
| 1127 |
|
| } |
| 1128 |
|
| |
| 1129 |
388 |
▶ | if (!SvOK(value_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(value_sv)) { |
3 |
385 |
388 |
|
| 1130 |
3 |
▶ | if (gql_validation_type_is_non_null(expected_type_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_type_is_non_null(expected_type_sv)) { |
2 |
1 |
3 |
|
| 1131 |
2 |
| SV *type_name_sv = gql_validation_named_type_name_sv(expected_type_sv); |
| 1132 |
4 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
2 |
0 |
2 |
| SV *message = newSVpvf( |
2 |
0 |
2 |
|
| 1133 |
|
| "Null is not a valid value for non-null type '%s'.", |
| 1134 |
|
| type_name_sv && SvOK(type_name_sv) ? SvPV_nolen(type_name_sv) : "" |
| 1135 |
|
| ); |
| 1136 |
2 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1137 |
2 |
| SvREFCNT_dec(message); |
| 1138 |
|
| } |
| 1139 |
3 |
| return; |
| 1140 |
|
| } |
| 1141 |
|
| |
| 1142 |
385 |
▶ | if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVAV) { |
279 |
106 |
385 |
| if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVAV) { |
13 |
266 |
279 |
|
| 1143 |
13 |
| AV *value_av = (AV *)SvRV(value_sv); |
| 1144 |
13 |
| SV *item_type_sv = expected_type_sv; |
| 1145 |
13 |
| SV *list_type_sv = expected_type_sv; |
| 1146 |
13 |
▶ | if (gql_validation_type_is_non_null(list_type_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_type_is_non_null(list_type_sv)) { |
8 |
5 |
13 |
|
| 1147 |
8 |
| SV **of_svp = hv_fetch((HV *)SvRV(list_type_sv), "of", 2, 0); |
| 1148 |
8 |
▶ | list_type_sv = of_svp ? *of_svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| list_type_sv = of_svp ? *of_svp : NULL; |
8 |
0 |
8 |
|
| 1149 |
|
| } |
| 1150 |
13 |
▶ | if (list_type_sv && SvROK(list_type_sv) && SvTYPE(SvRV(list_type_sv)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (list_type_sv && SvROK(list_type_sv) && SvTYPE(SvRV(list_type_sv)) == SVt_PVHV) { |
13 |
0 |
13 |
| if (list_type_sv && SvROK(list_type_sv) && SvTYPE(SvRV(list_type_sv)) == SVt_PVHV) { |
13 |
0 |
13 |
| if (list_type_sv && SvROK(list_type_sv) && SvTYPE(SvRV(list_type_sv)) == SVt_PVHV) { |
13 |
0 |
13 |
|
| 1151 |
13 |
| SV **kind_svp = hv_fetch((HV *)SvRV(list_type_sv), "kind", 4, 0); |
| 1152 |
38 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
13 |
0 |
13 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
13 |
0 |
13 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
13 |
0 |
13 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
12 |
1 |
13 |
|
| 1153 |
12 |
| SV **of_svp = hv_fetch((HV *)SvRV(list_type_sv), "of", 2, 0); |
| 1154 |
12 |
▶ | if (of_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (of_svp) { |
12 |
0 |
12 |
|
| 1155 |
12 |
| item_type_sv = *of_svp; |
| 1156 |
|
| } |
| 1157 |
|
| } else { |
| 1158 |
1 |
| SV *message = newSVpv("List value is not valid for a non-list type.", 0); |
| 1159 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1160 |
1 |
| SvREFCNT_dec(message); |
| 1161 |
1 |
| return; |
| 1162 |
|
| } |
| 1163 |
|
| } |
| 1164 |
29 |
▶ | for (I32 i = 0; i <= av_len(value_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (I32 i = 0; i <= av_len(value_av); i++) { |
17 |
12 |
29 |
|
| 1165 |
17 |
| SV **item_svp = av_fetch(value_av, i, 0); |
| 1166 |
17 |
▶ | if (item_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (item_svp) { |
17 |
0 |
17 |
|
| 1167 |
17 |
| gql_validation_validate_nested_variable_position( |
| 1168 |
|
| aTHX_ errors_av, *item_svp, item_type_sv, variables_hv, 0, |
| 1169 |
|
| "a list item", location_sv |
| 1170 |
|
| ); |
| 1171 |
17 |
| gql_validation_validate_value(aTHX_ errors_av, schema, compiled_sv, *item_svp, item_type_sv, variables_hv, location_sv); |
| 1172 |
|
| } |
| 1173 |
|
| } |
| 1174 |
12 |
| return; |
| 1175 |
|
| } |
| 1176 |
|
| |
| 1177 |
372 |
▶ | if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { |
266 |
106 |
372 |
| if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { |
65 |
201 |
266 |
|
| 1178 |
65 |
| HV *value_hv = (HV *)SvRV(value_sv); |
| 1179 |
65 |
| SV *named_type_name_sv = gql_validation_named_type_name_sv(expected_type_sv); |
| 1180 |
65 |
| HV *named_type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, named_type_name_sv); |
| 1181 |
|
| SV **kind_svp; |
| 1182 |
65 |
▶ | if (!named_type_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!named_type_hv) { |
0 |
65 |
65 |
|
| 1183 |
0 |
| return; |
| 1184 |
|
| } |
| 1185 |
65 |
| kind_svp = hv_fetch(named_type_hv, "kind", 4, 0); |
| 1186 |
130 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
65 |
0 |
65 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
65 |
0 |
65 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
65 |
0 |
65 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
1 |
64 |
65 |
|
| 1187 |
1 |
| SV *message = newSVpv("Input object value is not valid for a non-input-object type.", 0); |
| 1188 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1189 |
1 |
| SvREFCNT_dec(message); |
| 1190 |
1 |
| return; |
| 1191 |
|
| } |
| 1192 |
|
| { |
| 1193 |
64 |
| SV **one_of_svp = hv_fetch(named_type_hv, "is_one_of", 9, 0); |
| 1194 |
64 |
▶ | if (one_of_svp && SvOK(*one_of_svp) && SvTRUE(*one_of_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (one_of_svp && SvOK(*one_of_svp) && SvTRUE(*one_of_svp)) { |
5 |
59 |
64 |
| if (one_of_svp && SvOK(*one_of_svp) && SvTRUE(*one_of_svp)) { |
5 |
0 |
5 |
| if (one_of_svp && SvOK(*one_of_svp) && SvTRUE(*one_of_svp)) { |
5 |
0 |
5 |
|
| 1195 |
5 |
▶ | if ((I32)HvUSEDKEYS(value_hv) != 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((I32)HvUSEDKEYS(value_hv) != 1) { |
0 |
5 |
5 |
| if ((I32)HvUSEDKEYS(value_hv) != 1) { |
2 |
3 |
5 |
|
| 1196 |
4 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
2 |
0 |
2 |
|
| 1197 |
|
| "OneOf Input Object '%s' must specify exactly one key.", |
| 1198 |
|
| named_type_name_sv ? SvPV_nolen(named_type_name_sv) : "" |
| 1199 |
|
| ); |
| 1200 |
2 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1201 |
2 |
| SvREFCNT_dec(message); |
| 1202 |
|
| } else { |
| 1203 |
|
| HE *entry; |
| 1204 |
3 |
| hv_iterinit(value_hv); |
| 1205 |
3 |
| entry = hv_iternext(value_hv); |
| 1206 |
3 |
▶ | if (entry && (!HeVAL(entry) || !SvOK(HeVAL(entry)))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (entry && (!HeVAL(entry) || !SvOK(HeVAL(entry)))) { |
3 |
0 |
3 |
| if (entry && (!HeVAL(entry) || !SvOK(HeVAL(entry)))) { |
3 |
0 |
3 |
| if (entry && (!HeVAL(entry) || !SvOK(HeVAL(entry)))) { |
1 |
2 |
3 |
|
| 1207 |
2 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
0 |
1 |
1 |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 1208 |
|
| "OneOf Input Object '%s' field '%s' must be non-null.", |
| 1209 |
|
| named_type_name_sv ? SvPV_nolen(named_type_name_sv) : "", |
| 1210 |
|
| HePV(entry, PL_na) |
| 1211 |
|
| ); |
| 1212 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1213 |
1 |
| SvREFCNT_dec(message); |
| 1214 |
|
| } |
| 1215 |
|
| } |
| 1216 |
|
| } |
| 1217 |
|
| } |
| 1218 |
|
| { |
| 1219 |
64 |
| SV **fields_svp = hv_fetch(named_type_hv, "fields", 6, 0); |
| 1220 |
64 |
▶ | HV *fields_hv = (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) ? (HV *)SvRV(*fields_svp) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| HV *fields_hv = (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) ? (HV *)SvRV(*fields_svp) : NULL; |
64 |
0 |
64 |
| HV *fields_hv = (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) ? (HV *)SvRV(*fields_svp) : NULL; |
64 |
0 |
64 |
| HV *fields_hv = (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) ? (HV *)SvRV(*fields_svp) : NULL; |
64 |
0 |
64 |
|
| 1221 |
64 |
| I32 count = 0; |
| 1222 |
64 |
| SV **keys = gql_parser_sorted_hash_keys(aTHX_ value_hv, &count); |
| 1223 |
|
| I32 i; |
| 1224 |
64 |
▶ | if (keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (keys) { |
63 |
1 |
64 |
|
| 1225 |
128 |
▶ | for (i = 0; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; i++) { |
65 |
63 |
128 |
|
| 1226 |
65 |
▶ | HE *field_he = fields_hv ? hv_fetch_ent(fields_hv, keys[i], 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| HE *field_he = fields_hv ? hv_fetch_ent(fields_hv, keys[i], 0, 0) : NULL; |
65 |
0 |
65 |
|
| 1227 |
65 |
| HE *value_he = hv_fetch_ent(value_hv, keys[i], 0, 0); |
| 1228 |
65 |
▶ | if (!field_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!field_he) { |
50 |
15 |
65 |
|
| 1229 |
150 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
50 |
0 |
50 |
|
| 1230 |
|
| "Input field '%s' is not defined on type '%s'.", |
| 1231 |
|
| SvPV_nolen(keys[i]), |
| 1232 |
|
| named_type_name_sv ? SvPV_nolen(named_type_name_sv) : "" |
| 1233 |
|
| ); |
| 1234 |
50 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1235 |
50 |
| SvREFCNT_dec(message); |
| 1236 |
50 |
| continue; |
| 1237 |
|
| } |
| 1238 |
15 |
▶ | if (value_he && SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (value_he && SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
15 |
0 |
15 |
| if (value_he && SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
15 |
0 |
15 |
| if (value_he && SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
15 |
0 |
15 |
|
| 1239 |
15 |
| SV **field_type_svp = hv_fetch((HV *)SvRV(HeVAL(field_he)), "type", 4, 0); |
| 1240 |
15 |
| SV **has_default_svp = hv_fetch( |
| 1241 |
|
| (HV *)SvRV(HeVAL(field_he)), "has_default_value", 17, 0 |
| 1242 |
|
| ); |
| 1243 |
30 |
▶ | gql_validation_validate_nested_variable_position( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_nested_variable_position( |
15 |
0 |
15 |
|
| 1244 |
|
| aTHX_ errors_av, HeVAL(value_he), |
| 1245 |
|
| field_type_svp ? *field_type_svp : NULL, variables_hv, |
| 1246 |
15 |
| has_default_svp && SvTRUE(*has_default_svp), |
| 1247 |
|
| "an input object field", location_sv |
| 1248 |
|
| ); |
| 1249 |
15 |
▶ | gql_validation_validate_value(aTHX_ errors_av, schema, compiled_sv, HeVAL(value_he), field_type_svp ? *field_type_svp : NULL, variables_hv, location_sv); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_value(aTHX_ errors_av, schema, compiled_sv, HeVAL(value_he), field_type_svp ? *field_type_svp : NULL, variables_hv, location_sv); |
15 |
0 |
15 |
|
| 1250 |
|
| } |
| 1251 |
|
| } |
| 1252 |
63 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 1253 |
|
| } |
| 1254 |
64 |
▶ | if (fields_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fields_hv) { |
64 |
0 |
64 |
|
| 1255 |
64 |
| keys = gql_parser_sorted_hash_keys(aTHX_ fields_hv, &count); |
| 1256 |
64 |
▶ | if (keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (keys) { |
64 |
0 |
64 |
|
| 1257 |
138 |
▶ | for (i = 0; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; i++) { |
74 |
64 |
138 |
|
| 1258 |
74 |
| HE *field_he = hv_fetch_ent(fields_hv, keys[i], 0, 0); |
| 1259 |
|
| HV *field_hv; |
| 1260 |
|
| SV **field_type_svp; |
| 1261 |
|
| SV **has_default_svp; |
| 1262 |
74 |
▶ | if (hv_fetch_ent(value_hv, keys[i], 0, 0) || !field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (hv_fetch_ent(value_hv, keys[i], 0, 0) || !field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
59 |
15 |
74 |
| if (hv_fetch_ent(value_hv, keys[i], 0, 0) || !field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
59 |
0 |
59 |
| if (hv_fetch_ent(value_hv, keys[i], 0, 0) || !field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
59 |
0 |
59 |
| if (hv_fetch_ent(value_hv, keys[i], 0, 0) || !field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
0 |
59 |
59 |
|
| 1263 |
15 |
| continue; |
| 1264 |
|
| } |
| 1265 |
59 |
| field_hv = (HV *)SvRV(HeVAL(field_he)); |
| 1266 |
59 |
| field_type_svp = hv_fetch(field_hv, "type", 4, 0); |
| 1267 |
59 |
| has_default_svp = hv_fetch(field_hv, "has_default_value", 17, 0); |
| 1268 |
59 |
▶ | if (field_type_svp && gql_validation_type_is_non_null(*field_type_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (field_type_svp && gql_validation_type_is_non_null(*field_type_svp) |
59 |
0 |
59 |
| if (field_type_svp && gql_validation_type_is_non_null(*field_type_svp) |
0 |
59 |
59 |
|
| 1269 |
0 |
▶ | && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
Branch: 3 branches
| Branch | True | False | Total |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
0 |
0 |
0 |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
0 |
0 |
0 |
| && !(has_default_svp && SvOK(*has_default_svp) && SvTRUE(*has_default_svp))) { |
0 |
0 |
0 |
|
| 1270 |
0 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
0 |
0 |
0 |
|
| 1271 |
|
| "Required input field '%s' was not provided for type '%s'.", |
| 1272 |
|
| SvPV_nolen(keys[i]), |
| 1273 |
|
| named_type_name_sv ? SvPV_nolen(named_type_name_sv) : "" |
| 1274 |
|
| ); |
| 1275 |
0 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1276 |
0 |
| SvREFCNT_dec(message); |
| 1277 |
|
| } |
| 1278 |
|
| } |
| 1279 |
64 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 1280 |
|
| } |
| 1281 |
|
| } |
| 1282 |
|
| } |
| 1283 |
64 |
| return; |
| 1284 |
|
| } |
| 1285 |
|
| |
| 1286 |
307 |
▶ | if (SvROK(value_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(value_sv)) { |
201 |
106 |
307 |
|
| 1287 |
201 |
| SV *inner_sv = SvRV(value_sv); |
| 1288 |
|
| /* A variable reference is an UNBLESSED scalar ref (\'name'). Blessed |
| 1289 |
|
| * scalar refs are literals - JSON::PP::Boolean booleans from the |
| 1290 |
|
| * parser - and REF-of-ref is the enum literal marker; neither names |
| 1291 |
|
| * a variable. */ |
| 1292 |
201 |
▶ | if (!SvROK(inner_sv) && !sv_isobject(value_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(inner_sv) && !sv_isobject(value_sv)) { |
196 |
5 |
201 |
| if (!SvROK(inner_sv) && !sv_isobject(value_sv)) { |
166 |
30 |
196 |
|
| 1293 |
|
| STRLEN name_len; |
| 1294 |
166 |
| const char *name = SvPV(inner_sv, name_len); |
| 1295 |
166 |
▶ | if ((!variables_hv || !hv_exists(variables_hv, name, (I32)name_len)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!variables_hv || !hv_exists(variables_hv, name, (I32)name_len)) |
163 |
3 |
166 |
| if ((!variables_hv || !hv_exists(variables_hv, name, (I32)name_len)) |
3 |
160 |
163 |
|
| 1296 |
6 |
▶ | && (!variables_hv |
Branch: 1 branch
| Branch | True | False | Total |
| && (!variables_hv |
3 |
3 |
6 |
|
| 1297 |
3 |
▶ | || !hv_exists(variables_hv, "__defer_fragment_variables", 26))) { |
Branch: 1 branch
| Branch | True | False | Total |
| || !hv_exists(variables_hv, "__defer_fragment_variables", 26))) { |
0 |
3 |
3 |
|
| 1298 |
3 |
| SV *message = newSVpvf("Variable '$%s' is used but not defined.", name); |
| 1299 |
3 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1300 |
3 |
| SvREFCNT_dec(message); |
| 1301 |
|
| } |
| 1302 |
166 |
| return; |
| 1303 |
|
| } |
| 1304 |
|
| } |
| 1305 |
|
| |
| 1306 |
|
| /* Built-in literal coercion stays in XS. The parser preserves literal |
| 1307 |
|
| * categories in the SV flags (and blesses JSON booleans), so validation |
| 1308 |
|
| * does not need a Perl method call per scalar literal. */ |
| 1309 |
|
| { |
| 1310 |
141 |
| SV *type_name_sv = gql_validation_named_type_name_sv(expected_type_sv); |
| 1311 |
141 |
▶ | const char *type_name = type_name_sv && SvOK(type_name_sv) |
Branch: 1 branch
| Branch | True | False | Total |
| const char *type_name = type_name_sv && SvOK(type_name_sv) |
141 |
0 |
141 |
|
| 1312 |
282 |
▶ | ? SvPV_nolen(type_name_sv) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvPV_nolen(type_name_sv) : NULL; |
141 |
0 |
141 |
|
| 1313 |
141 |
| int valid = 1; |
| 1314 |
141 |
▶ | if (!SvOK(value_sv) || !type_name) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvOK(value_sv) || !type_name) { |
141 |
0 |
141 |
| if (!SvOK(value_sv) || !type_name) { |
0 |
141 |
141 |
|
| 1315 |
0 |
| return; |
| 1316 |
|
| } |
| 1317 |
|
| { |
| 1318 |
141 |
| HV *named_type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, type_name_sv); |
| 1319 |
141 |
▶ | SV **kind_svp = named_type_hv ? hv_fetch(named_type_hv, "kind", 4, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **kind_svp = named_type_hv ? hv_fetch(named_type_hv, "kind", 4, 0) : NULL; |
141 |
0 |
141 |
|
| 1320 |
141 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
141 |
0 |
141 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
141 |
0 |
141 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
141 |
0 |
141 |
|
| 1321 |
282 |
▶ | && strEQ(SvPV_nolen(*kind_svp), "ENUM")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*kind_svp), "ENUM")) { |
6 |
135 |
141 |
|
| 1322 |
6 |
| SV **values_svp = hv_fetch(named_type_hv, "values", 6, 0); |
| 1323 |
6 |
▶ | HV *values_hv = values_svp && SvROK(*values_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| HV *values_hv = values_svp && SvROK(*values_svp) |
6 |
0 |
6 |
|
| 1324 |
6 |
▶ | && SvTYPE(SvRV(*values_svp)) == SVt_PVHV |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*values_svp)) == SVt_PVHV |
6 |
0 |
6 |
|
| 1325 |
12 |
▶ | ? (HV *)SvRV(*values_svp) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(*values_svp) : NULL; |
6 |
0 |
6 |
|
| 1326 |
6 |
| valid = 0; |
| 1327 |
6 |
▶ | if (values_hv && SvROK(value_sv) && SvROK(SvRV(value_sv))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (values_hv && SvROK(value_sv) && SvROK(SvRV(value_sv))) { |
6 |
0 |
6 |
| if (values_hv && SvROK(value_sv) && SvROK(SvRV(value_sv))) { |
5 |
1 |
6 |
| if (values_hv && SvROK(value_sv) && SvROK(SvRV(value_sv))) { |
5 |
0 |
5 |
|
| 1328 |
5 |
| SV *enum_name_sv = SvRV(SvRV(value_sv)); |
| 1329 |
5 |
▶ | if (!SvROK(enum_name_sv) && SvOK(enum_name_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(enum_name_sv) && SvOK(enum_name_sv)) { |
5 |
0 |
5 |
| if (!SvROK(enum_name_sv) && SvOK(enum_name_sv)) { |
5 |
0 |
5 |
|
| 1330 |
|
| STRLEN enum_name_len; |
| 1331 |
5 |
| const char *enum_name = SvPV(enum_name_sv, enum_name_len); |
| 1332 |
5 |
| valid = hv_exists(values_hv, enum_name, (I32)enum_name_len); |
| 1333 |
|
| } |
| 1334 |
|
| } |
| 1335 |
6 |
▶ | if (!valid) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!valid) { |
2 |
4 |
6 |
|
| 1336 |
2 |
| SV *message = newSVpvf("Value is not a valid %s literal.", type_name); |
| 1337 |
2 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1338 |
2 |
| SvREFCNT_dec(message); |
| 1339 |
|
| } |
| 1340 |
6 |
| return; |
| 1341 |
|
| } |
| 1342 |
135 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
135 |
0 |
135 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
135 |
0 |
135 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
135 |
0 |
135 |
|
| 1343 |
270 |
▶ | && strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*kind_svp), "INPUT_OBJECT")) { |
1 |
134 |
135 |
|
| 1344 |
1 |
| SV *message = newSVpv("Scalar value is not valid for an input object type.", 0); |
| 1345 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1346 |
1 |
| SvREFCNT_dec(message); |
| 1347 |
1 |
| return; |
| 1348 |
|
| } |
| 1349 |
134 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
134 |
0 |
134 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
134 |
0 |
134 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
134 |
0 |
134 |
|
| 1350 |
268 |
▶ | && strEQ(SvPV_nolen(*kind_svp), "SCALAR") |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*kind_svp), "SCALAR") |
134 |
0 |
134 |
|
| 1351 |
134 |
▶ | && !strEQ(type_name, "Int") && !strEQ(type_name, "Float") |
Branch: 2 branches
| Branch | True | False | Total |
| && !strEQ(type_name, "Int") && !strEQ(type_name, "Float") |
124 |
10 |
134 |
| && !strEQ(type_name, "Int") && !strEQ(type_name, "Float") |
124 |
0 |
124 |
|
| 1352 |
124 |
▶ | && !strEQ(type_name, "String") && !strEQ(type_name, "Boolean") |
Branch: 2 branches
| Branch | True | False | Total |
| && !strEQ(type_name, "String") && !strEQ(type_name, "Boolean") |
57 |
67 |
124 |
| && !strEQ(type_name, "String") && !strEQ(type_name, "Boolean") |
28 |
29 |
57 |
|
| 1353 |
28 |
▶ | && !strEQ(type_name, "ID")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !strEQ(type_name, "ID")) { |
1 |
27 |
28 |
|
| 1354 |
1 |
| SV **parse_value_svp = hv_fetch(named_type_hv, "parse_value", 11, 0); |
| 1355 |
1 |
▶ | if (parse_value_svp && SvOK(*parse_value_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (parse_value_svp && SvOK(*parse_value_svp)) { |
1 |
0 |
1 |
| if (parse_value_svp && SvOK(*parse_value_svp)) { |
1 |
0 |
1 |
|
| 1356 |
1 |
| dSP; |
| 1357 |
|
| int count; |
| 1358 |
1 |
| ENTER; |
| 1359 |
1 |
| SAVETMPS; |
| 1360 |
1 |
▶ | sv_setsv(ERRSV, &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, &PL_sv_undef); |
1 |
0 |
1 |
|
| 1361 |
1 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
1 |
1 |
|
| 1362 |
1 |
▶ | XPUSHs(value_sv); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(value_sv); |
0 |
1 |
1 |
|
| 1363 |
1 |
| PUTBACK; |
| 1364 |
1 |
| count = call_sv(*parse_value_svp, G_SCALAR | G_EVAL); |
| 1365 |
1 |
| SPAGAIN; |
| 1366 |
1 |
▶ | if (count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 0) { |
1 |
0 |
1 |
|
| 1367 |
1 |
| (void)POPs; |
| 1368 |
|
| } |
| 1369 |
1 |
| PUTBACK; |
| 1370 |
1 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
1 |
0 |
1 |
| if (SvTRUE(ERRSV)) { |
1 |
0 |
1 |
|
| 1371 |
2 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 1372 |
|
| "Value is not a valid %s literal: %s", |
| 1373 |
|
| type_name, SvPV_nolen(ERRSV) |
| 1374 |
|
| ); |
| 1375 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1376 |
1 |
| SvREFCNT_dec(message); |
| 1377 |
|
| } |
| 1378 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 1379 |
1 |
| LEAVE; |
| 1380 |
|
| } |
| 1381 |
1 |
| return; |
| 1382 |
|
| } |
| 1383 |
|
| } |
| 1384 |
133 |
▶ | if (strEQ(type_name, "Int")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(type_name, "Int")) { |
10 |
123 |
133 |
|
| 1385 |
20 |
▶ | valid = !SvROK(value_sv) && SvIOK(value_sv) |
Branch: 1 branch
| Branch | True | False | Total |
| valid = !SvROK(value_sv) && SvIOK(value_sv) |
10 |
0 |
10 |
|
| 1386 |
20 |
▶ | && SvIV(value_sv) >= -2147483648LL && SvIV(value_sv) <= 2147483647LL; |
Branch: 3 branches
| Branch | True | False | Total |
| && SvIV(value_sv) >= -2147483648LL && SvIV(value_sv) <= 2147483647LL; |
10 |
0 |
10 |
| && SvIV(value_sv) >= -2147483648LL && SvIV(value_sv) <= 2147483647LL; |
10 |
0 |
10 |
| && SvIV(value_sv) >= -2147483648LL && SvIV(value_sv) <= 2147483647LL; |
10 |
0 |
10 |
|
| 1387 |
123 |
▶ | } else if (strEQ(type_name, "Float")) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (strEQ(type_name, "Float")) { |
0 |
123 |
123 |
|
| 1388 |
0 |
▶ | valid = !SvROK(value_sv) && (SvIOK(value_sv) || SvNOK(value_sv)); |
Branch: 3 branches
| Branch | True | False | Total |
| valid = !SvROK(value_sv) && (SvIOK(value_sv) || SvNOK(value_sv)); |
0 |
0 |
0 |
| valid = !SvROK(value_sv) && (SvIOK(value_sv) || SvNOK(value_sv)); |
0 |
0 |
0 |
| valid = !SvROK(value_sv) && (SvIOK(value_sv) || SvNOK(value_sv)); |
0 |
0 |
0 |
|
| 1389 |
123 |
▶ | } else if (strEQ(type_name, "String")) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (strEQ(type_name, "String")) { |
67 |
56 |
123 |
|
| 1390 |
132 |
▶ | valid = !SvROK(value_sv) && SvPOK(value_sv) |
Branch: 1 branch
| Branch | True | False | Total |
| valid = !SvROK(value_sv) && SvPOK(value_sv) |
65 |
0 |
65 |
|
| 1391 |
132 |
▶ | && !SvIOK(value_sv) && !SvNOK(value_sv); |
Branch: 3 branches
| Branch | True | False | Total |
| && !SvIOK(value_sv) && !SvNOK(value_sv); |
65 |
2 |
67 |
| && !SvIOK(value_sv) && !SvNOK(value_sv); |
65 |
0 |
65 |
| && !SvIOK(value_sv) && !SvNOK(value_sv); |
65 |
0 |
65 |
|
| 1392 |
56 |
▶ | } else if (strEQ(type_name, "Boolean")) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (strEQ(type_name, "Boolean")) { |
29 |
27 |
56 |
|
| 1393 |
29 |
| valid = sv_isobject(value_sv); |
| 1394 |
27 |
▶ | } else if (strEQ(type_name, "ID")) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (strEQ(type_name, "ID")) { |
27 |
0 |
27 |
|
| 1395 |
27 |
▶ | valid = !SvROK(value_sv) && (SvPOK(value_sv) || SvIOK(value_sv)); |
Branch: 3 branches
| Branch | True | False | Total |
| valid = !SvROK(value_sv) && (SvPOK(value_sv) || SvIOK(value_sv)); |
27 |
0 |
27 |
| valid = !SvROK(value_sv) && (SvPOK(value_sv) || SvIOK(value_sv)); |
0 |
27 |
27 |
| valid = !SvROK(value_sv) && (SvPOK(value_sv) || SvIOK(value_sv)); |
0 |
0 |
0 |
|
| 1396 |
|
| } else { |
| 1397 |
0 |
| return; |
| 1398 |
|
| } |
| 1399 |
133 |
▶ | if (!valid) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!valid) { |
3 |
130 |
133 |
|
| 1400 |
3 |
| SV *message = newSVpvf("Value is not a valid %s literal.", type_name); |
| 1401 |
3 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 1402 |
3 |
| SvREFCNT_dec(message); |
| 1403 |
|
| } |
| 1404 |
|
| } |
| 1405 |
|
| } |
| 1406 |
|
| |
| 1407 |
|
| static int |
| 1408 |
3015 |
| gql_validation_values_equal(pTHX_ SV *left_sv, SV *right_sv) { |
| 1409 |
3015 |
▶ | if (left_sv == right_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (left_sv == right_sv) { |
3013 |
2 |
3015 |
|
| 1410 |
3013 |
| return 1; |
| 1411 |
|
| } |
| 1412 |
2 |
▶ | if (!left_sv || !right_sv || SvOK(left_sv) != SvOK(right_sv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!left_sv || !right_sv || SvOK(left_sv) != SvOK(right_sv)) { |
2 |
0 |
2 |
| if (!left_sv || !right_sv || SvOK(left_sv) != SvOK(right_sv)) { |
2 |
0 |
2 |
| if (!left_sv || !right_sv || SvOK(left_sv) != SvOK(right_sv)) { |
0 |
2 |
2 |
|
| 1413 |
0 |
| return 0; |
| 1414 |
|
| } |
| 1415 |
2 |
▶ | if (!SvOK(left_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(left_sv)) { |
0 |
2 |
2 |
|
| 1416 |
0 |
| return 1; |
| 1417 |
|
| } |
| 1418 |
2 |
▶ | if (SvROK(left_sv) != SvROK(right_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(left_sv) != SvROK(right_sv)) { |
0 |
2 |
2 |
|
| 1419 |
0 |
| return 0; |
| 1420 |
|
| } |
| 1421 |
2 |
▶ | if (!SvROK(left_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(left_sv)) { |
1 |
1 |
2 |
|
| 1422 |
1 |
| return sv_eq(left_sv, right_sv); |
| 1423 |
|
| } |
| 1424 |
1 |
▶ | if (SvTYPE(SvRV(left_sv)) != SvTYPE(SvRV(right_sv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(left_sv)) != SvTYPE(SvRV(right_sv))) { |
0 |
1 |
1 |
|
| 1425 |
0 |
| return 0; |
| 1426 |
|
| } |
| 1427 |
1 |
▶ | if (SvTYPE(SvRV(left_sv)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(left_sv)) == SVt_PVAV) { |
0 |
1 |
1 |
|
| 1428 |
0 |
| AV *left_av = (AV *)SvRV(left_sv); |
| 1429 |
0 |
| AV *right_av = (AV *)SvRV(right_sv); |
| 1430 |
|
| I32 i; |
| 1431 |
0 |
▶ | if (av_len(left_av) != av_len(right_av)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(left_av) != av_len(right_av)) { |
0 |
0 |
0 |
|
| 1432 |
0 |
| return 0; |
| 1433 |
|
| } |
| 1434 |
0 |
▶ | for (i = 0; i <= av_len(left_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(left_av); i++) { |
0 |
0 |
0 |
|
| 1435 |
0 |
| SV **left_item = av_fetch(left_av, i, 0); |
| 1436 |
0 |
| SV **right_item = av_fetch(right_av, i, 0); |
| 1437 |
0 |
▶ | if (!gql_validation_values_equal(aTHX_ left_item ? *left_item : NULL, right_item ? *right_item : NULL)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!gql_validation_values_equal(aTHX_ left_item ? *left_item : NULL, right_item ? *right_item : NULL)) { |
0 |
0 |
0 |
| if (!gql_validation_values_equal(aTHX_ left_item ? *left_item : NULL, right_item ? *right_item : NULL)) { |
0 |
0 |
0 |
| if (!gql_validation_values_equal(aTHX_ left_item ? *left_item : NULL, right_item ? *right_item : NULL)) { |
0 |
0 |
0 |
|
| 1438 |
0 |
| return 0; |
| 1439 |
|
| } |
| 1440 |
|
| } |
| 1441 |
0 |
| return 1; |
| 1442 |
|
| } |
| 1443 |
1 |
▶ | if (SvTYPE(SvRV(left_sv)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(left_sv)) == SVt_PVHV) { |
1 |
0 |
1 |
|
| 1444 |
1 |
| HV *left_hv = (HV *)SvRV(left_sv); |
| 1445 |
1 |
| HV *right_hv = (HV *)SvRV(right_sv); |
| 1446 |
|
| HE *he; |
| 1447 |
1 |
▶ | if (HvUSEDKEYS(left_hv) != HvUSEDKEYS(right_hv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (HvUSEDKEYS(left_hv) != HvUSEDKEYS(right_hv)) { |
0 |
1 |
1 |
| if (HvUSEDKEYS(left_hv) != HvUSEDKEYS(right_hv)) { |
0 |
1 |
1 |
| if (HvUSEDKEYS(left_hv) != HvUSEDKEYS(right_hv)) { |
0 |
1 |
1 |
|
| 1448 |
0 |
| return 0; |
| 1449 |
|
| } |
| 1450 |
1 |
| hv_iterinit(left_hv); |
| 1451 |
1 |
▶ | while ((he = hv_iternext(left_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(left_hv))) { |
1 |
0 |
1 |
|
| 1452 |
1 |
| SV *key_sv = hv_iterkeysv(he); |
| 1453 |
1 |
| HE *right_he = hv_fetch_ent(right_hv, key_sv, 0, 0); |
| 1454 |
1 |
▶ | if (!right_he || !gql_validation_values_equal(aTHX_ HeVAL(he), HeVAL(right_he))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!right_he || !gql_validation_values_equal(aTHX_ HeVAL(he), HeVAL(right_he))) { |
1 |
0 |
1 |
| if (!right_he || !gql_validation_values_equal(aTHX_ HeVAL(he), HeVAL(right_he))) { |
1 |
0 |
1 |
|
| 1455 |
1 |
| return 0; |
| 1456 |
|
| } |
| 1457 |
|
| } |
| 1458 |
0 |
| return 1; |
| 1459 |
|
| } |
| 1460 |
0 |
| return gql_validation_values_equal(aTHX_ SvRV(left_sv), SvRV(right_sv)); |
| 1461 |
|
| } |
| 1462 |
|
| |
| 1463 |
|
| static void |
| 1464 |
3091 |
| gql_validation_collect_merge_fields( |
| 1465 |
|
| pTHX_ AV *out_av, |
| 1466 |
|
| AV *selections_av, |
| 1467 |
|
| SV *parent_type_name_sv, |
| 1468 |
|
| HV *fragments_hv, |
| 1469 |
|
| HV *visited_fragments_hv |
| 1470 |
|
| ) { |
| 1471 |
|
| I32 i; |
| 1472 |
3091 |
▶ | if (!selections_av) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!selections_av) { |
0 |
3091 |
3091 |
|
| 1473 |
0 |
| return; |
| 1474 |
|
| } |
| 1475 |
9882 |
▶ | for (i = 0; i <= av_len(selections_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(selections_av); i++) { |
6791 |
3091 |
9882 |
|
| 1476 |
6791 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 1477 |
|
| HV *selection_hv; |
| 1478 |
|
| SV **kind_svp; |
| 1479 |
6791 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
6791 |
0 |
6791 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
6791 |
0 |
6791 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
0 |
6791 |
6791 |
|
| 1480 |
0 |
| continue; |
| 1481 |
|
| } |
| 1482 |
6791 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 1483 |
6791 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 1484 |
6791 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
6791 |
0 |
6791 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
6791 |
0 |
6791 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
6791 |
6791 |
|
| 1485 |
0 |
| continue; |
| 1486 |
|
| } |
| 1487 |
13582 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
5716 |
1075 |
6791 |
|
| 1488 |
5716 |
| HV *entry_hv = newHV(); |
| 1489 |
5716 |
| gql_store_sv(entry_hv, "field", newSVsv(*selection_svp)); |
| 1490 |
5716 |
| gql_store_sv(entry_hv, "parent_type", newSVsv(parent_type_name_sv)); |
| 1491 |
5716 |
| av_push(out_av, newRV_noinc((SV *)entry_hv)); |
| 1492 |
5716 |
| continue; |
| 1493 |
|
| } |
| 1494 |
2150 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
1038 |
37 |
1075 |
|
| 1495 |
1038 |
| SV **on_svp = hv_fetch(selection_hv, "on", 2, 0); |
| 1496 |
1038 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 1497 |
1038 |
▶ | SV *target_type_sv = on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *target_type_sv = on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv; |
1038 |
0 |
1038 |
| SV *target_type_sv = on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv; |
1038 |
0 |
1038 |
|
| 1498 |
1038 |
▶ | if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
1038 |
0 |
1038 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
1038 |
0 |
1038 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
1038 |
0 |
1038 |
|
| 1499 |
1038 |
| gql_validation_collect_merge_fields( |
| 1500 |
1038 |
| aTHX_ out_av, (AV *)SvRV(*nested_svp), target_type_sv, |
| 1501 |
|
| fragments_hv, visited_fragments_hv |
| 1502 |
|
| ); |
| 1503 |
|
| } |
| 1504 |
1038 |
| continue; |
| 1505 |
|
| } |
| 1506 |
74 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
37 |
0 |
37 |
|
| 1507 |
37 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 1508 |
|
| HE *fragment_he; |
| 1509 |
|
| STRLEN name_len; |
| 1510 |
|
| const char *name; |
| 1511 |
37 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
37 |
0 |
37 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
37 |
37 |
|
| 1512 |
1 |
| continue; |
| 1513 |
|
| } |
| 1514 |
37 |
| name = SvPV(*name_svp, name_len); |
| 1515 |
37 |
▶ | if (hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
1 |
36 |
37 |
|
| 1516 |
1 |
| continue; |
| 1517 |
|
| } |
| 1518 |
36 |
| fragment_he = hv_fetch_ent(fragments_hv, *name_svp, 0, 0); |
| 1519 |
36 |
▶ | if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
36 |
0 |
36 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
36 |
0 |
36 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
36 |
0 |
36 |
|
| 1520 |
36 |
| HV *fragment_hv = (HV *)SvRV(HeVAL(fragment_he)); |
| 1521 |
36 |
| SV **on_svp = hv_fetch(fragment_hv, "on", 2, 0); |
| 1522 |
36 |
| SV **nested_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 1523 |
36 |
| (void)hv_store_ent(visited_fragments_hv, *name_svp, newSViv(1), 0); |
| 1524 |
36 |
▶ | if (on_svp && SvOK(*on_svp) && nested_svp && SvROK(*nested_svp) |
Branch: 4 branches
| Branch | True | False | Total |
| if (on_svp && SvOK(*on_svp) && nested_svp && SvROK(*nested_svp) |
36 |
0 |
36 |
| if (on_svp && SvOK(*on_svp) && nested_svp && SvROK(*nested_svp) |
36 |
0 |
36 |
| if (on_svp && SvOK(*on_svp) && nested_svp && SvROK(*nested_svp) |
36 |
0 |
36 |
| if (on_svp && SvOK(*on_svp) && nested_svp && SvROK(*nested_svp) |
36 |
0 |
36 |
|
| 1525 |
36 |
▶ | && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
36 |
0 |
36 |
|
| 1526 |
36 |
| gql_validation_collect_merge_fields( |
| 1527 |
36 |
| aTHX_ out_av, (AV *)SvRV(*nested_svp), *on_svp, |
| 1528 |
|
| fragments_hv, visited_fragments_hv |
| 1529 |
|
| ); |
| 1530 |
|
| } |
| 1531 |
|
| } |
| 1532 |
|
| } |
| 1533 |
|
| } |
| 1534 |
|
| } |
| 1535 |
|
| |
| 1536 |
|
| static SV * |
| 1537 |
7034 |
| gql_validation_field_type_sv( |
| 1538 |
|
| pTHX_ SV *compiled_sv, |
| 1539 |
|
| SV *parent_type_name_sv, |
| 1540 |
|
| SV *field_name_sv |
| 1541 |
|
| ) { |
| 1542 |
7034 |
| HV *parent_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, parent_type_name_sv); |
| 1543 |
7034 |
▶ | SV **fields_svp = parent_hv ? hv_fetch(parent_hv, "fields", 6, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **fields_svp = parent_hv ? hv_fetch(parent_hv, "fields", 6, 0) : NULL; |
7034 |
0 |
7034 |
|
| 1544 |
|
| HE *field_he; |
| 1545 |
|
| SV **type_svp; |
| 1546 |
7034 |
▶ | if (!fields_svp || !SvROK(*fields_svp) || SvTYPE(SvRV(*fields_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!fields_svp || !SvROK(*fields_svp) || SvTYPE(SvRV(*fields_svp)) != SVt_PVHV) { |
7034 |
0 |
7034 |
| if (!fields_svp || !SvROK(*fields_svp) || SvTYPE(SvRV(*fields_svp)) != SVt_PVHV) { |
7034 |
0 |
7034 |
| if (!fields_svp || !SvROK(*fields_svp) || SvTYPE(SvRV(*fields_svp)) != SVt_PVHV) { |
0 |
7034 |
7034 |
|
| 1547 |
0 |
| return NULL; |
| 1548 |
|
| } |
| 1549 |
7034 |
| field_he = hv_fetch_ent((HV *)SvRV(*fields_svp), field_name_sv, 0, 0); |
| 1550 |
7034 |
▶ | if (!field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
7034 |
0 |
7034 |
| if (!field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
7034 |
0 |
7034 |
| if (!field_he || !SvROK(HeVAL(field_he)) || SvTYPE(SvRV(HeVAL(field_he))) != SVt_PVHV) { |
0 |
7034 |
7034 |
|
| 1551 |
0 |
| return NULL; |
| 1552 |
|
| } |
| 1553 |
7034 |
| type_svp = hv_fetch((HV *)SvRV(HeVAL(field_he)), "type", 4, 0); |
| 1554 |
7034 |
▶ | return type_svp ? *type_svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return type_svp ? *type_svp : NULL; |
7034 |
0 |
7034 |
|
| 1555 |
|
| } |
| 1556 |
|
| |
| 1557 |
|
| static int |
| 1558 |
4013 |
| gql_validation_same_response_shape(pTHX_ SV *compiled_sv, SV *left_type_sv, SV *right_type_sv) { |
| 1559 |
|
| HV *left_hv; |
| 1560 |
|
| HV *right_hv; |
| 1561 |
|
| SV **left_kind_svp; |
| 1562 |
|
| SV **right_kind_svp; |
| 1563 |
|
| const char *left_kind; |
| 1564 |
|
| const char *right_kind; |
| 1565 |
4013 |
▶ | if (!left_type_sv || !right_type_sv || !SvROK(left_type_sv) || !SvROK(right_type_sv) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!left_type_sv || !right_type_sv || !SvROK(left_type_sv) || !SvROK(right_type_sv) |
4013 |
0 |
4013 |
| if (!left_type_sv || !right_type_sv || !SvROK(left_type_sv) || !SvROK(right_type_sv) |
4013 |
0 |
4013 |
| if (!left_type_sv || !right_type_sv || !SvROK(left_type_sv) || !SvROK(right_type_sv) |
4013 |
0 |
4013 |
| if (!left_type_sv || !right_type_sv || !SvROK(left_type_sv) || !SvROK(right_type_sv) |
4013 |
0 |
4013 |
|
| 1566 |
4013 |
▶ | || SvTYPE(SvRV(left_type_sv)) != SVt_PVHV || SvTYPE(SvRV(right_type_sv)) != SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| || SvTYPE(SvRV(left_type_sv)) != SVt_PVHV || SvTYPE(SvRV(right_type_sv)) != SVt_PVHV) { |
4013 |
0 |
4013 |
| || SvTYPE(SvRV(left_type_sv)) != SVt_PVHV || SvTYPE(SvRV(right_type_sv)) != SVt_PVHV) { |
0 |
4013 |
4013 |
|
| 1567 |
0 |
| return 0; |
| 1568 |
|
| } |
| 1569 |
4013 |
| left_hv = (HV *)SvRV(left_type_sv); |
| 1570 |
4013 |
| right_hv = (HV *)SvRV(right_type_sv); |
| 1571 |
4013 |
| left_kind_svp = hv_fetch(left_hv, "kind", 4, 0); |
| 1572 |
4013 |
| right_kind_svp = hv_fetch(right_hv, "kind", 4, 0); |
| 1573 |
4013 |
▶ | if (!left_kind_svp || !right_kind_svp || !SvOK(*left_kind_svp) || !SvOK(*right_kind_svp)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!left_kind_svp || !right_kind_svp || !SvOK(*left_kind_svp) || !SvOK(*right_kind_svp)) { |
4013 |
0 |
4013 |
| if (!left_kind_svp || !right_kind_svp || !SvOK(*left_kind_svp) || !SvOK(*right_kind_svp)) { |
4013 |
0 |
4013 |
| if (!left_kind_svp || !right_kind_svp || !SvOK(*left_kind_svp) || !SvOK(*right_kind_svp)) { |
4013 |
0 |
4013 |
| if (!left_kind_svp || !right_kind_svp || !SvOK(*left_kind_svp) || !SvOK(*right_kind_svp)) { |
0 |
4013 |
4013 |
|
| 1574 |
0 |
| return 0; |
| 1575 |
|
| } |
| 1576 |
4013 |
| left_kind = SvPV_nolen(*left_kind_svp); |
| 1577 |
4013 |
▶ | right_kind = SvPV_nolen(*right_kind_svp); |
Branch: 1 branch
| Branch | True | False | Total |
| right_kind = SvPV_nolen(*right_kind_svp); |
4013 |
0 |
4013 |
|
| 1578 |
4013 |
▶ | if (strEQ(left_kind, "NON_NULL") || strEQ(right_kind, "NON_NULL") |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(left_kind, "NON_NULL") || strEQ(right_kind, "NON_NULL") |
3013 |
1000 |
4013 |
| if (strEQ(left_kind, "NON_NULL") || strEQ(right_kind, "NON_NULL") |
3010 |
3 |
3013 |
|
| 1579 |
3010 |
▶ | || strEQ(left_kind, "LIST") || strEQ(right_kind, "LIST")) { |
Branch: 2 branches
| Branch | True | False | Total |
| || strEQ(left_kind, "LIST") || strEQ(right_kind, "LIST")) { |
3010 |
0 |
3010 |
| || strEQ(left_kind, "LIST") || strEQ(right_kind, "LIST")) { |
0 |
3010 |
3010 |
|
| 1580 |
|
| SV **left_of_svp; |
| 1581 |
|
| SV **right_of_svp; |
| 1582 |
1003 |
▶ | if (!strEQ(left_kind, right_kind)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strEQ(left_kind, right_kind)) { |
4 |
999 |
1003 |
|
| 1583 |
4 |
| return 0; |
| 1584 |
|
| } |
| 1585 |
999 |
| left_of_svp = hv_fetch(left_hv, "of", 2, 0); |
| 1586 |
999 |
| right_of_svp = hv_fetch(right_hv, "of", 2, 0); |
| 1587 |
999 |
▶ | return left_of_svp && right_of_svp |
Branch: 1 branch
| Branch | True | False | Total |
| return left_of_svp && right_of_svp |
999 |
0 |
999 |
|
| 1588 |
1998 |
▶ | && gql_validation_same_response_shape(aTHX_ compiled_sv, *left_of_svp, *right_of_svp); |
Branch: 2 branches
| Branch | True | False | Total |
| && gql_validation_same_response_shape(aTHX_ compiled_sv, *left_of_svp, *right_of_svp); |
999 |
0 |
999 |
| && gql_validation_same_response_shape(aTHX_ compiled_sv, *left_of_svp, *right_of_svp); |
999 |
0 |
999 |
|
| 1589 |
|
| } |
| 1590 |
3010 |
▶ | if (strEQ(left_kind, "NAMED") && strEQ(right_kind, "NAMED")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(left_kind, "NAMED") && strEQ(right_kind, "NAMED")) { |
3010 |
0 |
3010 |
| if (strEQ(left_kind, "NAMED") && strEQ(right_kind, "NAMED")) { |
3010 |
0 |
3010 |
|
| 1591 |
3010 |
| SV **left_name_svp = hv_fetch(left_hv, "name", 4, 0); |
| 1592 |
3010 |
| SV **right_name_svp = hv_fetch(right_hv, "name", 4, 0); |
| 1593 |
3010 |
| HV *left_named_hv = left_name_svp |
| 1594 |
3010 |
▶ | ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *left_name_svp) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *left_name_svp) : NULL; |
3010 |
0 |
3010 |
|
| 1595 |
3010 |
| HV *right_named_hv = right_name_svp |
| 1596 |
3010 |
▶ | ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *right_name_svp) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *right_name_svp) : NULL; |
3010 |
0 |
3010 |
|
| 1597 |
3010 |
▶ | SV **left_named_kind_svp = left_named_hv ? hv_fetch(left_named_hv, "kind", 4, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **left_named_kind_svp = left_named_hv ? hv_fetch(left_named_hv, "kind", 4, 0) : NULL; |
3010 |
0 |
3010 |
|
| 1598 |
3010 |
▶ | SV **right_named_kind_svp = right_named_hv ? hv_fetch(right_named_hv, "kind", 4, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **right_named_kind_svp = right_named_hv ? hv_fetch(right_named_hv, "kind", 4, 0) : NULL; |
3010 |
0 |
3010 |
|
| 1599 |
3010 |
▶ | int left_leaf = left_named_kind_svp && SvOK(*left_named_kind_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| int left_leaf = left_named_kind_svp && SvOK(*left_named_kind_svp) |
3010 |
0 |
3010 |
|
| 1600 |
10033 |
▶ | && (strEQ(SvPV_nolen(*left_named_kind_svp), "SCALAR") |
Branch: 2 branches
| Branch | True | False | Total |
| && (strEQ(SvPV_nolen(*left_named_kind_svp), "SCALAR") |
3010 |
0 |
3010 |
| && (strEQ(SvPV_nolen(*left_named_kind_svp), "SCALAR") |
1003 |
2007 |
3010 |
|
| 1601 |
2006 |
▶ | || strEQ(SvPV_nolen(*left_named_kind_svp), "ENUM")); |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(SvPV_nolen(*left_named_kind_svp), "ENUM")); |
0 |
1003 |
1003 |
|
| 1602 |
3010 |
▶ | int right_leaf = right_named_kind_svp && SvOK(*right_named_kind_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| int right_leaf = right_named_kind_svp && SvOK(*right_named_kind_svp) |
3010 |
0 |
3010 |
|
| 1603 |
10033 |
▶ | && (strEQ(SvPV_nolen(*right_named_kind_svp), "SCALAR") |
Branch: 2 branches
| Branch | True | False | Total |
| && (strEQ(SvPV_nolen(*right_named_kind_svp), "SCALAR") |
3010 |
0 |
3010 |
| && (strEQ(SvPV_nolen(*right_named_kind_svp), "SCALAR") |
1003 |
2007 |
3010 |
|
| 1604 |
2006 |
▶ | || strEQ(SvPV_nolen(*right_named_kind_svp), "ENUM")); |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(SvPV_nolen(*right_named_kind_svp), "ENUM")); |
0 |
1003 |
1003 |
|
| 1605 |
3010 |
▶ | if (left_leaf || right_leaf) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (left_leaf || right_leaf) { |
1003 |
2007 |
3010 |
| if (left_leaf || right_leaf) { |
0 |
1003 |
1003 |
|
| 1606 |
2007 |
▶ | return left_leaf && right_leaf && left_name_svp && right_name_svp |
Branch: 3 branches
| Branch | True | False | Total |
| return left_leaf && right_leaf && left_name_svp && right_name_svp |
2007 |
0 |
2007 |
| return left_leaf && right_leaf && left_name_svp && right_name_svp |
2007 |
0 |
2007 |
| return left_leaf && right_leaf && left_name_svp && right_name_svp |
2007 |
0 |
2007 |
|
| 1607 |
4014 |
▶ | && sv_eq(*left_name_svp, *right_name_svp); |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*left_name_svp, *right_name_svp); |
2007 |
0 |
2007 |
| && sv_eq(*left_name_svp, *right_name_svp); |
2007 |
0 |
2007 |
|
| 1608 |
|
| } |
| 1609 |
1003 |
| return 1; |
| 1610 |
|
| } |
| 1611 |
0 |
| return 0; |
| 1612 |
|
| } |
| 1613 |
|
| |
| 1614 |
|
| static void |
| 1615 |
2017 |
| gql_validation_validate_field_merging( |
| 1616 |
|
| pTHX_ AV *errors_av, |
| 1617 |
|
| SV *compiled_sv, |
| 1618 |
|
| AV *selections_av, |
| 1619 |
|
| SV *parent_type_name_sv, |
| 1620 |
|
| HV *fragments_hv |
| 1621 |
|
| ) { |
| 1622 |
2017 |
| HV *fields_by_key_hv = newHV(); |
| 1623 |
2017 |
| HV *visited_fragments_hv = newHV(); |
| 1624 |
2017 |
| AV *fields_av = newAV(); |
| 1625 |
|
| I32 i; |
| 1626 |
2017 |
| gql_validation_collect_merge_fields( |
| 1627 |
|
| aTHX_ fields_av, selections_av, parent_type_name_sv, |
| 1628 |
|
| fragments_hv, visited_fragments_hv |
| 1629 |
|
| ); |
| 1630 |
7733 |
▶ | for (i = 0; i <= av_len(fields_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(fields_av); i++) { |
5716 |
2017 |
7733 |
|
| 1631 |
5716 |
| SV **entry_svp = av_fetch(fields_av, i, 0); |
| 1632 |
|
| HV *entry_hv; |
| 1633 |
|
| SV **selection_svp; |
| 1634 |
|
| SV **parent_svp; |
| 1635 |
|
| HV *selection_hv; |
| 1636 |
|
| SV **name_svp; |
| 1637 |
|
| SV **alias_svp; |
| 1638 |
|
| SV *response_key_sv; |
| 1639 |
|
| HE *previous_he; |
| 1640 |
|
| HV *bucket_hv; |
| 1641 |
|
| AV *previous_av; |
| 1642 |
|
| AV *merge_entries_av; |
| 1643 |
|
| I32 j; |
| 1644 |
5716 |
| int keep_entry = 1; |
| 1645 |
5716 |
▶ | if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
5716 |
0 |
5716 |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
5716 |
0 |
5716 |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
0 |
5716 |
5716 |
|
| 1646 |
0 |
| continue; |
| 1647 |
|
| } |
| 1648 |
5716 |
| entry_hv = (HV *)SvRV(*entry_svp); |
| 1649 |
5716 |
| selection_svp = hv_fetch(entry_hv, "field", 5, 0); |
| 1650 |
5716 |
| parent_svp = hv_fetch(entry_hv, "parent_type", 11, 0); |
| 1651 |
5716 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV |
5716 |
0 |
5716 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV |
5716 |
0 |
5716 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV |
5716 |
0 |
5716 |
|
| 1652 |
5716 |
▶ | || !parent_svp || !SvOK(*parent_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| || !parent_svp || !SvOK(*parent_svp)) { |
5716 |
0 |
5716 |
| || !parent_svp || !SvOK(*parent_svp)) { |
0 |
5716 |
5716 |
|
| 1653 |
0 |
| continue; |
| 1654 |
|
| } |
| 1655 |
5716 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 1656 |
5716 |
| name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 1657 |
5716 |
| alias_svp = hv_fetch(selection_hv, "alias", 5, 0); |
| 1658 |
5716 |
▶ | if (!name_svp || !SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) { |
5716 |
0 |
5716 |
| if (!name_svp || !SvOK(*name_svp)) { |
0 |
5716 |
5716 |
|
| 1659 |
0 |
| continue; |
| 1660 |
|
| } |
| 1661 |
5716 |
▶ | response_key_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
Branch: 2 branches
| Branch | True | False | Total |
| response_key_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
2323 |
3393 |
5716 |
| response_key_sv = alias_svp && SvOK(*alias_svp) ? *alias_svp : *name_svp; |
2323 |
0 |
2323 |
|
| 1662 |
5716 |
| previous_he = hv_fetch_ent(fields_by_key_hv, response_key_sv, 0, 0); |
| 1663 |
5716 |
▶ | if (!previous_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!previous_he) { |
2702 |
3014 |
5716 |
|
| 1664 |
2702 |
| bucket_hv = newHV(); |
| 1665 |
2702 |
| previous_av = newAV(); |
| 1666 |
2702 |
| merge_entries_av = newAV(); |
| 1667 |
2702 |
| gql_store_sv(bucket_hv, "entries", newRV_noinc((SV *)previous_av)); |
| 1668 |
2702 |
| gql_store_sv(bucket_hv, "merge_entries", newRV_noinc((SV *)merge_entries_av)); |
| 1669 |
2702 |
| (void)hv_store_ent(fields_by_key_hv, response_key_sv, newRV_noinc((SV *)bucket_hv), 0); |
| 1670 |
|
| } else { |
| 1671 |
|
| SV **entries_svp; |
| 1672 |
|
| SV **merge_entries_svp; |
| 1673 |
|
| SV **conflicted_svp; |
| 1674 |
3014 |
| bucket_hv = (HV *)SvRV(HeVAL(previous_he)); |
| 1675 |
3014 |
| conflicted_svp = hv_fetch(bucket_hv, "conflicted", 10, 0); |
| 1676 |
3014 |
▶ | if (conflicted_svp && SvTRUE(*conflicted_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (conflicted_svp && SvTRUE(*conflicted_svp)) { |
0 |
3014 |
3014 |
| if (conflicted_svp && SvTRUE(*conflicted_svp)) { |
0 |
0 |
0 |
|
| 1677 |
0 |
| continue; |
| 1678 |
|
| } |
| 1679 |
3014 |
| entries_svp = hv_fetch(bucket_hv, "entries", 7, 0); |
| 1680 |
3014 |
| merge_entries_svp = hv_fetch(bucket_hv, "merge_entries", 13, 0); |
| 1681 |
3014 |
| previous_av = (AV *)SvRV(*entries_svp); |
| 1682 |
3014 |
| merge_entries_av = (AV *)SvRV(*merge_entries_svp); |
| 1683 |
|
| } |
| 1684 |
5716 |
| av_push(merge_entries_av, newSVsv(*entry_svp)); |
| 1685 |
8725 |
▶ | for (j = 0; j <= av_len(previous_av); j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j <= av_len(previous_av); j++) { |
3014 |
5711 |
8725 |
|
| 1686 |
3014 |
| SV **previous_svp = av_fetch(previous_av, j, 0); |
| 1687 |
3014 |
| HV *previous_entry_hv = (HV *)SvRV(*previous_svp); |
| 1688 |
3014 |
| SV **previous_field_svp = hv_fetch(previous_entry_hv, "field", 5, 0); |
| 1689 |
3014 |
| SV **previous_parent_svp = hv_fetch(previous_entry_hv, "parent_type", 11, 0); |
| 1690 |
3014 |
| HV *previous_hv = (HV *)SvRV(*previous_field_svp); |
| 1691 |
3014 |
| SV **previous_name_svp = hv_fetch(previous_hv, "name", 4, 0); |
| 1692 |
3014 |
| SV **arguments_svp = hv_fetch(selection_hv, "arguments", 9, 0); |
| 1693 |
3014 |
| SV **previous_arguments_svp = hv_fetch(previous_hv, "arguments", 9, 0); |
| 1694 |
3014 |
| SV *field_type_sv = gql_validation_field_type_sv( |
| 1695 |
|
| aTHX_ compiled_sv, *parent_svp, *name_svp |
| 1696 |
|
| ); |
| 1697 |
3014 |
| SV *previous_field_type_sv = gql_validation_field_type_sv( |
| 1698 |
|
| aTHX_ compiled_sv, *previous_parent_svp, *previous_name_svp |
| 1699 |
|
| ); |
| 1700 |
3014 |
▶ | int same_name = previous_name_svp && SvOK(*previous_name_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| int same_name = previous_name_svp && SvOK(*previous_name_svp) |
3014 |
0 |
3014 |
|
| 1701 |
6028 |
▶ | && sv_eq(*name_svp, *previous_name_svp); |
Branch: 2 branches
| Branch | True | False | Total |
| && sv_eq(*name_svp, *previous_name_svp); |
3014 |
0 |
3014 |
| && sv_eq(*name_svp, *previous_name_svp); |
3009 |
5 |
3014 |
|
| 1702 |
3014 |
▶ | int same_arguments = gql_validation_values_equal( |
Branch: 2 branches
| Branch | True | False | Total |
| int same_arguments = gql_validation_values_equal( |
1 |
3013 |
3014 |
| int same_arguments = gql_validation_values_equal( |
1 |
3013 |
3014 |
|
| 1703 |
|
| aTHX_ arguments_svp ? *arguments_svp : NULL, |
| 1704 |
|
| previous_arguments_svp ? *previous_arguments_svp : NULL |
| 1705 |
|
| ); |
| 1706 |
3014 |
▶ | int types_overlap = previous_parent_svp && SvOK(*previous_parent_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| int types_overlap = previous_parent_svp && SvOK(*previous_parent_svp) |
3014 |
0 |
3014 |
|
| 1707 |
6028 |
▶ | && gql_validation_selection_types_overlap( |
Branch: 2 branches
| Branch | True | False | Total |
| && gql_validation_selection_types_overlap( |
3014 |
0 |
3014 |
| && gql_validation_selection_types_overlap( |
3005 |
9 |
3014 |
|
| 1708 |
|
| aTHX_ compiled_sv, *parent_svp, *previous_parent_svp |
| 1709 |
|
| ); |
| 1710 |
3014 |
| int same_shape = gql_validation_same_response_shape( |
| 1711 |
|
| aTHX_ compiled_sv, field_type_sv, previous_field_type_sv |
| 1712 |
|
| ); |
| 1713 |
3014 |
▶ | if (!same_shape || (types_overlap && (!same_name || !same_arguments))) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!same_shape || (types_overlap && (!same_name || !same_arguments))) { |
3010 |
4 |
3014 |
| if (!same_shape || (types_overlap && (!same_name || !same_arguments))) { |
3002 |
8 |
3010 |
| if (!same_shape || (types_overlap && (!same_name || !same_arguments))) { |
3002 |
0 |
3002 |
| if (!same_shape || (types_overlap && (!same_name || !same_arguments))) { |
1 |
3001 |
3002 |
|
| 1714 |
5 |
| SV **location_svp = hv_fetch(selection_hv, "location", 8, 0); |
| 1715 |
5 |
| SV *message = newSVpvf( |
| 1716 |
|
| "Fields '%s' conflict because they select different fields or arguments.", |
| 1717 |
|
| SvPV_nolen(response_key_sv) |
| 1718 |
|
| ); |
| 1719 |
10 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
5 |
0 |
5 |
|
| 1720 |
5 |
| SvREFCNT_dec(message); |
| 1721 |
5 |
| gql_store_sv(bucket_hv, "conflicted", newSViv(1)); |
| 1722 |
5 |
| keep_entry = 0; |
| 1723 |
5 |
| break; |
| 1724 |
|
| } |
| 1725 |
3009 |
▶ | if (same_name && same_arguments && same_shape) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (same_name && same_arguments && same_shape) { |
3008 |
1 |
3009 |
| if (same_name && same_arguments && same_shape) { |
3008 |
0 |
3008 |
| if (same_name && same_arguments && same_shape) { |
3008 |
0 |
3008 |
|
| 1726 |
3008 |
▶ | if (sv_eq(*parent_svp, *previous_parent_svp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_eq(*parent_svp, *previous_parent_svp)) { |
3001 |
7 |
3008 |
|
| 1727 |
|
| /* Keep one comparison representative for an identical signature. |
| 1728 |
|
| * Composite selections remain in merge_entries and are validated |
| 1729 |
|
| * together once at the next depth. */ |
| 1730 |
3001 |
| keep_entry = 0; |
| 1731 |
|
| } |
| 1732 |
|
| } |
| 1733 |
|
| } |
| 1734 |
5716 |
▶ | if (keep_entry) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (keep_entry) { |
2710 |
3006 |
5716 |
|
| 1735 |
2710 |
| av_push(previous_av, newSVsv(*entry_svp)); |
| 1736 |
|
| } |
| 1737 |
|
| } |
| 1738 |
|
| { |
| 1739 |
|
| HE *bucket_he; |
| 1740 |
2017 |
| hv_iterinit(fields_by_key_hv); |
| 1741 |
4719 |
▶ | while ((bucket_he = hv_iternext(fields_by_key_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((bucket_he = hv_iternext(fields_by_key_hv))) { |
2702 |
2017 |
4719 |
|
| 1742 |
2702 |
| HV *bucket_hv = (HV *)SvRV(HeVAL(bucket_he)); |
| 1743 |
2702 |
| SV **conflicted_svp = hv_fetch(bucket_hv, "conflicted", 10, 0); |
| 1744 |
2702 |
| SV **entries_svp = hv_fetch(bucket_hv, "merge_entries", 13, 0); |
| 1745 |
|
| AV *entries_av; |
| 1746 |
|
| AV *combined_av; |
| 1747 |
2702 |
| SV *first_named_type_sv = NULL; |
| 1748 |
|
| I32 entry_i; |
| 1749 |
2702 |
▶ | if ((conflicted_svp && SvTRUE(*conflicted_svp)) || !entries_svp |
Branch: 3 branches
| Branch | True | False | Total |
| if ((conflicted_svp && SvTRUE(*conflicted_svp)) || !entries_svp |
5 |
2697 |
2702 |
| if ((conflicted_svp && SvTRUE(*conflicted_svp)) || !entries_svp |
0 |
5 |
5 |
| if ((conflicted_svp && SvTRUE(*conflicted_svp)) || !entries_svp |
2697 |
0 |
2697 |
|
| 1750 |
2697 |
▶ | || !SvROK(*entries_svp) || SvTYPE(SvRV(*entries_svp)) != SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| || !SvROK(*entries_svp) || SvTYPE(SvRV(*entries_svp)) != SVt_PVAV) { |
2697 |
0 |
2697 |
| || !SvROK(*entries_svp) || SvTYPE(SvRV(*entries_svp)) != SVt_PVAV) { |
0 |
2697 |
2697 |
|
| 1751 |
5 |
| continue; |
| 1752 |
|
| } |
| 1753 |
2697 |
| entries_av = (AV *)SvRV(*entries_svp); |
| 1754 |
2697 |
▶ | if (av_len(entries_av) < 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(entries_av) < 1) { |
2682 |
15 |
2697 |
|
| 1755 |
2682 |
| continue; |
| 1756 |
|
| } |
| 1757 |
15 |
| combined_av = newAV(); |
| 1758 |
3039 |
▶ | for (entry_i = 0; entry_i <= av_len(entries_av); entry_i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (entry_i = 0; entry_i <= av_len(entries_av); entry_i++) { |
3024 |
15 |
3039 |
|
| 1759 |
3024 |
| SV **entry_svp = av_fetch(entries_av, entry_i, 0); |
| 1760 |
|
| HV *entry_hv; |
| 1761 |
|
| SV **field_svp; |
| 1762 |
|
| SV **parent_svp; |
| 1763 |
|
| HV *field_hv; |
| 1764 |
|
| SV **name_svp; |
| 1765 |
|
| SV **selections_svp; |
| 1766 |
|
| SV *field_type_sv; |
| 1767 |
|
| SV *named_type_sv; |
| 1768 |
|
| HV *inline_hv; |
| 1769 |
3024 |
▶ | if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
3024 |
0 |
3024 |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
3024 |
0 |
3024 |
| if (!entry_svp || !SvROK(*entry_svp) || SvTYPE(SvRV(*entry_svp)) != SVt_PVHV) { |
0 |
3024 |
3024 |
|
| 1770 |
0 |
| continue; |
| 1771 |
|
| } |
| 1772 |
3024 |
| entry_hv = (HV *)SvRV(*entry_svp); |
| 1773 |
3024 |
| field_svp = hv_fetch(entry_hv, "field", 5, 0); |
| 1774 |
3024 |
| parent_svp = hv_fetch(entry_hv, "parent_type", 11, 0); |
| 1775 |
3024 |
▶ | if (!field_svp || !SvROK(*field_svp) || !parent_svp) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!field_svp || !SvROK(*field_svp) || !parent_svp) { |
3024 |
0 |
3024 |
| if (!field_svp || !SvROK(*field_svp) || !parent_svp) { |
3024 |
0 |
3024 |
| if (!field_svp || !SvROK(*field_svp) || !parent_svp) { |
0 |
3024 |
3024 |
|
| 1776 |
0 |
| continue; |
| 1777 |
|
| } |
| 1778 |
3024 |
| field_hv = (HV *)SvRV(*field_svp); |
| 1779 |
3024 |
| name_svp = hv_fetch(field_hv, "name", 4, 0); |
| 1780 |
3024 |
| selections_svp = hv_fetch(field_hv, "selections", 10, 0); |
| 1781 |
3024 |
▶ | if (!name_svp || !selections_svp || !SvROK(*selections_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!name_svp || !selections_svp || !SvROK(*selections_svp) |
3024 |
0 |
3024 |
| if (!name_svp || !selections_svp || !SvROK(*selections_svp) |
1006 |
2018 |
3024 |
| if (!name_svp || !selections_svp || !SvROK(*selections_svp) |
1006 |
0 |
1006 |
|
| 1782 |
1006 |
▶ | || SvTYPE(SvRV(*selections_svp)) != SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(*selections_svp)) != SVt_PVAV) { |
0 |
1006 |
1006 |
|
| 1783 |
2018 |
| continue; |
| 1784 |
|
| } |
| 1785 |
1006 |
| field_type_sv = gql_validation_field_type_sv( |
| 1786 |
|
| aTHX_ compiled_sv, *parent_svp, *name_svp |
| 1787 |
|
| ); |
| 1788 |
1006 |
| named_type_sv = gql_validation_named_type_name_sv(field_type_sv); |
| 1789 |
1006 |
▶ | if (!named_type_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!named_type_sv) { |
0 |
1006 |
1006 |
|
| 1790 |
0 |
| continue; |
| 1791 |
|
| } |
| 1792 |
1006 |
▶ | if (!first_named_type_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!first_named_type_sv) { |
4 |
1002 |
1006 |
|
| 1793 |
4 |
| first_named_type_sv = named_type_sv; |
| 1794 |
|
| } |
| 1795 |
1006 |
| inline_hv = newHV(); |
| 1796 |
1006 |
| gql_store_sv(inline_hv, "kind", newSVpv("inline_fragment", 0)); |
| 1797 |
1006 |
| gql_store_sv(inline_hv, "on", newSVsv(named_type_sv)); |
| 1798 |
1006 |
| gql_store_sv(inline_hv, "selections", newSVsv(*selections_svp)); |
| 1799 |
1006 |
| av_push(combined_av, newRV_noinc((SV *)inline_hv)); |
| 1800 |
|
| } |
| 1801 |
15 |
▶ | if (av_len(combined_av) >= 1 && first_named_type_sv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (av_len(combined_av) >= 1 && first_named_type_sv) { |
4 |
11 |
15 |
| if (av_len(combined_av) >= 1 && first_named_type_sv) { |
4 |
0 |
4 |
|
| 1802 |
4 |
| gql_validation_validate_field_merging( |
| 1803 |
|
| aTHX_ errors_av, compiled_sv, combined_av, |
| 1804 |
|
| first_named_type_sv, fragments_hv |
| 1805 |
|
| ); |
| 1806 |
|
| } |
| 1807 |
15 |
| SvREFCNT_dec((SV *)combined_av); |
| 1808 |
|
| } |
| 1809 |
|
| } |
| 1810 |
2017 |
| SvREFCNT_dec((SV *)fields_av); |
| 1811 |
2017 |
| SvREFCNT_dec((SV *)visited_fragments_hv); |
| 1812 |
2017 |
| SvREFCNT_dec((SV *)fields_by_key_hv); |
| 1813 |
2017 |
| } |
| 1814 |
|
| |
| 1815 |
|
| static void gql_validation_validate_selections( |
| 1816 |
|
| pTHX_ AV *errors_av, |
| 1817 |
|
| SV *schema, |
| 1818 |
|
| SV *compiled_sv, |
| 1819 |
|
| AV *selections_av, |
| 1820 |
|
| SV *parent_type_name_sv, |
| 1821 |
|
| HV *variables_hv, |
| 1822 |
|
| HV *fragments_hv, |
| 1823 |
|
| HV *visited_fragments_hv |
| 1824 |
|
| ); |
| 1825 |
|
| |
| 1826 |
|
| static void |
| 1827 |
4587 |
| gql_validation_validate_field_selection( |
| 1828 |
|
| pTHX_ AV *errors_av, |
| 1829 |
|
| SV *schema, |
| 1830 |
|
| SV *compiled_sv, |
| 1831 |
|
| HV *selection_hv, |
| 1832 |
|
| HV *parent_type_hv, |
| 1833 |
|
| HV *variables_hv, |
| 1834 |
|
| HV *fragments_hv, |
| 1835 |
|
| HV *visited_fragments_hv |
| 1836 |
|
| ) { |
| 1837 |
4587 |
| SV **field_name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 1838 |
4587 |
| SV **location_svp = hv_fetch(selection_hv, "location", 8, 0); |
| 1839 |
4587 |
| SV **parent_name_svp = hv_fetch(parent_type_hv, "name", 4, 0); |
| 1840 |
4587 |
| SV **fields_svp = hv_fetch(parent_type_hv, "fields", 6, 0); |
| 1841 |
4587 |
| HE *field_he = NULL; |
| 1842 |
|
| |
| 1843 |
4587 |
▶ | if (!field_name_svp || !SvOK(*field_name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!field_name_svp || !SvOK(*field_name_svp)) { |
4587 |
0 |
4587 |
| if (!field_name_svp || !SvOK(*field_name_svp)) { |
0 |
4587 |
4587 |
|
| 1844 |
0 |
| return; |
| 1845 |
|
| } |
| 1846 |
|
| |
| 1847 |
4587 |
▶ | if (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) { |
4583 |
4 |
4587 |
| if (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) { |
4583 |
0 |
4583 |
| if (fields_svp && SvROK(*fields_svp) && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV) { |
4583 |
0 |
4583 |
|
| 1848 |
4583 |
| field_he = hv_fetch_ent((HV *)SvRV(*fields_svp), *field_name_svp, 0, 0); |
| 1849 |
|
| } |
| 1850 |
|
| |
| 1851 |
4587 |
▶ | if (!field_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!field_he) { |
52 |
4535 |
4587 |
|
| 1852 |
52 |
| const char *field_name = SvPV_nolen(*field_name_svp); |
| 1853 |
52 |
| int is_meta = strEQ(field_name, "__typename"); |
| 1854 |
52 |
▶ | if (!is_meta && (strEQ(field_name, "__schema") || strEQ(field_name, "__type"))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!is_meta && (strEQ(field_name, "__schema") || strEQ(field_name, "__type"))) { |
40 |
12 |
52 |
| if (!is_meta && (strEQ(field_name, "__schema") || strEQ(field_name, "__type"))) { |
27 |
13 |
40 |
| if (!is_meta && (strEQ(field_name, "__schema") || strEQ(field_name, "__type"))) { |
18 |
9 |
27 |
|
| 1855 |
|
| /* __schema / __type exist on the query root only. Their subtrees |
| 1856 |
|
| * select over the introspection meta types, which are not part of |
| 1857 |
|
| * the compiled type index, so validation stops here (like the |
| 1858 |
|
| * __typename leaf) and the introspection executor takes over. */ |
| 1859 |
31 |
| HV *compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 1860 |
31 |
▶ | SV **roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
31 |
0 |
31 |
|
| 1861 |
31 |
▶ | if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
31 |
0 |
31 |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
31 |
0 |
31 |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
31 |
0 |
31 |
|
| 1862 |
31 |
| SV **query_root_svp = hv_fetch((HV *)SvRV(*roots_svp), "query", 5, 0); |
| 1863 |
62 |
▶ | is_meta = query_root_svp && SvOK(*query_root_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| is_meta = query_root_svp && SvOK(*query_root_svp) |
31 |
0 |
31 |
|
| 1864 |
31 |
▶ | && parent_name_svp && SvOK(*parent_name_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| && parent_name_svp && SvOK(*parent_name_svp) |
31 |
0 |
31 |
| && parent_name_svp && SvOK(*parent_name_svp) |
31 |
0 |
31 |
|
| 1865 |
124 |
▶ | && strEQ(SvPV_nolen(*query_root_svp), SvPV_nolen(*parent_name_svp)); |
Branch: 3 branches
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*query_root_svp), SvPV_nolen(*parent_name_svp)); |
31 |
0 |
31 |
| && strEQ(SvPV_nolen(*query_root_svp), SvPV_nolen(*parent_name_svp)); |
31 |
0 |
31 |
| && strEQ(SvPV_nolen(*query_root_svp), SvPV_nolen(*parent_name_svp)); |
30 |
1 |
31 |
|
| 1866 |
|
| } |
| 1867 |
|
| } |
| 1868 |
52 |
▶ | if (!is_meta) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_meta) { |
10 |
42 |
52 |
|
| 1869 |
20 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
10 |
0 |
10 |
| SV *message = newSVpvf( |
10 |
0 |
10 |
|
| 1870 |
|
| "Field '%s' does not exist on type '%s'.", |
| 1871 |
|
| field_name, |
| 1872 |
|
| (parent_name_svp && SvOK(*parent_name_svp)) ? SvPV_nolen(*parent_name_svp) : "" |
| 1873 |
|
| ); |
| 1874 |
20 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
10 |
0 |
10 |
|
| 1875 |
10 |
| SvREFCNT_dec(message); |
| 1876 |
|
| } |
| 1877 |
52 |
| return; |
| 1878 |
|
| } |
| 1879 |
|
| |
| 1880 |
4535 |
▶ | if (SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
4535 |
0 |
4535 |
| if (SvROK(HeVAL(field_he)) && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
4535 |
0 |
4535 |
|
| 1881 |
4535 |
| HV *field_hv = (HV *)SvRV(HeVAL(field_he)); |
| 1882 |
4535 |
| SV **arguments_svp = hv_fetch(selection_hv, "arguments", 9, 0); |
| 1883 |
4535 |
| SV **arg_defs_svp = hv_fetch(field_hv, "args", 4, 0); |
| 1884 |
4535 |
▶ | HV *arguments_hv = (arguments_svp && SvROK(*arguments_svp) && SvTYPE(SvRV(*arguments_svp)) == SVt_PVHV) ? (HV *)SvRV(*arguments_svp) : newHV(); |
Branch: 3 branches
| Branch | True | False | Total |
| HV *arguments_hv = (arguments_svp && SvROK(*arguments_svp) && SvTYPE(SvRV(*arguments_svp)) == SVt_PVHV) ? (HV *)SvRV(*arguments_svp) : newHV(); |
302 |
4233 |
4535 |
| HV *arguments_hv = (arguments_svp && SvROK(*arguments_svp) && SvTYPE(SvRV(*arguments_svp)) == SVt_PVHV) ? (HV *)SvRV(*arguments_svp) : newHV(); |
302 |
0 |
302 |
| HV *arguments_hv = (arguments_svp && SvROK(*arguments_svp) && SvTYPE(SvRV(*arguments_svp)) == SVt_PVHV) ? (HV *)SvRV(*arguments_svp) : newHV(); |
302 |
0 |
302 |
|
| 1885 |
4535 |
▶ | HV *arg_defs_hv = (arg_defs_svp && SvROK(*arg_defs_svp) && SvTYPE(SvRV(*arg_defs_svp)) == SVt_PVHV) ? (HV *)SvRV(*arg_defs_svp) : newHV(); |
Branch: 3 branches
| Branch | True | False | Total |
| HV *arg_defs_hv = (arg_defs_svp && SvROK(*arg_defs_svp) && SvTYPE(SvRV(*arg_defs_svp)) == SVt_PVHV) ? (HV *)SvRV(*arg_defs_svp) : newHV(); |
4535 |
0 |
4535 |
| HV *arg_defs_hv = (arg_defs_svp && SvROK(*arg_defs_svp) && SvTYPE(SvRV(*arg_defs_svp)) == SVt_PVHV) ? (HV *)SvRV(*arg_defs_svp) : newHV(); |
4535 |
0 |
4535 |
| HV *arg_defs_hv = (arg_defs_svp && SvROK(*arg_defs_svp) && SvTYPE(SvRV(*arg_defs_svp)) == SVt_PVHV) ? (HV *)SvRV(*arg_defs_svp) : newHV(); |
4535 |
0 |
4535 |
|
| 1886 |
4535 |
| SV **selections_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 1887 |
4535 |
| SV **type_svp = hv_fetch(field_hv, "type", 4, 0); |
| 1888 |
|
| |
| 1889 |
4535 |
▶ | gql_validation_validate_arguments(aTHX_ errors_av, schema, compiled_sv, arguments_hv, arg_defs_hv, variables_hv, location_svp ? *location_svp : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_arguments(aTHX_ errors_av, schema, compiled_sv, arguments_hv, arg_defs_hv, variables_hv, location_svp ? *location_svp : NULL); |
4535 |
0 |
4535 |
|
| 1890 |
4535 |
▶ | if ((!arguments_svp || arguments_hv != (HV *)SvRV(*arguments_svp))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!arguments_svp || arguments_hv != (HV *)SvRV(*arguments_svp))) { |
302 |
4233 |
4535 |
| if ((!arguments_svp || arguments_hv != (HV *)SvRV(*arguments_svp))) { |
0 |
302 |
302 |
|
| 1891 |
4233 |
| SvREFCNT_dec((SV *)arguments_hv); |
| 1892 |
|
| } |
| 1893 |
4535 |
▶ | if ((!arg_defs_svp || arg_defs_hv != (HV *)SvRV(*arg_defs_svp))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!arg_defs_svp || arg_defs_hv != (HV *)SvRV(*arg_defs_svp))) { |
4535 |
0 |
4535 |
| if ((!arg_defs_svp || arg_defs_hv != (HV *)SvRV(*arg_defs_svp))) { |
0 |
4535 |
4535 |
|
| 1894 |
0 |
| SvREFCNT_dec((SV *)arg_defs_hv); |
| 1895 |
|
| } |
| 1896 |
|
| |
| 1897 |
4535 |
▶ | if (type_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type_svp) { |
4535 |
0 |
4535 |
|
| 1898 |
4535 |
| SV *next_type_name_sv = gql_validation_named_type_name_sv(*type_svp); |
| 1899 |
4535 |
| HV *next_type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, next_type_name_sv); |
| 1900 |
4535 |
▶ | SV **next_kind_svp = next_type_hv ? hv_fetch(next_type_hv, "kind", 4, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **next_kind_svp = next_type_hv ? hv_fetch(next_type_hv, "kind", 4, 0) : NULL; |
4535 |
0 |
4535 |
|
| 1901 |
1449 |
▶ | int has_selections = selections_svp && SvROK(*selections_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| int has_selections = selections_svp && SvROK(*selections_svp) |
1449 |
0 |
1449 |
|
| 1902 |
5984 |
▶ | && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV; |
Branch: 2 branches
| Branch | True | False | Total |
| && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV; |
1449 |
3086 |
4535 |
| && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV; |
1449 |
0 |
1449 |
|
| 1903 |
4535 |
▶ | int is_leaf = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| int is_leaf = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
4535 |
0 |
4535 |
| int is_leaf = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
4535 |
0 |
4535 |
|
| 1904 |
15085 |
▶ | && (strEQ(SvPV_nolen(*next_kind_svp), "SCALAR") |
Branch: 2 branches
| Branch | True | False | Total |
| && (strEQ(SvPV_nolen(*next_kind_svp), "SCALAR") |
4535 |
0 |
4535 |
| && (strEQ(SvPV_nolen(*next_kind_svp), "SCALAR") |
1480 |
3055 |
4535 |
|
| 1905 |
2960 |
▶ | || strEQ(SvPV_nolen(*next_kind_svp), "ENUM")); |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(SvPV_nolen(*next_kind_svp), "ENUM")); |
30 |
1450 |
1480 |
|
| 1906 |
4535 |
▶ | int is_composite = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| int is_composite = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
4535 |
0 |
4535 |
| int is_composite = next_kind_svp && SvOK(*next_kind_svp) && SvPOK(*next_kind_svp) |
4535 |
0 |
4535 |
|
| 1907 |
16769 |
▶ | && (strEQ(SvPV_nolen(*next_kind_svp), "OBJECT") |
Branch: 2 branches
| Branch | True | False | Total |
| && (strEQ(SvPV_nolen(*next_kind_svp), "OBJECT") |
4535 |
0 |
4535 |
| && (strEQ(SvPV_nolen(*next_kind_svp), "OBJECT") |
3164 |
1371 |
4535 |
|
| 1908 |
6328 |
▶ | || strEQ(SvPV_nolen(*next_kind_svp), "INTERFACE") |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(SvPV_nolen(*next_kind_svp), "INTERFACE") |
3098 |
66 |
3164 |
|
| 1909 |
6196 |
▶ | || strEQ(SvPV_nolen(*next_kind_svp), "UNION")); |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(SvPV_nolen(*next_kind_svp), "UNION")); |
13 |
3085 |
3098 |
|
| 1910 |
|
| |
| 1911 |
4536 |
▶ | if (is_leaf && has_selections) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_leaf && has_selections) { |
3085 |
1450 |
4535 |
| if (is_leaf && has_selections) { |
1 |
3084 |
3085 |
|
| 1912 |
3 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 1913 |
|
| "Field '%s' must not have a selection since type '%s' has no subfields.", |
| 1914 |
|
| SvPV_nolen(*field_name_svp), |
| 1915 |
|
| next_type_name_sv ? SvPV_nolen(next_type_name_sv) : "" |
| 1916 |
|
| ); |
| 1917 |
2 |
▶ | av_push(errors_av, gql_validation_error( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error( |
1 |
0 |
1 |
|
| 1918 |
|
| aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL |
| 1919 |
|
| )); |
| 1920 |
1 |
| SvREFCNT_dec(message); |
| 1921 |
4534 |
▶ | } else if (is_composite && !has_selections) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (is_composite && !has_selections) { |
1450 |
3084 |
4534 |
| } else if (is_composite && !has_selections) { |
2 |
1448 |
1450 |
|
| 1922 |
6 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
2 |
0 |
2 |
|
| 1923 |
|
| "Field '%s' of type '%s' must have a selection of subfields.", |
| 1924 |
|
| SvPV_nolen(*field_name_svp), |
| 1925 |
|
| next_type_name_sv ? SvPV_nolen(next_type_name_sv) : "" |
| 1926 |
|
| ); |
| 1927 |
4 |
▶ | av_push(errors_av, gql_validation_error( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error( |
2 |
0 |
2 |
|
| 1928 |
|
| aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL |
| 1929 |
|
| )); |
| 1930 |
2 |
| SvREFCNT_dec(message); |
| 1931 |
|
| } |
| 1932 |
|
| |
| 1933 |
4535 |
▶ | if (has_selections && next_type_name_sv && !is_leaf) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (has_selections && next_type_name_sv && !is_leaf) { |
1449 |
3086 |
4535 |
| if (has_selections && next_type_name_sv && !is_leaf) { |
1449 |
0 |
1449 |
| if (has_selections && next_type_name_sv && !is_leaf) { |
1448 |
1 |
1449 |
|
| 1934 |
1448 |
| gql_validation_validate_selections( |
| 1935 |
|
| aTHX_ errors_av, |
| 1936 |
|
| schema, |
| 1937 |
|
| compiled_sv, |
| 1938 |
1448 |
| (AV *)SvRV(*selections_svp), |
| 1939 |
|
| next_type_name_sv, |
| 1940 |
|
| variables_hv, |
| 1941 |
|
| fragments_hv, |
| 1942 |
|
| visited_fragments_hv |
| 1943 |
|
| ); |
| 1944 |
|
| } |
| 1945 |
|
| } |
| 1946 |
|
| } |
| 1947 |
|
| } |
| 1948 |
|
| |
| 1949 |
|
| static void |
| 1950 |
2014 |
| gql_validation_validate_selections( |
| 1951 |
|
| pTHX_ AV *errors_av, |
| 1952 |
|
| SV *schema, |
| 1953 |
|
| SV *compiled_sv, |
| 1954 |
|
| AV *selections_av, |
| 1955 |
|
| SV *parent_type_name_sv, |
| 1956 |
|
| HV *variables_hv, |
| 1957 |
|
| HV *fragments_hv, |
| 1958 |
|
| HV *visited_fragments_hv |
| 1959 |
|
| ) { |
| 1960 |
2014 |
| HV *parent_type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, parent_type_name_sv); |
| 1961 |
|
| I32 i; |
| 1962 |
|
| |
| 1963 |
2014 |
▶ | if (!parent_type_hv || !selections_av) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!parent_type_hv || !selections_av) { |
2013 |
1 |
2014 |
| if (!parent_type_hv || !selections_av) { |
0 |
2013 |
2013 |
|
| 1964 |
1 |
| return; |
| 1965 |
|
| } |
| 1966 |
|
| |
| 1967 |
2013 |
| gql_validation_validate_field_merging( |
| 1968 |
|
| aTHX_ errors_av, compiled_sv, selections_av, |
| 1969 |
|
| parent_type_name_sv, fragments_hv |
| 1970 |
|
| ); |
| 1971 |
|
| |
| 1972 |
6666 |
▶ | for (i = 0; i <= av_len(selections_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(selections_av); i++) { |
4653 |
2013 |
6666 |
|
| 1973 |
4653 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 1974 |
|
| HV *selection_hv; |
| 1975 |
|
| SV **kind_svp; |
| 1976 |
4653 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
4653 |
0 |
4653 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
4653 |
0 |
4653 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
0 |
4653 |
4653 |
|
| 1977 |
0 |
| continue; |
| 1978 |
|
| } |
| 1979 |
4653 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 1980 |
4653 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 1981 |
4653 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
4653 |
0 |
4653 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
4653 |
0 |
4653 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
4653 |
4653 |
|
| 1982 |
0 |
| continue; |
| 1983 |
|
| } |
| 1984 |
9306 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
4587 |
66 |
4653 |
|
| 1985 |
4587 |
| gql_validation_validate_field_selection(aTHX_ errors_av, schema, compiled_sv, selection_hv, parent_type_hv, variables_hv, fragments_hv, visited_fragments_hv); |
| 1986 |
4587 |
| continue; |
| 1987 |
|
| } |
| 1988 |
132 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
34 |
32 |
66 |
|
| 1989 |
34 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 1990 |
34 |
| SV **location_svp = hv_fetch(selection_hv, "location", 8, 0); |
| 1991 |
34 |
▶ | HE *fragment_he = name_svp ? hv_fetch_ent(fragments_hv, *name_svp, 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| HE *fragment_he = name_svp ? hv_fetch_ent(fragments_hv, *name_svp, 0, 0) : NULL; |
34 |
0 |
34 |
|
| 1992 |
34 |
▶ | if (!fragment_he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fragment_he) { |
0 |
34 |
34 |
|
| 1993 |
0 |
▶ | if (name_svp && SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name_svp && SvOK(*name_svp)) { |
0 |
0 |
0 |
| if (name_svp && SvOK(*name_svp)) { |
0 |
0 |
0 |
|
| 1994 |
0 |
| SV *message = newSVpvf("Unknown fragment '%s'.", SvPV_nolen(*name_svp)); |
| 1995 |
0 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
0 |
0 |
|
| 1996 |
0 |
| SvREFCNT_dec(message); |
| 1997 |
|
| } |
| 1998 |
0 |
| continue; |
| 1999 |
|
| } |
| 2000 |
34 |
▶ | if (SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
34 |
0 |
34 |
| if (SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
34 |
0 |
34 |
|
| 2001 |
34 |
| HV *fragment_hv = (HV *)SvRV(HeVAL(fragment_he)); |
| 2002 |
34 |
| SV **on_svp = hv_fetch(fragment_hv, "on", 2, 0); |
| 2003 |
34 |
▶ | if (on_svp && SvOK(*on_svp) && gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (on_svp && SvOK(*on_svp) && gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) |
34 |
0 |
34 |
| if (on_svp && SvOK(*on_svp) && gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) |
34 |
0 |
34 |
| if (on_svp && SvOK(*on_svp) && gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) |
33 |
1 |
34 |
|
| 2004 |
33 |
▶ | && !gql_validation_selection_types_overlap(aTHX_ compiled_sv, parent_type_name_sv, *on_svp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !gql_validation_selection_types_overlap(aTHX_ compiled_sv, parent_type_name_sv, *on_svp)) { |
1 |
32 |
33 |
|
| 2005 |
3 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 2006 |
|
| "Fragment '%s' cannot be spread here because type '%s' can never apply to '%s'.", |
| 2007 |
|
| name_svp ? SvPV_nolen(*name_svp) : "", |
| 2008 |
|
| SvPV_nolen(*on_svp), |
| 2009 |
|
| SvPV_nolen(parent_type_name_sv) |
| 2010 |
|
| ); |
| 2011 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
1 |
0 |
1 |
|
| 2012 |
1 |
| SvREFCNT_dec(message); |
| 2013 |
|
| } |
| 2014 |
34 |
▶ | if (visited_fragments_hv && name_svp && SvOK(*name_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (visited_fragments_hv && name_svp && SvOK(*name_svp)) { |
20 |
14 |
34 |
| if (visited_fragments_hv && name_svp && SvOK(*name_svp)) { |
20 |
0 |
20 |
| if (visited_fragments_hv && name_svp && SvOK(*name_svp)) { |
20 |
0 |
20 |
|
| 2015 |
|
| STRLEN name_len; |
| 2016 |
20 |
| const char *name = SvPV(*name_svp, name_len); |
| 2017 |
20 |
▶ | if (!hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
19 |
1 |
20 |
|
| 2018 |
19 |
| SV **fragment_selections_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 2019 |
19 |
| (void)hv_store(visited_fragments_hv, name, (I32)name_len, newSViv(1), 0); |
| 2020 |
19 |
▶ | if (on_svp && SvOK(*on_svp) && fragment_selections_svp |
Branch: 3 branches
| Branch | True | False | Total |
| if (on_svp && SvOK(*on_svp) && fragment_selections_svp |
19 |
0 |
19 |
| if (on_svp && SvOK(*on_svp) && fragment_selections_svp |
19 |
0 |
19 |
| if (on_svp && SvOK(*on_svp) && fragment_selections_svp |
19 |
0 |
19 |
|
| 2021 |
19 |
▶ | && SvROK(*fragment_selections_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvROK(*fragment_selections_svp) |
19 |
0 |
19 |
|
| 2022 |
19 |
▶ | && SvTYPE(SvRV(*fragment_selections_svp)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*fragment_selections_svp)) == SVt_PVAV) { |
19 |
0 |
19 |
|
| 2023 |
19 |
| AV *fragment_errors_av = newAV(); |
| 2024 |
|
| I32 error_i; |
| 2025 |
19 |
| gql_validation_validate_selections( |
| 2026 |
|
| aTHX_ fragment_errors_av, schema, compiled_sv, |
| 2027 |
19 |
| (AV *)SvRV(*fragment_selections_svp), *on_svp, |
| 2028 |
|
| variables_hv, fragments_hv, visited_fragments_hv |
| 2029 |
|
| ); |
| 2030 |
23 |
▶ | for (error_i = 0; error_i <= av_len(fragment_errors_av); error_i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (error_i = 0; error_i <= av_len(fragment_errors_av); error_i++) { |
4 |
19 |
23 |
|
| 2031 |
4 |
| SV **error_svp = av_fetch(fragment_errors_av, error_i, 0); |
| 2032 |
|
| SV **message_svp; |
| 2033 |
4 |
▶ | if (!error_svp || !SvROK(*error_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!error_svp || !SvROK(*error_svp) |
4 |
0 |
4 |
| if (!error_svp || !SvROK(*error_svp) |
4 |
0 |
4 |
|
| 2034 |
4 |
▶ | || SvTYPE(SvRV(*error_svp)) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(*error_svp)) != SVt_PVHV) { |
0 |
4 |
4 |
|
| 2035 |
0 |
| continue; |
| 2036 |
|
| } |
| 2037 |
4 |
| message_svp = hv_fetch((HV *)SvRV(*error_svp), "message", 7, 0); |
| 2038 |
4 |
▶ | if (message_svp && SvOK(*message_svp) && SvCUR(*message_svp) >= 11 |
Branch: 3 branches
| Branch | True | False | Total |
| if (message_svp && SvOK(*message_svp) && SvCUR(*message_svp) >= 11 |
4 |
0 |
4 |
| if (message_svp && SvOK(*message_svp) && SvCUR(*message_svp) >= 11 |
4 |
0 |
4 |
| if (message_svp && SvOK(*message_svp) && SvCUR(*message_svp) >= 11 |
4 |
0 |
4 |
|
| 2039 |
8 |
▶ | && strnEQ(SvPV_nolen(*message_svp), "Variable '$", 11)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && strnEQ(SvPV_nolen(*message_svp), "Variable '$", 11)) { |
3 |
1 |
4 |
|
| 2040 |
3 |
| av_push(errors_av, newSVsv(*error_svp)); |
| 2041 |
|
| } |
| 2042 |
|
| } |
| 2043 |
19 |
| SvREFCNT_dec((SV *)fragment_errors_av); |
| 2044 |
|
| } |
| 2045 |
|
| } |
| 2046 |
|
| } |
| 2047 |
|
| } |
| 2048 |
34 |
| continue; |
| 2049 |
|
| } |
| 2050 |
64 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
32 |
0 |
32 |
|
| 2051 |
32 |
| SV **on_svp = hv_fetch(selection_hv, "on", 2, 0); |
| 2052 |
32 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 2053 |
32 |
| SV **location_svp = hv_fetch(selection_hv, "location", 8, 0); |
| 2054 |
32 |
▶ | SV *target_type_name_sv = (on_svp && SvOK(*on_svp)) ? *on_svp : parent_type_name_sv; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *target_type_name_sv = (on_svp && SvOK(*on_svp)) ? *on_svp : parent_type_name_sv; |
32 |
0 |
32 |
| SV *target_type_name_sv = (on_svp && SvOK(*on_svp)) ? *on_svp : parent_type_name_sv; |
32 |
0 |
32 |
|
| 2055 |
32 |
▶ | if (!gql_validation_compiled_type_hv(aTHX_ compiled_sv, target_type_name_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gql_validation_compiled_type_hv(aTHX_ compiled_sv, target_type_name_sv)) { |
0 |
32 |
32 |
|
| 2056 |
0 |
| SV *message = newSVpvf("Inline fragment references unknown type '%s'.", SvPV_nolen(target_type_name_sv)); |
| 2057 |
0 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
0 |
0 |
|
| 2058 |
0 |
| SvREFCNT_dec(message); |
| 2059 |
0 |
| continue; |
| 2060 |
|
| } |
| 2061 |
32 |
▶ | if (!gql_validation_selection_types_overlap(aTHX_ compiled_sv, parent_type_name_sv, target_type_name_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gql_validation_selection_types_overlap(aTHX_ compiled_sv, parent_type_name_sv, target_type_name_sv)) { |
1 |
31 |
32 |
|
| 2062 |
2 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 2063 |
|
| "Inline fragment on '%s' cannot be used where type '%s' is expected.", |
| 2064 |
|
| SvPV_nolen(target_type_name_sv), |
| 2065 |
|
| SvPV_nolen(parent_type_name_sv) |
| 2066 |
|
| ); |
| 2067 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
1 |
0 |
1 |
|
| 2068 |
1 |
| SvREFCNT_dec(message); |
| 2069 |
1 |
| continue; |
| 2070 |
|
| } |
| 2071 |
31 |
▶ | if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
31 |
0 |
31 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
31 |
0 |
31 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
31 |
0 |
31 |
|
| 2072 |
31 |
| gql_validation_validate_selections(aTHX_ errors_av, schema, compiled_sv, (AV *)SvRV(*nested_svp), target_type_name_sv, variables_hv, fragments_hv, visited_fragments_hv); |
| 2073 |
|
| } |
| 2074 |
|
| } |
| 2075 |
|
| } |
| 2076 |
|
| } |
| 2077 |
|
| |
| 2078 |
|
| static void |
| 2079 |
127 |
| gql_validation_validate_variable_definitions( |
| 2080 |
|
| pTHX_ AV *errors_av, |
| 2081 |
|
| SV *schema, |
| 2082 |
|
| SV *compiled_sv, |
| 2083 |
|
| HV *variables_hv, |
| 2084 |
|
| SV *location_sv |
| 2085 |
|
| ) { |
| 2086 |
127 |
| I32 count = 0; |
| 2087 |
127 |
| SV **keys = gql_parser_sorted_hash_keys(aTHX_ variables_hv, &count); |
| 2088 |
|
| I32 i; |
| 2089 |
|
| |
| 2090 |
127 |
▶ | if (!keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!keys) { |
0 |
127 |
127 |
|
| 2091 |
0 |
| return; |
| 2092 |
|
| } |
| 2093 |
|
| |
| 2094 |
287 |
▶ | for (i = 0; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; i++) { |
160 |
127 |
287 |
|
| 2095 |
160 |
| HE *he = hv_fetch_ent(variables_hv, keys[i], 0, 0); |
| 2096 |
160 |
| SV *type_sv = NULL; |
| 2097 |
160 |
| int has_error = 0; |
| 2098 |
160 |
▶ | if (!he) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!he) { |
0 |
160 |
160 |
|
| 2099 |
0 |
| continue; |
| 2100 |
|
| } |
| 2101 |
160 |
| type_sv = gql_validation_lookup_type_sv(aTHX_ schema, HeVAL(he)); |
| 2102 |
160 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
160 |
0 |
160 |
| if (SvTRUE(ERRSV)) { |
0 |
160 |
160 |
|
| 2103 |
0 |
| has_error = 1; |
| 2104 |
0 |
▶ | sv_setsv(ERRSV, &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, &PL_sv_undef); |
0 |
0 |
0 |
|
| 2105 |
|
| } |
| 2106 |
160 |
▶ | if (has_error || !type_sv || !SvOK(type_sv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (has_error || !type_sv || !SvOK(type_sv)) { |
160 |
0 |
160 |
| if (has_error || !type_sv || !SvOK(type_sv)) { |
160 |
0 |
160 |
| if (has_error || !type_sv || !SvOK(type_sv)) { |
0 |
160 |
160 |
|
| 2107 |
0 |
| SV *message = newSVpvf("Variable '$%s' has an invalid type.", SvPV_nolen(keys[i])); |
| 2108 |
0 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 2109 |
0 |
| SvREFCNT_dec(message); |
| 2110 |
0 |
▶ | if (type_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type_sv) { |
0 |
0 |
0 |
|
| 2111 |
0 |
| SvREFCNT_dec(type_sv); |
| 2112 |
|
| } |
| 2113 |
0 |
| continue; |
| 2114 |
|
| } |
| 2115 |
|
| { |
| 2116 |
|
| /* Role::Tiny provides DOES as an installed method, which C-level |
| 2117 |
|
| * sv_does (UNIVERSAL isa semantics) never dispatches - it reported |
| 2118 |
|
| * every Houtou type as non-input. Call the DOES method instead. */ |
| 2119 |
160 |
| int is_input = gql_schema_does_role(aTHX_ type_sv, "GraphQL::Houtou::Role::Input") |
| 2120 |
160 |
▶ | || gql_schema_does_role(aTHX_ type_sv, "GraphQL::Role::Input"); |
Branch: 2 branches
| Branch | True | False | Total |
| || gql_schema_does_role(aTHX_ type_sv, "GraphQL::Role::Input"); |
1 |
159 |
160 |
| || gql_schema_does_role(aTHX_ type_sv, "GraphQL::Role::Input"); |
0 |
1 |
1 |
|
| 2121 |
160 |
▶ | if (!is_input) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_input) { |
1 |
159 |
160 |
|
| 2122 |
1 |
| dSP; |
| 2123 |
|
| int count_call; |
| 2124 |
|
| SV *type_string_sv; |
| 2125 |
1 |
| ENTER; |
| 2126 |
1 |
| SAVETMPS; |
| 2127 |
1 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
1 |
1 |
|
| 2128 |
1 |
▶ | XPUSHs(sv_2mortal(newSVsv(type_sv))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVsv(type_sv))); |
0 |
1 |
1 |
|
| 2129 |
1 |
| PUTBACK; |
| 2130 |
1 |
| count_call = call_method("to_string", G_SCALAR); |
| 2131 |
1 |
| SPAGAIN; |
| 2132 |
1 |
▶ | type_string_sv = count_call == 1 ? newSVsv(POPs) : newSVpv("", 0); |
Branch: 1 branch
| Branch | True | False | Total |
| type_string_sv = count_call == 1 ? newSVsv(POPs) : newSVpv("", 0); |
1 |
0 |
1 |
|
| 2133 |
1 |
| PUTBACK; |
| 2134 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 2135 |
1 |
| LEAVE; |
| 2136 |
|
| { |
| 2137 |
2 |
▶ | SV *message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 2138 |
|
| "Variable '$%s' is type '%s' which cannot be used as an input type.", |
| 2139 |
|
| SvPV_nolen(keys[i]), |
| 2140 |
|
| SvPV_nolen(type_string_sv) |
| 2141 |
|
| ); |
| 2142 |
1 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_sv)); |
| 2143 |
1 |
| SvREFCNT_dec(message); |
| 2144 |
|
| } |
| 2145 |
1 |
| SvREFCNT_dec(type_string_sv); |
| 2146 |
159 |
▶ | } else if (SvROK(HeVAL(he)) && SvTYPE(SvRV(HeVAL(he))) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (SvROK(HeVAL(he)) && SvTYPE(SvRV(HeVAL(he))) == SVt_PVHV) { |
159 |
0 |
159 |
| } else if (SvROK(HeVAL(he)) && SvTYPE(SvRV(HeVAL(he))) == SVt_PVHV) { |
159 |
0 |
159 |
|
| 2147 |
159 |
| HV *variable_hv = (HV *)SvRV(HeVAL(he)); |
| 2148 |
159 |
| SV **default_svp = hv_fetch(variable_hv, "default_value", 13, 0); |
| 2149 |
159 |
▶ | if (default_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (default_svp) { |
10 |
149 |
159 |
|
| 2150 |
10 |
| SV *compiled_type_sv = gql_schema_compile_type_ref(aTHX_ type_sv); |
| 2151 |
10 |
| gql_validation_validate_value( |
| 2152 |
|
| aTHX_ errors_av, schema, compiled_sv, *default_svp, |
| 2153 |
|
| compiled_type_sv, NULL, location_sv |
| 2154 |
|
| ); |
| 2155 |
10 |
| SvREFCNT_dec(compiled_type_sv); |
| 2156 |
|
| } |
| 2157 |
|
| } |
| 2158 |
|
| } |
| 2159 |
160 |
| SvREFCNT_dec(type_sv); |
| 2160 |
|
| } |
| 2161 |
|
| |
| 2162 |
127 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 2163 |
|
| } |
| 2164 |
|
| |
| 2165 |
|
| static void |
| 2166 |
487 |
| gql_validation_validate_fragments(pTHX_ AV *errors_av, SV *compiled_sv, HV *fragments_hv) { |
| 2167 |
487 |
| I32 count = 0; |
| 2168 |
487 |
| SV **keys = gql_parser_sorted_hash_keys(aTHX_ fragments_hv, &count); |
| 2169 |
|
| I32 i; |
| 2170 |
487 |
▶ | if (!keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!keys) { |
468 |
19 |
487 |
|
| 2171 |
468 |
| return; |
| 2172 |
|
| } |
| 2173 |
46 |
▶ | for (i = 0; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; i++) { |
27 |
19 |
46 |
|
| 2174 |
27 |
| HE *fragment_he = hv_fetch_ent(fragments_hv, keys[i], 0, 0); |
| 2175 |
|
| HV *fragment_hv; |
| 2176 |
|
| SV **on_svp; |
| 2177 |
|
| HV *type_hv; |
| 2178 |
|
| SV **kind_svp; |
| 2179 |
27 |
▶ | if (!fragment_he || !SvROK(HeVAL(fragment_he)) || SvTYPE(SvRV(HeVAL(fragment_he))) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!fragment_he || !SvROK(HeVAL(fragment_he)) || SvTYPE(SvRV(HeVAL(fragment_he))) != SVt_PVHV) { |
27 |
0 |
27 |
| if (!fragment_he || !SvROK(HeVAL(fragment_he)) || SvTYPE(SvRV(HeVAL(fragment_he))) != SVt_PVHV) { |
27 |
0 |
27 |
| if (!fragment_he || !SvROK(HeVAL(fragment_he)) || SvTYPE(SvRV(HeVAL(fragment_he))) != SVt_PVHV) { |
0 |
27 |
27 |
|
| 2180 |
0 |
| continue; |
| 2181 |
|
| } |
| 2182 |
27 |
| fragment_hv = (HV *)SvRV(HeVAL(fragment_he)); |
| 2183 |
27 |
| on_svp = hv_fetch(fragment_hv, "on", 2, 0); |
| 2184 |
27 |
▶ | type_hv = on_svp ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| type_hv = on_svp ? gql_validation_compiled_type_hv(aTHX_ compiled_sv, *on_svp) : NULL; |
27 |
0 |
27 |
|
| 2185 |
27 |
▶ | if (!type_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!type_hv) { |
1 |
26 |
27 |
|
| 2186 |
1 |
| SV **location_svp = hv_fetch(fragment_hv, "location", 8, 0); |
| 2187 |
3 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
1 |
0 |
1 |
| SV *message = newSVpvf( |
1 |
0 |
1 |
|
| 2188 |
|
| "Fragment '%s' references unknown type '%s'.", |
| 2189 |
|
| SvPV_nolen(keys[i]), |
| 2190 |
|
| (on_svp && SvOK(*on_svp)) ? SvPV_nolen(*on_svp) : "" |
| 2191 |
|
| ); |
| 2192 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
1 |
0 |
1 |
|
| 2193 |
1 |
| SvREFCNT_dec(message); |
| 2194 |
1 |
| continue; |
| 2195 |
|
| } |
| 2196 |
26 |
| kind_svp = hv_fetch(type_hv, "kind", 4, 0); |
| 2197 |
26 |
▶ | if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
26 |
0 |
26 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
26 |
0 |
26 |
| if (kind_svp && SvOK(*kind_svp) && SvPOK(*kind_svp) |
26 |
0 |
26 |
|
| 2198 |
52 |
▶ | && !strEQ(SvPV_nolen(*kind_svp), "OBJECT") |
Branch: 1 branch
| Branch | True | False | Total |
| && !strEQ(SvPV_nolen(*kind_svp), "OBJECT") |
0 |
26 |
26 |
|
| 2199 |
0 |
▶ | && !strEQ(SvPV_nolen(*kind_svp), "INTERFACE") |
Branch: 1 branch
| Branch | True | False | Total |
| && !strEQ(SvPV_nolen(*kind_svp), "INTERFACE") |
0 |
0 |
0 |
|
| 2200 |
0 |
▶ | && !strEQ(SvPV_nolen(*kind_svp), "UNION")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !strEQ(SvPV_nolen(*kind_svp), "UNION")) { |
0 |
0 |
0 |
|
| 2201 |
0 |
| SV **location_svp = hv_fetch(fragment_hv, "location", 8, 0); |
| 2202 |
0 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
0 |
0 |
0 |
| SV *message = newSVpvf( |
0 |
0 |
0 |
|
| 2203 |
|
| "Fragment '%s' cannot target non-composite type '%s'.", |
| 2204 |
|
| SvPV_nolen(keys[i]), |
| 2205 |
|
| (on_svp && SvOK(*on_svp)) ? SvPV_nolen(*on_svp) : "" |
| 2206 |
|
| ); |
| 2207 |
0 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
0 |
0 |
|
| 2208 |
0 |
| SvREFCNT_dec(message); |
| 2209 |
0 |
| continue; |
| 2210 |
|
| } |
| 2211 |
|
| { |
| 2212 |
26 |
| SV **selections_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 2213 |
26 |
▶ | if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
26 |
0 |
26 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
26 |
0 |
26 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
26 |
0 |
26 |
|
| 2214 |
26 |
| HV *deferred_variables_hv = newHV(); |
| 2215 |
26 |
| (void)hv_store( |
| 2216 |
|
| deferred_variables_hv, "__defer_fragment_variables", 26, newSViv(1), 0 |
| 2217 |
|
| ); |
| 2218 |
26 |
| gql_validation_validate_selections( |
| 2219 |
|
| aTHX_ errors_av, NULL, compiled_sv, |
| 2220 |
26 |
| (AV *)SvRV(*selections_svp), *on_svp, |
| 2221 |
|
| deferred_variables_hv, fragments_hv, NULL |
| 2222 |
|
| ); |
| 2223 |
26 |
| SvREFCNT_dec((SV *)deferred_variables_hv); |
| 2224 |
|
| } |
| 2225 |
|
| } |
| 2226 |
|
| } |
| 2227 |
19 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 2228 |
|
| } |
| 2229 |
|
| |
| 2230 |
|
| static void |
| 2231 |
490 |
| gql_validation_validate_operation( |
| 2232 |
|
| pTHX_ AV *errors_av, |
| 2233 |
|
| SV *schema, |
| 2234 |
|
| SV *compiled_sv, |
| 2235 |
|
| HV *operation_hv, |
| 2236 |
|
| HV *fragments_hv |
| 2237 |
|
| ) { |
| 2238 |
490 |
| HV *compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 2239 |
490 |
| SV **operation_type_svp = hv_fetch(operation_hv, "operationType", 13, 0); |
| 2240 |
654 |
▶ | const char *operation_type = (operation_type_svp && SvOK(*operation_type_svp)) ? SvPV_nolen(*operation_type_svp) : "query"; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *operation_type = (operation_type_svp && SvOK(*operation_type_svp)) ? SvPV_nolen(*operation_type_svp) : "query"; |
164 |
326 |
490 |
| const char *operation_type = (operation_type_svp && SvOK(*operation_type_svp)) ? SvPV_nolen(*operation_type_svp) : "query"; |
164 |
0 |
164 |
|
| 2241 |
490 |
▶ | SV **roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
490 |
0 |
490 |
|
| 2242 |
490 |
| SV *root_type_name_sv = NULL; |
| 2243 |
490 |
| HV *variables_hv = NULL; |
| 2244 |
|
| |
| 2245 |
490 |
▶ | if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
| if (roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
|
| 2246 |
490 |
| SV **root_type_svp = hv_fetch((HV *)SvRV(*roots_svp), operation_type, (I32)strlen(operation_type), 0); |
| 2247 |
490 |
▶ | if (root_type_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (root_type_svp) { |
490 |
0 |
490 |
|
| 2248 |
490 |
| root_type_name_sv = *root_type_svp; |
| 2249 |
|
| } |
| 2250 |
|
| } |
| 2251 |
|
| |
| 2252 |
490 |
▶ | if (!root_type_name_sv || !SvOK(root_type_name_sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!root_type_name_sv || !SvOK(root_type_name_sv)) { |
490 |
0 |
490 |
| if (!root_type_name_sv || !SvOK(root_type_name_sv)) { |
0 |
490 |
490 |
|
| 2253 |
0 |
| SV **location_svp = hv_fetch(operation_hv, "location", 8, 0); |
| 2254 |
0 |
| SV *message = newSVpvf("Schema does not define a root type for '%s'.", operation_type); |
| 2255 |
0 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
0 |
0 |
|
| 2256 |
0 |
| SvREFCNT_dec(message); |
| 2257 |
0 |
| return; |
| 2258 |
|
| } |
| 2259 |
|
| |
| 2260 |
|
| { |
| 2261 |
490 |
| SV **variables_svp = hv_fetch(operation_hv, "variables", 9, 0); |
| 2262 |
490 |
▶ | if (variables_svp && SvROK(*variables_svp) && SvTYPE(SvRV(*variables_svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (variables_svp && SvROK(*variables_svp) && SvTYPE(SvRV(*variables_svp)) == SVt_PVHV) { |
127 |
363 |
490 |
| if (variables_svp && SvROK(*variables_svp) && SvTYPE(SvRV(*variables_svp)) == SVt_PVHV) { |
127 |
0 |
127 |
| if (variables_svp && SvROK(*variables_svp) && SvTYPE(SvRV(*variables_svp)) == SVt_PVHV) { |
127 |
0 |
127 |
|
| 2263 |
127 |
| variables_hv = (HV *)SvRV(*variables_svp); |
| 2264 |
254 |
▶ | gql_validation_validate_variable_definitions( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_variable_definitions( |
127 |
0 |
127 |
|
| 2265 |
|
| aTHX_ errors_av, |
| 2266 |
|
| schema, |
| 2267 |
|
| compiled_sv, |
| 2268 |
|
| variables_hv, |
| 2269 |
254 |
| (hv_fetch(operation_hv, "location", 8, 0) ? *hv_fetch(operation_hv, "location", 8, 0) : NULL) |
| 2270 |
|
| ); |
| 2271 |
|
| } |
| 2272 |
|
| } |
| 2273 |
|
| |
| 2274 |
|
| { |
| 2275 |
490 |
| SV **selections_svp = hv_fetch(operation_hv, "selections", 10, 0); |
| 2276 |
490 |
▶ | if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
|
| 2277 |
490 |
| HV *visited_fragments_hv = newHV(); |
| 2278 |
490 |
| gql_validation_validate_selections( |
| 2279 |
|
| aTHX_ errors_av, schema, compiled_sv, |
| 2280 |
490 |
| (AV *)SvRV(*selections_svp), root_type_name_sv, |
| 2281 |
|
| variables_hv, fragments_hv, visited_fragments_hv |
| 2282 |
|
| ); |
| 2283 |
490 |
| SvREFCNT_dec((SV *)visited_fragments_hv); |
| 2284 |
|
| } |
| 2285 |
|
| } |
| 2286 |
|
| } |
| 2287 |
|
| |
| 2288 |
|
| static SV * |
| 2289 |
5427 |
| gql_validation_compiled_directives_sv(SV *compiled_sv) { |
| 2290 |
5427 |
| HV *compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 2291 |
5427 |
▶ | SV **directives_svp = compiled_hv ? hv_fetch(compiled_hv, "directives", 10, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **directives_svp = compiled_hv ? hv_fetch(compiled_hv, "directives", 10, 0) : NULL; |
5427 |
0 |
5427 |
|
| 2292 |
5427 |
▶ | return directives_svp ? *directives_svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return directives_svp ? *directives_svp : NULL; |
5427 |
0 |
5427 |
|
| 2293 |
|
| } |
| 2294 |
|
| |
| 2295 |
|
| static int |
| 2296 |
32 |
| gql_validation_directive_has_location(HV *directive_hv, const char *location) { |
| 2297 |
32 |
| SV **locations_svp = hv_fetch(directive_hv, "locations", 9, 0); |
| 2298 |
|
| I32 i; |
| 2299 |
32 |
▶ | if (!locations_svp || !SvROK(*locations_svp) || SvTYPE(SvRV(*locations_svp)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!locations_svp || !SvROK(*locations_svp) || SvTYPE(SvRV(*locations_svp)) != SVt_PVAV) { |
32 |
0 |
32 |
| if (!locations_svp || !SvROK(*locations_svp) || SvTYPE(SvRV(*locations_svp)) != SVt_PVAV) { |
32 |
0 |
32 |
| if (!locations_svp || !SvROK(*locations_svp) || SvTYPE(SvRV(*locations_svp)) != SVt_PVAV) { |
0 |
32 |
32 |
|
| 2300 |
0 |
| return 0; |
| 2301 |
|
| } |
| 2302 |
39 |
▶ | for (i = 0; i <= av_len((AV *)SvRV(*locations_svp)); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len((AV *)SvRV(*locations_svp)); i++) { |
37 |
2 |
39 |
|
| 2303 |
37 |
| SV **item_svp = av_fetch((AV *)SvRV(*locations_svp), i, 0); |
| 2304 |
74 |
▶ | if (item_svp && SvOK(*item_svp) && strEQ(SvPV_nolen(*item_svp), location)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (item_svp && SvOK(*item_svp) && strEQ(SvPV_nolen(*item_svp), location)) { |
37 |
0 |
37 |
| if (item_svp && SvOK(*item_svp) && strEQ(SvPV_nolen(*item_svp), location)) { |
37 |
0 |
37 |
| if (item_svp && SvOK(*item_svp) && strEQ(SvPV_nolen(*item_svp), location)) { |
30 |
7 |
37 |
|
| 2305 |
30 |
| return 1; |
| 2306 |
|
| } |
| 2307 |
|
| } |
| 2308 |
2 |
| return 0; |
| 2309 |
|
| } |
| 2310 |
|
| |
| 2311 |
|
| static int |
| 2312 |
35 |
| gql_validation_value_contains_variable(SV *value_sv) { |
| 2313 |
35 |
▶ | if (!value_sv || !SvROK(value_sv)) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!value_sv || !SvROK(value_sv)) return 0; |
35 |
0 |
35 |
| if (!value_sv || !SvROK(value_sv)) return 0; |
4 |
31 |
35 |
|
| 2314 |
31 |
▶ | if (SvTYPE(SvRV(value_sv)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(value_sv)) == SVt_PVAV) { |
4 |
27 |
31 |
|
| 2315 |
4 |
| AV *value_av = (AV *)SvRV(value_sv); |
| 2316 |
|
| I32 i; |
| 2317 |
4 |
▶ | for (i = 0; i <= av_len(value_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(value_av); i++) { |
4 |
0 |
4 |
|
| 2318 |
4 |
| SV **item_svp = av_fetch(value_av, i, 0); |
| 2319 |
4 |
▶ | if (item_svp && gql_validation_value_contains_variable(*item_svp)) return 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (item_svp && gql_validation_value_contains_variable(*item_svp)) return 1; |
4 |
0 |
4 |
| if (item_svp && gql_validation_value_contains_variable(*item_svp)) return 1; |
4 |
0 |
4 |
|
| 2320 |
|
| } |
| 2321 |
0 |
| return 0; |
| 2322 |
|
| } |
| 2323 |
27 |
▶ | if (SvTYPE(SvRV(value_sv)) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(SvRV(value_sv)) == SVt_PVHV) { |
0 |
27 |
27 |
|
| 2324 |
0 |
| HV *value_hv = (HV *)SvRV(value_sv); |
| 2325 |
|
| HE *he; |
| 2326 |
0 |
| hv_iterinit(value_hv); |
| 2327 |
0 |
▶ | while ((he = hv_iternext(value_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(value_hv))) { |
0 |
0 |
0 |
|
| 2328 |
0 |
▶ | if (gql_validation_value_contains_variable(HeVAL(he))) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_validation_value_contains_variable(HeVAL(he))) return 1; |
0 |
0 |
0 |
|
| 2329 |
|
| } |
| 2330 |
0 |
| return 0; |
| 2331 |
|
| } |
| 2332 |
27 |
▶ | return !SvROK(SvRV(value_sv)) && !sv_isobject(value_sv); |
Branch: 2 branches
| Branch | True | False | Total |
| return !SvROK(SvRV(value_sv)) && !sv_isobject(value_sv); |
27 |
0 |
27 |
| return !SvROK(SvRV(value_sv)) && !sv_isobject(value_sv); |
19 |
8 |
27 |
|
| 2333 |
|
| } |
| 2334 |
|
| |
| 2335 |
|
| static void |
| 2336 |
5427 |
| gql_validation_validate_directive_list( |
| 2337 |
|
| pTHX_ AV *errors_av, SV *compiled_sv, SV *directives_sv, |
| 2338 |
|
| const char *location, HV *variables_hv, int validate_structure |
| 2339 |
|
| ) { |
| 2340 |
5427 |
| SV *compiled_directives_sv = gql_validation_compiled_directives_sv(compiled_sv); |
| 2341 |
|
| HV *compiled_directives_hv; |
| 2342 |
|
| AV *directives_av; |
| 2343 |
|
| HV *seen_hv; |
| 2344 |
|
| I32 i; |
| 2345 |
5427 |
▶ | if (!directives_sv || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV |
Branch: 3 branches
| Branch | True | False | Total |
| if (!directives_sv || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV |
33 |
5394 |
5427 |
| if (!directives_sv || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV |
33 |
0 |
33 |
| if (!directives_sv || !SvROK(directives_sv) || SvTYPE(SvRV(directives_sv)) != SVt_PVAV |
33 |
0 |
33 |
|
| 2346 |
33 |
▶ | || !compiled_directives_sv || !SvROK(compiled_directives_sv) |
Branch: 2 branches
| Branch | True | False | Total |
| || !compiled_directives_sv || !SvROK(compiled_directives_sv) |
33 |
0 |
33 |
| || !compiled_directives_sv || !SvROK(compiled_directives_sv) |
33 |
0 |
33 |
|
| 2347 |
33 |
▶ | || SvTYPE(SvRV(compiled_directives_sv)) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(compiled_directives_sv)) != SVt_PVHV) { |
0 |
33 |
33 |
|
| 2348 |
5394 |
| return; |
| 2349 |
|
| } |
| 2350 |
33 |
| directives_av = (AV *)SvRV(directives_sv); |
| 2351 |
33 |
| compiled_directives_hv = (HV *)SvRV(compiled_directives_sv); |
| 2352 |
33 |
| seen_hv = newHV(); |
| 2353 |
69 |
▶ | for (i = 0; i <= av_len(directives_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(directives_av); i++) { |
36 |
33 |
69 |
|
| 2354 |
36 |
| SV **directive_svp = av_fetch(directives_av, i, 0); |
| 2355 |
|
| HV *directive_hv; |
| 2356 |
|
| SV **name_svp; |
| 2357 |
|
| SV **location_svp; |
| 2358 |
|
| HE *def_he; |
| 2359 |
|
| HV *def_hv; |
| 2360 |
|
| STRLEN name_len; |
| 2361 |
|
| const char *name; |
| 2362 |
37 |
▶ | if (!directive_svp || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!directive_svp || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) continue; |
36 |
0 |
36 |
| if (!directive_svp || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) continue; |
36 |
0 |
36 |
| if (!directive_svp || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) continue; |
0 |
36 |
36 |
|
| 2363 |
36 |
| directive_hv = (HV *)SvRV(*directive_svp); |
| 2364 |
36 |
| name_svp = hv_fetch(directive_hv, "name", 4, 0); |
| 2365 |
36 |
| location_svp = hv_fetch(directive_hv, "location", 8, 0); |
| 2366 |
36 |
▶ | if (!name_svp || !SvOK(*name_svp)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) continue; |
36 |
0 |
36 |
| if (!name_svp || !SvOK(*name_svp)) continue; |
0 |
36 |
36 |
|
| 2367 |
36 |
| name = SvPV(*name_svp, name_len); |
| 2368 |
36 |
| def_he = hv_fetch_ent(compiled_directives_hv, *name_svp, 0, 0); |
| 2369 |
36 |
▶ | if (!def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
35 |
1 |
36 |
| if (!def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
35 |
0 |
35 |
| if (!def_he || !SvROK(HeVAL(def_he)) || SvTYPE(SvRV(HeVAL(def_he))) != SVt_PVHV) { |
0 |
35 |
35 |
|
| 2370 |
1 |
▶ | if (validate_structure) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (validate_structure) { |
1 |
0 |
1 |
|
| 2371 |
1 |
| SV *message = newSVpvf("Unknown directive '@%s'.", name); |
| 2372 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
1 |
1 |
|
| 2373 |
1 |
| SvREFCNT_dec(message); |
| 2374 |
|
| } |
| 2375 |
1 |
| continue; |
| 2376 |
|
| } |
| 2377 |
35 |
| def_hv = (HV *)SvRV(HeVAL(def_he)); |
| 2378 |
35 |
▶ | if (validate_structure && !gql_validation_directive_has_location(def_hv, location)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (validate_structure && !gql_validation_directive_has_location(def_hv, location)) { |
32 |
3 |
35 |
| if (validate_structure && !gql_validation_directive_has_location(def_hv, location)) { |
2 |
30 |
32 |
|
| 2379 |
2 |
| SV *message = newSVpvf("Directive '@%s' may not be used on %s.", name, location); |
| 2380 |
4 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
2 |
2 |
|
| 2381 |
2 |
| SvREFCNT_dec(message); |
| 2382 |
|
| } |
| 2383 |
|
| { |
| 2384 |
35 |
| SV **repeatable_svp = hv_fetch(def_hv, "repeatable", 10, 0); |
| 2385 |
35 |
▶ | if (validate_structure && hv_exists(seen_hv, name, (I32)name_len) && !(repeatable_svp && SvTRUE(*repeatable_svp))) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (validate_structure && hv_exists(seen_hv, name, (I32)name_len) && !(repeatable_svp && SvTRUE(*repeatable_svp))) { |
32 |
3 |
35 |
| if (validate_structure && hv_exists(seen_hv, name, (I32)name_len) && !(repeatable_svp && SvTRUE(*repeatable_svp))) { |
2 |
30 |
32 |
| if (validate_structure && hv_exists(seen_hv, name, (I32)name_len) && !(repeatable_svp && SvTRUE(*repeatable_svp))) { |
2 |
0 |
2 |
| if (validate_structure && hv_exists(seen_hv, name, (I32)name_len) && !(repeatable_svp && SvTRUE(*repeatable_svp))) { |
1 |
1 |
2 |
|
| 2386 |
1 |
| SV *message = newSVpvf("Directive '@%s' is not repeatable and cannot be used more than once at this location.", name); |
| 2387 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
1 |
1 |
|
| 2388 |
1 |
| SvREFCNT_dec(message); |
| 2389 |
|
| } |
| 2390 |
35 |
| (void)hv_store(seen_hv, name, (I32)name_len, newSViv(1), 0); |
| 2391 |
|
| } |
| 2392 |
|
| { |
| 2393 |
35 |
| SV **arguments_svp = hv_fetch(directive_hv, "arguments", 9, 0); |
| 2394 |
35 |
| SV **arg_defs_svp = hv_fetch(def_hv, "args", 4, 0); |
| 2395 |
35 |
▶ | HV *arguments_hv = arguments_svp && SvROK(*arguments_svp) ? (HV *)SvRV(*arguments_svp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *arguments_hv = arguments_svp && SvROK(*arguments_svp) ? (HV *)SvRV(*arguments_svp) : NULL; |
31 |
4 |
35 |
| HV *arguments_hv = arguments_svp && SvROK(*arguments_svp) ? (HV *)SvRV(*arguments_svp) : NULL; |
31 |
0 |
31 |
|
| 2396 |
35 |
▶ | HV *arg_defs_hv = arg_defs_svp && SvROK(*arg_defs_svp) ? (HV *)SvRV(*arg_defs_svp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *arg_defs_hv = arg_defs_svp && SvROK(*arg_defs_svp) ? (HV *)SvRV(*arg_defs_svp) : NULL; |
35 |
0 |
35 |
| HV *arg_defs_hv = arg_defs_svp && SvROK(*arg_defs_svp) ? (HV *)SvRV(*arg_defs_svp) : NULL; |
35 |
0 |
35 |
|
| 2397 |
35 |
| I32 count = 0; |
| 2398 |
|
| SV **keys; |
| 2399 |
|
| I32 j; |
| 2400 |
35 |
▶ | if (!arg_defs_hv) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arg_defs_hv) continue; |
0 |
35 |
35 |
|
| 2401 |
35 |
▶ | if (validate_structure && arguments_hv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (validate_structure && arguments_hv) { |
32 |
3 |
35 |
| if (validate_structure && arguments_hv) { |
28 |
4 |
32 |
|
| 2402 |
28 |
| keys = gql_parser_sorted_hash_keys(aTHX_ arguments_hv, &count); |
| 2403 |
57 |
▶ | for (j = 0; keys && j < count; j++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (j = 0; keys && j < count; j++) { |
57 |
0 |
57 |
| for (j = 0; keys && j < count; j++) { |
29 |
28 |
57 |
|
| 2404 |
29 |
▶ | if (!hv_fetch_ent(arg_defs_hv, keys[j], 0, 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_fetch_ent(arg_defs_hv, keys[j], 0, 0)) { |
1 |
28 |
29 |
|
| 2405 |
2 |
| SV *message = newSVpvf("Unknown argument '%s' on directive '@%s'.", SvPV_nolen(keys[j]), name); |
| 2406 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
1 |
1 |
|
| 2407 |
1 |
| SvREFCNT_dec(message); |
| 2408 |
|
| } |
| 2409 |
|
| } |
| 2410 |
28 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 2411 |
|
| } |
| 2412 |
35 |
| keys = gql_parser_sorted_hash_keys(aTHX_ arg_defs_hv, &count); |
| 2413 |
67 |
▶ | for (j = 0; keys && j < count; j++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (j = 0; keys && j < count; j++) { |
64 |
3 |
67 |
| for (j = 0; keys && j < count; j++) { |
32 |
32 |
64 |
|
| 2414 |
32 |
| HE *arg_he = hv_fetch_ent(arg_defs_hv, keys[j], 0, 0); |
| 2415 |
32 |
▶ | HV *arg_hv = arg_he && SvROK(HeVAL(arg_he)) ? (HV *)SvRV(HeVAL(arg_he)) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *arg_hv = arg_he && SvROK(HeVAL(arg_he)) ? (HV *)SvRV(HeVAL(arg_he)) : NULL; |
32 |
0 |
32 |
| HV *arg_hv = arg_he && SvROK(HeVAL(arg_he)) ? (HV *)SvRV(HeVAL(arg_he)) : NULL; |
32 |
0 |
32 |
|
| 2416 |
32 |
▶ | HE *value_he = arguments_hv ? hv_fetch_ent(arguments_hv, keys[j], 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| HE *value_he = arguments_hv ? hv_fetch_ent(arguments_hv, keys[j], 0, 0) : NULL; |
31 |
1 |
32 |
|
| 2417 |
32 |
▶ | SV **type_svp = arg_hv ? hv_fetch(arg_hv, "type", 4, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **type_svp = arg_hv ? hv_fetch(arg_hv, "type", 4, 0) : NULL; |
32 |
0 |
32 |
|
| 2418 |
32 |
▶ | SV **default_svp = arg_hv ? hv_fetch(arg_hv, "has_default_value", 17, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **default_svp = arg_hv ? hv_fetch(arg_hv, "has_default_value", 17, 0) : NULL; |
32 |
0 |
32 |
|
| 2419 |
32 |
▶ | if (validate_structure && !value_he && type_svp && gql_validation_type_is_non_null(*type_svp) |
Branch: 4 branches
| Branch | True | False | Total |
| if (validate_structure && !value_he && type_svp && gql_validation_type_is_non_null(*type_svp) |
29 |
3 |
32 |
| if (validate_structure && !value_he && type_svp && gql_validation_type_is_non_null(*type_svp) |
1 |
28 |
29 |
| if (validate_structure && !value_he && type_svp && gql_validation_type_is_non_null(*type_svp) |
1 |
0 |
1 |
| if (validate_structure && !value_he && type_svp && gql_validation_type_is_non_null(*type_svp) |
1 |
0 |
1 |
|
| 2420 |
2 |
▶ | && !(default_svp && SvTRUE(*default_svp))) { |
Branch: 2 branches
| Branch | True | False | Total |
| && !(default_svp && SvTRUE(*default_svp))) { |
1 |
0 |
1 |
| && !(default_svp && SvTRUE(*default_svp))) { |
1 |
0 |
1 |
|
| 2421 |
2 |
| SV *message = newSVpvf("Required argument '%s' was not provided to directive '@%s'.", SvPV_nolen(keys[j]), name); |
| 2422 |
2 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
1 |
1 |
|
| 2423 |
1 |
| SvREFCNT_dec(message); |
| 2424 |
31 |
▶ | } else if (value_he && type_svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (value_he && type_svp) { |
31 |
0 |
31 |
| } else if (value_he && type_svp) { |
31 |
0 |
31 |
|
| 2425 |
31 |
| SV *directive_value_sv = HeVAL(value_he); |
| 2426 |
31 |
| int contains_variable = gql_validation_value_contains_variable(directive_value_sv); |
| 2427 |
|
| AV *value_errors_av; |
| 2428 |
31 |
▶ | if ((!validate_structure && !contains_variable) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!validate_structure && !contains_variable) |
3 |
28 |
31 |
| if ((!validate_structure && !contains_variable) |
3 |
0 |
3 |
|
| 2429 |
31 |
▶ | || (!variables_hv && contains_variable)) { |
Branch: 2 branches
| Branch | True | False | Total |
| || (!variables_hv && contains_variable)) { |
12 |
19 |
31 |
| || (!variables_hv && contains_variable)) { |
3 |
9 |
12 |
|
| 2430 |
3 |
| continue; |
| 2431 |
|
| } |
| 2432 |
56 |
▶ | gql_validation_validate_nested_variable_position( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_nested_variable_position( |
0 |
28 |
28 |
|
| 2433 |
|
| aTHX_ errors_av, directive_value_sv, *type_svp, variables_hv, |
| 2434 |
28 |
| default_svp && SvTRUE(*default_svp), "a directive argument", |
| 2435 |
|
| location_svp ? *location_svp : NULL |
| 2436 |
|
| ); |
| 2437 |
28 |
| value_errors_av = newAV(); |
| 2438 |
28 |
▶ | gql_validation_validate_value(aTHX_ value_errors_av, NULL, compiled_sv, directive_value_sv, *type_svp, variables_hv, location_svp ? *location_svp : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_value(aTHX_ value_errors_av, NULL, compiled_sv, directive_value_sv, *type_svp, variables_hv, location_svp ? *location_svp : NULL); |
0 |
28 |
28 |
|
| 2439 |
28 |
▶ | if (av_len(value_errors_av) >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(value_errors_av) >= 0) { |
3 |
25 |
28 |
|
| 2440 |
3 |
▶ | if (contains_variable) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (contains_variable) { |
1 |
2 |
3 |
|
| 2441 |
|
| I32 error_i; |
| 2442 |
2 |
▶ | for (error_i = 0; error_i <= av_len(value_errors_av); error_i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (error_i = 0; error_i <= av_len(value_errors_av); error_i++) { |
1 |
1 |
2 |
|
| 2443 |
1 |
| SV **value_error_svp = av_fetch(value_errors_av, error_i, 0); |
| 2444 |
1 |
▶ | if (value_error_svp) av_push(errors_av, newSVsv(*value_error_svp)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (value_error_svp) av_push(errors_av, newSVsv(*value_error_svp)); |
1 |
0 |
1 |
|
| 2445 |
|
| } |
| 2446 |
1 |
| SvREFCNT_dec((SV *)value_errors_av); |
| 2447 |
1 |
| continue; |
| 2448 |
|
| } |
| 2449 |
2 |
| SV *named_type_sv = gql_validation_named_type_name_sv(*type_svp); |
| 2450 |
4 |
▶ | const char *type_name = named_type_sv && SvOK(named_type_sv) ? SvPV_nolen(named_type_sv) : "value"; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *type_name = named_type_sv && SvOK(named_type_sv) ? SvPV_nolen(named_type_sv) : "value"; |
2 |
0 |
2 |
| const char *type_name = named_type_sv && SvOK(named_type_sv) ? SvPV_nolen(named_type_sv) : "value"; |
2 |
0 |
2 |
|
| 2451 |
|
| SV *message; |
| 2452 |
2 |
▶ | if (strEQ(type_name, "Int") || strEQ(type_name, "Float") |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(type_name, "Int") || strEQ(type_name, "Float") |
2 |
0 |
2 |
| if (strEQ(type_name, "Int") || strEQ(type_name, "Float") |
2 |
0 |
2 |
|
| 2453 |
2 |
▶ | || strEQ(type_name, "String") || strEQ(type_name, "Boolean") |
Branch: 2 branches
| Branch | True | False | Total |
| || strEQ(type_name, "String") || strEQ(type_name, "Boolean") |
2 |
0 |
2 |
| || strEQ(type_name, "String") || strEQ(type_name, "Boolean") |
1 |
1 |
2 |
|
| 2454 |
1 |
▶ | || strEQ(type_name, "ID")) { |
Branch: 1 branch
| Branch | True | False | Total |
| || strEQ(type_name, "ID")) { |
0 |
1 |
1 |
|
| 2455 |
2 |
| message = newSVpvf( |
| 2456 |
|
| "Argument '%s' on directive '@%s' has invalid value: Not a %s.", |
| 2457 |
|
| SvPV_nolen(keys[j]), name, type_name |
| 2458 |
|
| ); |
| 2459 |
|
| } else { |
| 2460 |
1 |
| SV **first_error_svp = av_fetch(value_errors_av, 0, 0); |
| 2461 |
1 |
▶ | SV **first_message_svp = first_error_svp && SvROK(*first_error_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| SV **first_message_svp = first_error_svp && SvROK(*first_error_svp) |
1 |
0 |
1 |
|
| 2462 |
2 |
▶ | ? hv_fetch((HV *)SvRV(*first_error_svp), "message", 7, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? hv_fetch((HV *)SvRV(*first_error_svp), "message", 7, 0) : NULL; |
1 |
0 |
1 |
|
| 2463 |
3 |
▶ | message = newSVpvf( |
Branch: 1 branch
| Branch | True | False | Total |
| message = newSVpvf( |
1 |
0 |
1 |
|
| 2464 |
|
| "Argument '%s' on directive '@%s' has invalid value: %s", |
| 2465 |
|
| SvPV_nolen(keys[j]), name, |
| 2466 |
|
| first_message_svp ? SvPV_nolen(*first_message_svp) : "invalid value" |
| 2467 |
|
| ); |
| 2468 |
|
| } |
| 2469 |
4 |
▶ | av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL)); |
0 |
2 |
2 |
|
| 2470 |
2 |
| SvREFCNT_dec(message); |
| 2471 |
|
| } |
| 2472 |
27 |
| SvREFCNT_dec((SV *)value_errors_av); |
| 2473 |
|
| } |
| 2474 |
|
| } |
| 2475 |
35 |
| gql_parser_free_sorted_hash_keys(keys, count); |
| 2476 |
|
| } |
| 2477 |
|
| } |
| 2478 |
33 |
| SvREFCNT_dec((SV *)seen_hv); |
| 2479 |
|
| } |
| 2480 |
|
| |
| 2481 |
|
| static void |
| 2482 |
2071 |
| gql_validation_validate_directives_in_selections( |
| 2483 |
|
| pTHX_ AV *errors_av, SV *compiled_sv, AV *selections_av, |
| 2484 |
|
| HV *variables_hv, HV *fragments_hv, HV *visited_fragments_hv, |
| 2485 |
|
| int validate_structure |
| 2486 |
|
| ) { |
| 2487 |
|
| I32 i; |
| 2488 |
6819 |
▶ | for (i = 0; selections_av && i <= av_len(selections_av); i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; selections_av && i <= av_len(selections_av); i++) { |
6819 |
0 |
6819 |
| for (i = 0; selections_av && i <= av_len(selections_av); i++) { |
4748 |
2071 |
6819 |
|
| 2489 |
4748 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 2490 |
|
| HV *selection_hv; |
| 2491 |
|
| SV **kind_svp; |
| 2492 |
|
| SV **directives_svp; |
| 2493 |
|
| SV **nested_svp; |
| 2494 |
|
| const char *location; |
| 2495 |
4748 |
▶ | if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) continue; |
4748 |
0 |
4748 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) continue; |
4748 |
0 |
4748 |
| if (!selection_svp || !SvROK(*selection_svp) || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) continue; |
0 |
4748 |
4748 |
|
| 2496 |
4748 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 2497 |
4748 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 2498 |
4748 |
▶ | if (!kind_svp || !SvOK(*kind_svp)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp)) continue; |
4748 |
0 |
4748 |
| if (!kind_svp || !SvOK(*kind_svp)) continue; |
0 |
4748 |
4748 |
|
| 2499 |
4748 |
| location = strEQ(SvPV_nolen(*kind_svp), "field") ? "FIELD" |
| 2500 |
4818 |
▶ | : strEQ(SvPV_nolen(*kind_svp), "fragment_spread") ? "FRAGMENT_SPREAD" |
Branch: 2 branches
| Branch | True | False | Total |
| : strEQ(SvPV_nolen(*kind_svp), "fragment_spread") ? "FRAGMENT_SPREAD" |
70 |
4678 |
4748 |
| : strEQ(SvPV_nolen(*kind_svp), "fragment_spread") ? "FRAGMENT_SPREAD" |
38 |
32 |
70 |
|
| 2501 |
|
| : "INLINE_FRAGMENT"; |
| 2502 |
4748 |
| directives_svp = hv_fetch(selection_hv, "directives", 10, 0); |
| 2503 |
4748 |
▶ | gql_validation_validate_directive_list(aTHX_ errors_av, compiled_sv, directives_svp ? *directives_svp : NULL, location, variables_hv, validate_structure); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_directive_list(aTHX_ errors_av, compiled_sv, directives_svp ? *directives_svp : NULL, location, variables_hv, validate_structure); |
30 |
4718 |
4748 |
|
| 2504 |
9496 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread") |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread") |
38 |
4710 |
4748 |
|
| 2505 |
38 |
▶ | && fragments_hv && visited_fragments_hv && variables_hv) { |
Branch: 3 branches
| Branch | True | False | Total |
| && fragments_hv && visited_fragments_hv && variables_hv) { |
38 |
0 |
38 |
| && fragments_hv && visited_fragments_hv && variables_hv) { |
23 |
15 |
38 |
| && fragments_hv && visited_fragments_hv && variables_hv) { |
7 |
16 |
23 |
|
| 2506 |
7 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 2507 |
7 |
▶ | if (name_svp && SvOK(*name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name_svp && SvOK(*name_svp)) { |
7 |
0 |
7 |
| if (name_svp && SvOK(*name_svp)) { |
7 |
0 |
7 |
|
| 2508 |
|
| STRLEN name_len; |
| 2509 |
7 |
| const char *name = SvPV(*name_svp, name_len); |
| 2510 |
7 |
▶ | if (!hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(visited_fragments_hv, name, (I32)name_len)) { |
7 |
0 |
7 |
|
| 2511 |
7 |
| HE *fragment_he = hv_fetch_ent(fragments_hv, *name_svp, 0, 0); |
| 2512 |
7 |
| (void)hv_store(visited_fragments_hv, name, (I32)name_len, newSViv(1), 0); |
| 2513 |
7 |
▶ | if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
7 |
0 |
7 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
7 |
0 |
7 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
7 |
0 |
7 |
|
| 2514 |
7 |
| SV **fragment_selections_svp = hv_fetch((HV *)SvRV(HeVAL(fragment_he)), "selections", 10, 0); |
| 2515 |
7 |
▶ | if (fragment_selections_svp && SvROK(*fragment_selections_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (fragment_selections_svp && SvROK(*fragment_selections_svp) |
7 |
0 |
7 |
| if (fragment_selections_svp && SvROK(*fragment_selections_svp) |
7 |
0 |
7 |
|
| 2516 |
7 |
▶ | && SvTYPE(SvRV(*fragment_selections_svp)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*fragment_selections_svp)) == SVt_PVAV) { |
7 |
0 |
7 |
|
| 2517 |
7 |
| gql_validation_validate_directives_in_selections( |
| 2518 |
7 |
| aTHX_ errors_av, compiled_sv, (AV *)SvRV(*fragment_selections_svp), |
| 2519 |
|
| variables_hv, fragments_hv, visited_fragments_hv, 0 |
| 2520 |
|
| ); |
| 2521 |
|
| } |
| 2522 |
|
| } |
| 2523 |
|
| } |
| 2524 |
|
| } |
| 2525 |
|
| } |
| 2526 |
4748 |
| nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 2527 |
4748 |
▶ | if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) |
Branch: 3 branches
| Branch | True | False | Total |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) |
1546 |
3202 |
4748 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) |
1546 |
0 |
1546 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) |
1546 |
0 |
1546 |
|
| 2528 |
1546 |
| gql_validation_validate_directives_in_selections( |
| 2529 |
1546 |
| aTHX_ errors_av, compiled_sv, (AV *)SvRV(*nested_svp), |
| 2530 |
|
| variables_hv, fragments_hv, visited_fragments_hv, validate_structure |
| 2531 |
|
| ); |
| 2532 |
|
| } |
| 2533 |
2071 |
| } |
| 2534 |
|
| |
| 2535 |
|
| static void |
| 2536 |
487 |
| gql_validation_validate_document_directives( |
| 2537 |
|
| pTHX_ AV *errors_av, SV *compiled_sv, AV *ast_av, HV *fragments_hv |
| 2538 |
|
| ) { |
| 2539 |
|
| I32 i; |
| 2540 |
1006 |
▶ | for (i = 0; i <= av_len(ast_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(ast_av); i++) { |
519 |
487 |
1006 |
|
| 2541 |
519 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 2542 |
|
| HV *node_hv; |
| 2543 |
|
| SV **kind_svp; |
| 2544 |
|
| SV **directives_svp; |
| 2545 |
|
| SV **selections_svp; |
| 2546 |
519 |
| HV *variables_hv = NULL; |
| 2547 |
|
| const char *location; |
| 2548 |
519 |
| HV *visited_fragments_hv = NULL; |
| 2549 |
519 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
0 |
519 |
519 |
|
| 2550 |
519 |
| node_hv = (HV *)SvRV(*node_svp); |
| 2551 |
519 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 2552 |
519 |
▶ | if (!kind_svp || !SvOK(*kind_svp)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp)) continue; |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp)) continue; |
0 |
519 |
519 |
|
| 2553 |
1038 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "operation")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "operation")) { |
490 |
29 |
519 |
|
| 2554 |
490 |
| SV **operation_type_svp = hv_fetch(node_hv, "operationType", 13, 0); |
| 2555 |
490 |
| SV **variables_svp = hv_fetch(node_hv, "variables", 9, 0); |
| 2556 |
164 |
▶ | location = operation_type_svp && SvOK(*operation_type_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| location = operation_type_svp && SvOK(*operation_type_svp) |
164 |
0 |
164 |
|
| 2557 |
328 |
▶ | && strEQ(SvPV_nolen(*operation_type_svp), "mutation") ? "MUTATION" |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*operation_type_svp), "mutation") ? "MUTATION" |
153 |
11 |
164 |
|
| 2558 |
807 |
▶ | : operation_type_svp && SvOK(*operation_type_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| : operation_type_svp && SvOK(*operation_type_svp) |
164 |
326 |
490 |
| : operation_type_svp && SvOK(*operation_type_svp) |
153 |
326 |
479 |
| : operation_type_svp && SvOK(*operation_type_svp) |
153 |
0 |
153 |
|
| 2559 |
306 |
▶ | && strEQ(SvPV_nolen(*operation_type_svp), "subscription") ? "SUBSCRIPTION" |
Branch: 1 branch
| Branch | True | False | Total |
| && strEQ(SvPV_nolen(*operation_type_svp), "subscription") ? "SUBSCRIPTION" |
4 |
149 |
153 |
|
| 2560 |
|
| : "QUERY"; |
| 2561 |
490 |
▶ | if (variables_svp && SvROK(*variables_svp)) variables_hv = (HV *)SvRV(*variables_svp); |
Branch: 2 branches
| Branch | True | False | Total |
| if (variables_svp && SvROK(*variables_svp)) variables_hv = (HV *)SvRV(*variables_svp); |
127 |
363 |
490 |
| if (variables_svp && SvROK(*variables_svp)) variables_hv = (HV *)SvRV(*variables_svp); |
127 |
0 |
127 |
|
| 2562 |
490 |
| visited_fragments_hv = newHV(); |
| 2563 |
490 |
▶ | if (variables_hv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (variables_hv) { |
127 |
363 |
490 |
|
| 2564 |
|
| HE *variable_he; |
| 2565 |
127 |
| hv_iterinit(variables_hv); |
| 2566 |
287 |
▶ | while ((variable_he = hv_iternext(variables_hv))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((variable_he = hv_iternext(variables_hv))) { |
160 |
127 |
287 |
|
| 2567 |
160 |
| SV *variable_sv = HeVAL(variable_he); |
| 2568 |
160 |
▶ | if (variable_sv && SvROK(variable_sv) && SvTYPE(SvRV(variable_sv)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (variable_sv && SvROK(variable_sv) && SvTYPE(SvRV(variable_sv)) == SVt_PVHV) { |
160 |
0 |
160 |
| if (variable_sv && SvROK(variable_sv) && SvTYPE(SvRV(variable_sv)) == SVt_PVHV) { |
160 |
0 |
160 |
| if (variable_sv && SvROK(variable_sv) && SvTYPE(SvRV(variable_sv)) == SVt_PVHV) { |
160 |
0 |
160 |
|
| 2569 |
160 |
| SV **variable_directives_svp = hv_fetch((HV *)SvRV(variable_sv), "directives", 10, 0); |
| 2570 |
160 |
▶ | gql_validation_validate_directive_list( |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_directive_list( |
2 |
158 |
160 |
|
| 2571 |
|
| aTHX_ errors_av, compiled_sv, |
| 2572 |
|
| variable_directives_svp ? *variable_directives_svp : NULL, |
| 2573 |
|
| "VARIABLE_DEFINITION", variables_hv, 1 |
| 2574 |
|
| ); |
| 2575 |
|
| } |
| 2576 |
|
| } |
| 2577 |
|
| } |
| 2578 |
|
| } else { |
| 2579 |
29 |
| location = "FRAGMENT_DEFINITION"; |
| 2580 |
|
| } |
| 2581 |
519 |
| directives_svp = hv_fetch(node_hv, "directives", 10, 0); |
| 2582 |
519 |
▶ | gql_validation_validate_directive_list(aTHX_ errors_av, compiled_sv, directives_svp ? *directives_svp : NULL, location, variables_hv, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_validation_validate_directive_list(aTHX_ errors_av, compiled_sv, directives_svp ? *directives_svp : NULL, location, variables_hv, 1); |
1 |
518 |
519 |
|
| 2583 |
519 |
| selections_svp = hv_fetch(node_hv, "selections", 10, 0); |
| 2584 |
519 |
▶ | if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) |
Branch: 3 branches
| Branch | True | False | Total |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) |
518 |
1 |
519 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) |
518 |
0 |
518 |
| if (selections_svp && SvROK(*selections_svp) && SvTYPE(SvRV(*selections_svp)) == SVt_PVAV) |
518 |
0 |
518 |
|
| 2585 |
518 |
| gql_validation_validate_directives_in_selections( |
| 2586 |
518 |
| aTHX_ errors_av, compiled_sv, (AV *)SvRV(*selections_svp), |
| 2587 |
|
| variables_hv, fragments_hv, visited_fragments_hv, 1 |
| 2588 |
|
| ); |
| 2589 |
519 |
▶ | if (visited_fragments_hv) SvREFCNT_dec((SV *)visited_fragments_hv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (visited_fragments_hv) SvREFCNT_dec((SV *)visited_fragments_hv); |
490 |
29 |
519 |
|
| 2590 |
|
| } |
| 2591 |
487 |
| } |
| 2592 |
|
| |
| 2593 |
|
| static int |
| 2594 |
1416 |
| gql_validation_type_is_list(SV *type_sv) { |
| 2595 |
|
| HV *type_hv; |
| 2596 |
|
| SV **kind_svp; |
| 2597 |
1416 |
▶ | if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVHV) { |
1416 |
0 |
1416 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVHV) { |
1416 |
0 |
1416 |
| if (!type_sv || !SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVHV) { |
0 |
1416 |
1416 |
|
| 2598 |
0 |
| return 0; |
| 2599 |
|
| } |
| 2600 |
1416 |
| type_hv = (HV *)SvRV(type_sv); |
| 2601 |
1416 |
| kind_svp = hv_fetch(type_hv, "kind", 4, 0); |
| 2602 |
1416 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
1416 |
0 |
1416 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
1416 |
0 |
1416 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
1416 |
1416 |
|
| 2603 |
0 |
| return 0; |
| 2604 |
|
| } |
| 2605 |
2832 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "LIST")) { |
128 |
1288 |
1416 |
|
| 2606 |
128 |
| return 1; |
| 2607 |
|
| } |
| 2608 |
2576 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "NON_NULL")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "NON_NULL")) { |
97 |
1191 |
1288 |
|
| 2609 |
97 |
| SV **of_svp = hv_fetch(type_hv, "of", 2, 0); |
| 2610 |
97 |
▶ | return of_svp ? gql_validation_type_is_list(*of_svp) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return of_svp ? gql_validation_type_is_list(*of_svp) : 0; |
97 |
0 |
97 |
|
| 2611 |
|
| } |
| 2612 |
1191 |
| return 0; |
| 2613 |
|
| } |
| 2614 |
|
| |
| 2615 |
|
| static UV |
| 2616 |
1401 |
| gql_validation_cost_add(UV total, UV add, UV max_cost) { |
| 2617 |
1401 |
▶ | return add > max_cost - total ? max_cost + 1 : total + add; |
Branch: 1 branch
| Branch | True | False | Total |
| return add > max_cost - total ? max_cost + 1 : total + add; |
0 |
1401 |
1401 |
|
| 2618 |
|
| } |
| 2619 |
|
| |
| 2620 |
|
| static UV gql_validation_selection_cost( |
| 2621 |
|
| pTHX_ SV *compiled_sv, AV *selections_av, SV *parent_type_name_sv, |
| 2622 |
|
| HV *fragments_hv, HV *visited_hv, UV default_list_size, UV max_cost |
| 2623 |
|
| ); |
| 2624 |
|
| |
| 2625 |
|
| static UV |
| 2626 |
841 |
| gql_validation_selection_cost( |
| 2627 |
|
| pTHX_ SV *compiled_sv, AV *selections_av, SV *parent_type_name_sv, |
| 2628 |
|
| HV *fragments_hv, HV *visited_hv, UV default_list_size, UV max_cost |
| 2629 |
|
| ) { |
| 2630 |
841 |
| HV *parent_type_hv = gql_validation_compiled_type_hv(aTHX_ compiled_sv, parent_type_name_sv); |
| 2631 |
841 |
▶ | SV **fields_svp = parent_type_hv ? hv_fetch(parent_type_hv, "fields", 6, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **fields_svp = parent_type_hv ? hv_fetch(parent_type_hv, "fields", 6, 0) : NULL; |
841 |
0 |
841 |
|
| 2632 |
828 |
▶ | HV *fields_hv = fields_svp && SvROK(*fields_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| HV *fields_hv = fields_svp && SvROK(*fields_svp) |
828 |
0 |
828 |
|
| 2633 |
1669 |
▶ | && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV ? (HV *)SvRV(*fields_svp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV ? (HV *)SvRV(*fields_svp) : NULL; |
828 |
13 |
841 |
| && SvTYPE(SvRV(*fields_svp)) == SVt_PVHV ? (HV *)SvRV(*fields_svp) : NULL; |
828 |
0 |
828 |
|
| 2634 |
841 |
| UV total = 0; |
| 2635 |
|
| I32 i; |
| 2636 |
|
| |
| 2637 |
2238 |
▶ | for (i = 0; i <= av_len(selections_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(selections_av); i++) { |
1401 |
837 |
2238 |
|
| 2638 |
1401 |
| SV **selection_svp = av_fetch(selections_av, i, 0); |
| 2639 |
|
| HV *selection_hv; |
| 2640 |
|
| SV **kind_svp; |
| 2641 |
1401 |
▶ | if (!selection_svp || !SvROK(*selection_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!selection_svp || !SvROK(*selection_svp) |
1401 |
0 |
1401 |
| if (!selection_svp || !SvROK(*selection_svp) |
1401 |
0 |
1401 |
|
| 2642 |
1401 |
▶ | || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(*selection_svp)) != SVt_PVHV) { |
0 |
1401 |
1401 |
|
| 2643 |
0 |
| continue; |
| 2644 |
|
| } |
| 2645 |
1401 |
| selection_hv = (HV *)SvRV(*selection_svp); |
| 2646 |
1401 |
| kind_svp = hv_fetch(selection_hv, "kind", 4, 0); |
| 2647 |
1401 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
1401 |
0 |
1401 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
1401 |
0 |
1401 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
1401 |
1401 |
|
| 2648 |
0 |
| continue; |
| 2649 |
|
| } |
| 2650 |
|
| |
| 2651 |
2802 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "field")) { |
1369 |
32 |
1401 |
|
| 2652 |
1369 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 2653 |
1369 |
▶ | HE *field_he = name_svp && fields_hv |
Branch: 1 branch
| Branch | True | False | Total |
| HE *field_he = name_svp && fields_hv |
1365 |
4 |
1369 |
|
| 2654 |
2738 |
▶ | ? hv_fetch_ent(fields_hv, *name_svp, 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? hv_fetch_ent(fields_hv, *name_svp, 0, 0) : NULL; |
1369 |
0 |
1369 |
|
| 2655 |
1369 |
| UV own_cost = 1; |
| 2656 |
1369 |
| UV multiplier = 1; |
| 2657 |
1369 |
| UV child_cost = 0; |
| 2658 |
1369 |
| int is_list = 0; |
| 2659 |
1369 |
▶ | if (field_he && SvROK(HeVAL(field_he)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (field_he && SvROK(HeVAL(field_he)) |
1319 |
50 |
1369 |
| if (field_he && SvROK(HeVAL(field_he)) |
1319 |
0 |
1319 |
|
| 2660 |
1319 |
▶ | && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(HeVAL(field_he))) == SVt_PVHV) { |
1319 |
0 |
1319 |
|
| 2661 |
1319 |
| HV *field_hv = (HV *)SvRV(HeVAL(field_he)); |
| 2662 |
1319 |
| SV **cost_svp = hv_fetch(field_hv, "cost", 4, 0); |
| 2663 |
1319 |
| SV **type_svp = hv_fetch(field_hv, "type", 4, 0); |
| 2664 |
1319 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 2665 |
1319 |
▶ | if (cost_svp && SvOK(*cost_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cost_svp && SvOK(*cost_svp)) { |
8 |
1311 |
1319 |
| if (cost_svp && SvOK(*cost_svp)) { |
8 |
0 |
8 |
|
| 2666 |
8 |
| own_cost = SvUV(*cost_svp); |
| 2667 |
|
| } |
| 2668 |
1319 |
▶ | if (type_svp && gql_validation_type_is_list(*type_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (type_svp && gql_validation_type_is_list(*type_svp)) { |
1319 |
0 |
1319 |
| if (type_svp && gql_validation_type_is_list(*type_svp)) { |
128 |
1191 |
1319 |
|
| 2669 |
128 |
| SV **list_size_svp = hv_fetch(field_hv, "list_size", 9, 0); |
| 2670 |
7 |
▶ | multiplier = list_size_svp && SvOK(*list_size_svp) |
Branch: 1 branch
| Branch | True | False | Total |
| multiplier = list_size_svp && SvOK(*list_size_svp) |
7 |
0 |
7 |
|
| 2671 |
135 |
▶ | ? SvUV(*list_size_svp) : default_list_size; |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvUV(*list_size_svp) : default_list_size; |
7 |
121 |
128 |
|
| 2672 |
128 |
| is_list = 1; |
| 2673 |
|
| } |
| 2674 |
1319 |
▶ | if (type_svp && nested_svp && SvROK(*nested_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (type_svp && nested_svp && SvROK(*nested_svp) |
1319 |
0 |
1319 |
| if (type_svp && nested_svp && SvROK(*nested_svp) |
361 |
958 |
1319 |
| if (type_svp && nested_svp && SvROK(*nested_svp) |
361 |
0 |
361 |
|
| 2675 |
361 |
▶ | && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
361 |
0 |
361 |
|
| 2676 |
361 |
| SV *child_type_name_sv = gql_validation_named_type_name_sv(*type_svp); |
| 2677 |
361 |
| child_cost = gql_validation_selection_cost( |
| 2678 |
361 |
| aTHX_ compiled_sv, (AV *)SvRV(*nested_svp), child_type_name_sv, |
| 2679 |
|
| fragments_hv, visited_hv, default_list_size, max_cost |
| 2680 |
|
| ); |
| 2681 |
|
| } |
| 2682 |
1319 |
▶ | if (is_list && child_cost == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_list && child_cost == 0) { |
128 |
1191 |
1319 |
| if (is_list && child_cost == 0) { |
28 |
100 |
128 |
|
| 2683 |
|
| /* A scalar/enum list still serializes each result item. Charge one |
| 2684 |
|
| * unit per estimated item even though it has no sub-selection. */ |
| 2685 |
28 |
| child_cost = 1; |
| 2686 |
|
| } |
| 2687 |
|
| } |
| 2688 |
1369 |
| total = gql_validation_cost_add(total, own_cost, max_cost); |
| 2689 |
1369 |
▶ | if (total > max_cost) return total; |
Branch: 1 branch
| Branch | True | False | Total |
| if (total > max_cost) return total; |
0 |
1369 |
1369 |
|
| 2690 |
1369 |
▶ | if (child_cost) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (child_cost) { |
389 |
980 |
1369 |
|
| 2691 |
389 |
▶ | if (multiplier > (max_cost - total) / child_cost) return max_cost + 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (multiplier > (max_cost - total) / child_cost) return max_cost + 1; |
4 |
385 |
389 |
|
| 2692 |
385 |
| total += multiplier * child_cost; |
| 2693 |
|
| } |
| 2694 |
1365 |
▶ | if (total > max_cost) return total; |
Branch: 1 branch
| Branch | True | False | Total |
| if (total > max_cost) return total; |
0 |
1365 |
1365 |
|
| 2695 |
1365 |
| continue; |
| 2696 |
|
| } |
| 2697 |
|
| |
| 2698 |
64 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "inline_fragment")) { |
27 |
5 |
32 |
|
| 2699 |
27 |
| SV **nested_svp = hv_fetch(selection_hv, "selections", 10, 0); |
| 2700 |
27 |
| SV **on_svp = hv_fetch(selection_hv, "on", 2, 0); |
| 2701 |
27 |
▶ | if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
27 |
0 |
27 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
27 |
0 |
27 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
27 |
0 |
27 |
|
| 2702 |
54 |
▶ | UV nested_cost = gql_validation_selection_cost( |
Branch: 1 branch
| Branch | True | False | Total |
| UV nested_cost = gql_validation_selection_cost( |
27 |
0 |
27 |
|
| 2703 |
27 |
| aTHX_ compiled_sv, (AV *)SvRV(*nested_svp), |
| 2704 |
27 |
▶ | on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv, |
Branch: 1 branch
| Branch | True | False | Total |
| on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv, |
27 |
0 |
27 |
|
| 2705 |
|
| fragments_hv, visited_hv, default_list_size, max_cost |
| 2706 |
|
| ); |
| 2707 |
27 |
| total = gql_validation_cost_add(total, nested_cost, max_cost); |
| 2708 |
27 |
▶ | if (total > max_cost) return total; |
Branch: 1 branch
| Branch | True | False | Total |
| if (total > max_cost) return total; |
0 |
27 |
27 |
|
| 2709 |
|
| } |
| 2710 |
27 |
| continue; |
| 2711 |
|
| } |
| 2712 |
|
| |
| 2713 |
10 |
▶ | if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(SvPV_nolen(*kind_svp), "fragment_spread")) { |
5 |
0 |
5 |
|
| 2714 |
5 |
| SV **name_svp = hv_fetch(selection_hv, "name", 4, 0); |
| 2715 |
|
| HE *fragment_he; |
| 2716 |
|
| STRLEN name_len; |
| 2717 |
|
| const char *name; |
| 2718 |
5 |
▶ | if (!name_svp || !SvOK(*name_svp)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp)) continue; |
5 |
0 |
5 |
| if (!name_svp || !SvOK(*name_svp)) continue; |
0 |
5 |
5 |
|
| 2719 |
5 |
| name = SvPV(*name_svp, name_len); |
| 2720 |
5 |
▶ | if (hv_exists(visited_hv, name, (I32)name_len)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(visited_hv, name, (I32)name_len)) continue; |
0 |
5 |
5 |
|
| 2721 |
5 |
| fragment_he = hv_fetch_ent(fragments_hv, *name_svp, 0, 0); |
| 2722 |
5 |
▶ | if (fragment_he && SvROK(HeVAL(fragment_he)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (fragment_he && SvROK(HeVAL(fragment_he)) |
5 |
0 |
5 |
| if (fragment_he && SvROK(HeVAL(fragment_he)) |
5 |
0 |
5 |
|
| 2723 |
5 |
▶ | && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(HeVAL(fragment_he))) == SVt_PVHV) { |
5 |
0 |
5 |
|
| 2724 |
5 |
| HV *fragment_hv = (HV *)SvRV(HeVAL(fragment_he)); |
| 2725 |
5 |
| SV **nested_svp = hv_fetch(fragment_hv, "selections", 10, 0); |
| 2726 |
5 |
| SV **on_svp = hv_fetch(fragment_hv, "on", 2, 0); |
| 2727 |
5 |
| (void)hv_store(visited_hv, name, (I32)name_len, newSViv(1), 0); |
| 2728 |
5 |
▶ | if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
5 |
0 |
5 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
5 |
0 |
5 |
| if (nested_svp && SvROK(*nested_svp) && SvTYPE(SvRV(*nested_svp)) == SVt_PVAV) { |
5 |
0 |
5 |
|
| 2729 |
10 |
▶ | UV nested_cost = gql_validation_selection_cost( |
Branch: 1 branch
| Branch | True | False | Total |
| UV nested_cost = gql_validation_selection_cost( |
5 |
0 |
5 |
|
| 2730 |
5 |
| aTHX_ compiled_sv, (AV *)SvRV(*nested_svp), |
| 2731 |
5 |
▶ | on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv, |
Branch: 1 branch
| Branch | True | False | Total |
| on_svp && SvOK(*on_svp) ? *on_svp : parent_type_name_sv, |
5 |
0 |
5 |
|
| 2732 |
|
| fragments_hv, visited_hv, default_list_size, max_cost |
| 2733 |
|
| ); |
| 2734 |
5 |
| total = gql_validation_cost_add(total, nested_cost, max_cost); |
| 2735 |
|
| } |
| 2736 |
5 |
| (void)hv_delete(visited_hv, name, (I32)name_len, G_DISCARD); |
| 2737 |
5 |
▶ | if (total > max_cost) return total; |
Branch: 1 branch
| Branch | True | False | Total |
| if (total > max_cost) return total; |
0 |
5 |
5 |
|
| 2738 |
|
| } |
| 2739 |
|
| } |
| 2740 |
|
| } |
| 2741 |
837 |
| return total; |
| 2742 |
|
| } |
| 2743 |
|
| |
| 2744 |
|
| static SV * |
| 2745 |
447 |
| gql_validation_check_cost(pTHX_ SV *schema, SV *document, SV *options) { |
| 2746 |
447 |
| AV *errors_av = newAV(); |
| 2747 |
|
| SV *ast_sv; |
| 2748 |
|
| SV *compiled_sv; |
| 2749 |
|
| AV *ast_av; |
| 2750 |
|
| HV *fragments_hv; |
| 2751 |
|
| HV *options_hv; |
| 2752 |
|
| SV **max_cost_svp; |
| 2753 |
|
| SV **default_list_size_svp; |
| 2754 |
|
| SV **operation_name_svp; |
| 2755 |
|
| UV max_cost; |
| 2756 |
447 |
| UV default_list_size = 10; |
| 2757 |
|
| I32 i; |
| 2758 |
|
| |
| 2759 |
447 |
▶ | if (!options || !SvROK(options) || SvTYPE(SvRV(options)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!options || !SvROK(options) || SvTYPE(SvRV(options)) != SVt_PVHV) { |
447 |
0 |
447 |
| if (!options || !SvROK(options) || SvTYPE(SvRV(options)) != SVt_PVHV) { |
447 |
0 |
447 |
| if (!options || !SvROK(options) || SvTYPE(SvRV(options)) != SVt_PVHV) { |
0 |
447 |
447 |
|
| 2760 |
0 |
| croak("query cost options must be a hash reference"); |
| 2761 |
|
| } |
| 2762 |
447 |
| options_hv = (HV *)SvRV(options); |
| 2763 |
447 |
| max_cost_svp = hv_fetch(options_hv, "max_cost", 8, 0); |
| 2764 |
447 |
▶ | if (!max_cost_svp || !SvOK(*max_cost_svp) || !SvIOK(*max_cost_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!max_cost_svp || !SvOK(*max_cost_svp) || !SvIOK(*max_cost_svp) |
447 |
0 |
447 |
| if (!max_cost_svp || !SvOK(*max_cost_svp) || !SvIOK(*max_cost_svp) |
447 |
0 |
447 |
| if (!max_cost_svp || !SvOK(*max_cost_svp) || !SvIOK(*max_cost_svp) |
447 |
0 |
447 |
|
| 2765 |
447 |
▶ | || SvIV(*max_cost_svp) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| || SvIV(*max_cost_svp) < 0) { |
0 |
447 |
447 |
|
| 2766 |
0 |
| croak("max_cost must be a non-negative integer"); |
| 2767 |
|
| } |
| 2768 |
447 |
| max_cost = SvUV(*max_cost_svp); |
| 2769 |
447 |
| default_list_size_svp = hv_fetch(options_hv, "default_list_size", 17, 0); |
| 2770 |
447 |
▶ | if (default_list_size_svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (default_list_size_svp) { |
442 |
5 |
447 |
|
| 2771 |
442 |
▶ | if (!SvIOK(*default_list_size_svp) || SvIV(*default_list_size_svp) < 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvIOK(*default_list_size_svp) || SvIV(*default_list_size_svp) < 1) { |
442 |
0 |
442 |
| if (!SvIOK(*default_list_size_svp) || SvIV(*default_list_size_svp) < 1) { |
0 |
442 |
442 |
|
| 2772 |
0 |
| croak("default_list_size must be a positive integer"); |
| 2773 |
|
| } |
| 2774 |
442 |
| default_list_size = SvUV(*default_list_size_svp); |
| 2775 |
|
| } |
| 2776 |
447 |
| operation_name_svp = hv_fetch(options_hv, "operation_name", 14, 0); |
| 2777 |
|
| |
| 2778 |
447 |
▶ | ast_sv = document && SvROK(document) |
Branch: 1 branch
| Branch | True | False | Total |
| ast_sv = document && SvROK(document) |
442 |
5 |
447 |
|
| 2779 |
442 |
| ? newSVsv(document) |
| 2780 |
452 |
▶ | : gql_parse_document(aTHX_ document, &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| : gql_parse_document(aTHX_ document, &PL_sv_undef); |
447 |
0 |
447 |
|
| 2781 |
447 |
| compiled_sv = gql_schema_compile_schema(aTHX_ schema); |
| 2782 |
447 |
| ast_av = (AV *)SvRV(ast_sv); |
| 2783 |
447 |
| fragments_hv = gql_validation_build_fragments_map(aTHX_ ast_av); |
| 2784 |
907 |
▶ | for (i = 0; i <= av_len(ast_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(ast_av); i++) { |
460 |
447 |
907 |
|
| 2785 |
460 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 2786 |
|
| HV *node_hv; |
| 2787 |
|
| SV **kind_svp; |
| 2788 |
|
| SV **operation_type_svp; |
| 2789 |
|
| HV *compiled_hv; |
| 2790 |
|
| SV **roots_svp; |
| 2791 |
|
| SV **root_svp; |
| 2792 |
|
| SV **selections_svp; |
| 2793 |
|
| HV *visited_hv; |
| 2794 |
|
| UV cost; |
| 2795 |
460 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
460 |
0 |
460 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
460 |
0 |
460 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) continue; |
0 |
460 |
460 |
|
| 2796 |
460 |
| node_hv = (HV *)SvRV(*node_svp); |
| 2797 |
460 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 2798 |
920 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "operation")) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "operation")) continue; |
460 |
0 |
460 |
| if (!kind_svp || !SvOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "operation")) continue; |
460 |
0 |
460 |
| if (!kind_svp || !SvOK(*kind_svp) || !strEQ(SvPV_nolen(*kind_svp), "operation")) continue; |
11 |
449 |
460 |
|
| 2799 |
449 |
▶ | if (operation_name_svp && SvOK(*operation_name_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (operation_name_svp && SvOK(*operation_name_svp)) { |
8 |
441 |
449 |
| if (operation_name_svp && SvOK(*operation_name_svp)) { |
8 |
0 |
8 |
|
| 2800 |
8 |
| SV **name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 2801 |
8 |
▶ | if (!name_svp || !SvOK(*name_svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name_svp || !SvOK(*name_svp) |
8 |
0 |
8 |
| if (!name_svp || !SvOK(*name_svp) |
8 |
0 |
8 |
|
| 2802 |
8 |
▶ | || !sv_eq(*name_svp, *operation_name_svp)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| || !sv_eq(*name_svp, *operation_name_svp)) continue; |
1 |
7 |
8 |
|
| 2803 |
|
| } |
| 2804 |
448 |
| operation_type_svp = hv_fetch(node_hv, "operationType", 13, 0); |
| 2805 |
448 |
| compiled_hv = gql_validation_compiled_hv_from_sv(compiled_sv); |
| 2806 |
448 |
▶ | roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| roots_svp = compiled_hv ? hv_fetch(compiled_hv, "roots", 5, 0) : NULL; |
448 |
0 |
448 |
|
| 2807 |
448 |
▶ | root_svp = roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV |
Branch: 2 branches
| Branch | True | False | Total |
| root_svp = roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV |
448 |
0 |
448 |
| root_svp = roots_svp && SvROK(*roots_svp) && SvTYPE(SvRV(*roots_svp)) == SVt_PVHV |
448 |
0 |
448 |
|
| 2808 |
589 |
▶ | ? hv_fetch((HV *)SvRV(*roots_svp), |
Branch: 4 branches
| Branch | True | False | Total |
| ? hv_fetch((HV *)SvRV(*roots_svp), |
141 |
307 |
448 |
| ? hv_fetch((HV *)SvRV(*roots_svp), |
141 |
0 |
141 |
| ? hv_fetch((HV *)SvRV(*roots_svp), |
141 |
307 |
448 |
| ? hv_fetch((HV *)SvRV(*roots_svp), |
141 |
0 |
141 |
|
| 2809 |
|
| operation_type_svp && SvOK(*operation_type_svp) ? SvPV_nolen(*operation_type_svp) : "query", |
| 2810 |
|
| operation_type_svp && SvOK(*operation_type_svp) ? (I32)SvCUR(*operation_type_svp) : 5, 0) |
| 2811 |
448 |
▶ | : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| : NULL; |
448 |
0 |
448 |
|
| 2812 |
448 |
| selections_svp = hv_fetch(node_hv, "selections", 10, 0); |
| 2813 |
448 |
▶ | if (!root_svp || !selections_svp || !SvROK(*selections_svp) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!root_svp || !selections_svp || !SvROK(*selections_svp) |
448 |
0 |
448 |
| if (!root_svp || !selections_svp || !SvROK(*selections_svp) |
448 |
0 |
448 |
| if (!root_svp || !selections_svp || !SvROK(*selections_svp) |
448 |
0 |
448 |
|
| 2814 |
448 |
▶ | || SvTYPE(SvRV(*selections_svp)) != SVt_PVAV) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| || SvTYPE(SvRV(*selections_svp)) != SVt_PVAV) continue; |
0 |
448 |
448 |
|
| 2815 |
448 |
| visited_hv = newHV(); |
| 2816 |
448 |
| cost = gql_validation_selection_cost( |
| 2817 |
448 |
| aTHX_ compiled_sv, (AV *)SvRV(*selections_svp), *root_svp, |
| 2818 |
|
| fragments_hv, visited_hv, default_list_size, max_cost |
| 2819 |
|
| ); |
| 2820 |
448 |
| SvREFCNT_dec((SV *)visited_hv); |
| 2821 |
448 |
▶ | if (cost > max_cost) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cost > max_cost) { |
4 |
444 |
448 |
|
| 2822 |
4 |
| SV **name_svp = hv_fetch(node_hv, "name", 4, 0); |
| 2823 |
4 |
▶ | SV *message = newSVpvf( |
Branch: 2 branches
| Branch | True | False | Total |
| SV *message = newSVpvf( |
0 |
4 |
4 |
| SV *message = newSVpvf( |
0 |
0 |
0 |
|
| 2824 |
|
| "Query cost exceeds maximum of %" UVuf " in %s operation", |
| 2825 |
|
| max_cost, name_svp && SvOK(*name_svp) ? SvPV_nolen(*name_svp) : "anonymous" |
| 2826 |
|
| ); |
| 2827 |
4 |
| av_push(errors_av, gql_validation_error(aTHX_ SvPV_nolen(message), NULL)); |
| 2828 |
4 |
| SvREFCNT_dec(message); |
| 2829 |
|
| } |
| 2830 |
|
| } |
| 2831 |
447 |
| SvREFCNT_dec((SV *)fragments_hv); |
| 2832 |
447 |
| SvREFCNT_dec(ast_sv); |
| 2833 |
447 |
| SvREFCNT_dec(compiled_sv); |
| 2834 |
447 |
| return newRV_noinc((SV *)errors_av); |
| 2835 |
|
| } |
| 2836 |
|
| |
| 2837 |
|
| static SV * |
| 2838 |
487 |
| gql_validation_validate(pTHX_ SV *schema, SV *document, SV *options) { |
| 2839 |
487 |
| AV *errors_av = newAV(); |
| 2840 |
487 |
| SV *ast_sv = gql_validation_parse_ast(aTHX_ document, options, errors_av); |
| 2841 |
487 |
| SV *compiled_sv = gql_schema_compile_schema(aTHX_ schema); |
| 2842 |
487 |
| AV *operations_av = newAV(); |
| 2843 |
|
| HV *fragments_hv; |
| 2844 |
487 |
| AV *operation_errors_av = newAV(); |
| 2845 |
487 |
| AV *fragment_cycle_errors_av = newAV(); |
| 2846 |
|
| AV *ast_av; |
| 2847 |
|
| I32 ast_len; |
| 2848 |
|
| I32 i; |
| 2849 |
|
| SV *ret; |
| 2850 |
|
| |
| 2851 |
487 |
▶ | if (!SvROK(ast_sv) || SvTYPE(SvRV(ast_sv)) != SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(ast_sv) || SvTYPE(SvRV(ast_sv)) != SVt_PVAV) { |
487 |
0 |
487 |
| if (!SvROK(ast_sv) || SvTYPE(SvRV(ast_sv)) != SVt_PVAV) { |
0 |
487 |
487 |
|
| 2852 |
0 |
| SvREFCNT_dec(ast_sv); |
| 2853 |
0 |
| SvREFCNT_dec(compiled_sv); |
| 2854 |
0 |
| croak("Validation AST must be an array reference"); |
| 2855 |
|
| } |
| 2856 |
|
| |
| 2857 |
487 |
| ast_av = (AV *)SvRV(ast_sv); |
| 2858 |
487 |
| ast_len = av_len(ast_av); |
| 2859 |
487 |
▶ | if (ast_len >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ast_len >= 0) { |
487 |
0 |
487 |
|
| 2860 |
487 |
| av_extend(operations_av, ast_len); |
| 2861 |
|
| } |
| 2862 |
|
| |
| 2863 |
1006 |
▶ | for (i = 0; i <= ast_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= ast_len; i++) { |
519 |
487 |
1006 |
|
| 2864 |
519 |
| SV **node_svp = av_fetch(ast_av, i, 0); |
| 2865 |
|
| HV *node_hv; |
| 2866 |
|
| SV **kind_svp; |
| 2867 |
|
| |
| 2868 |
519 |
▶ | if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
519 |
0 |
519 |
| if (!node_svp || !SvROK(*node_svp) || SvTYPE(SvRV(*node_svp)) != SVt_PVHV) { |
0 |
519 |
519 |
|
| 2869 |
0 |
| continue; |
| 2870 |
|
| } |
| 2871 |
|
| |
| 2872 |
519 |
| node_hv = (HV *)SvRV(*node_svp); |
| 2873 |
519 |
| kind_svp = hv_fetch(node_hv, "kind", 4, 0); |
| 2874 |
519 |
▶ | if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
519 |
0 |
519 |
| if (!kind_svp || !SvOK(*kind_svp) || !SvPOK(*kind_svp)) { |
0 |
519 |
519 |
|
| 2875 |
0 |
| continue; |
| 2876 |
|
| } |
| 2877 |
|
| |
| 2878 |
1038 |
▶ | if (!strEQ(SvPV_nolen(*kind_svp), "operation") |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strEQ(SvPV_nolen(*kind_svp), "operation") |
29 |
490 |
519 |
|
| 2879 |
58 |
▶ | && !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| && !strEQ(SvPV_nolen(*kind_svp), "fragment")) { |
1 |
28 |
29 |
|
| 2880 |
1 |
| SV **location_svp = hv_fetch(node_hv, "location", 8, 0); |
| 2881 |
2 |
| SV *message = newSVpvf( |
| 2882 |
|
| "The '%s' definition is not executable.", SvPV_nolen(*kind_svp) |
| 2883 |
|
| ); |
| 2884 |
2 |
▶ | av_push( |
Branch: 1 branch
| Branch | True | False | Total |
| av_push( |
1 |
0 |
1 |
|
| 2885 |
|
| errors_av, |
| 2886 |
|
| gql_validation_error(aTHX_ SvPV_nolen(message), location_svp ? *location_svp : NULL) |
| 2887 |
|
| ); |
| 2888 |
1 |
| SvREFCNT_dec(message); |
| 2889 |
1 |
| continue; |
| 2890 |
|
| } |
| 2891 |
|
| |
| 2892 |
1036 |
▶ | if (!strEQ(SvPV_nolen(*kind_svp), "operation")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strEQ(SvPV_nolen(*kind_svp), "operation")) { |
28 |
490 |
518 |
|
| 2893 |
28 |
| continue; |
| 2894 |
|
| } |
| 2895 |
|
| |
| 2896 |
490 |
| av_push(operations_av, newSVsv(*node_svp)); |
| 2897 |
|
| } |
| 2898 |
|
| |
| 2899 |
487 |
| fragments_hv = gql_validation_build_fragments_map(aTHX_ ast_av); |
| 2900 |
487 |
| gql_validation_push_operation_errors(aTHX_ errors_av, operations_av); |
| 2901 |
487 |
| gql_validation_push_fragment_name_errors(aTHX_ errors_av, ast_av); |
| 2902 |
487 |
| gql_validation_push_usage_errors(aTHX_ errors_av, ast_av, operations_av, fragments_hv); |
| 2903 |
487 |
| gql_validation_push_subscription_errors(aTHX_ operation_errors_av, operations_av, fragments_hv); |
| 2904 |
487 |
| gql_validation_push_fragment_cycle_errors(aTHX_ fragment_cycle_errors_av, fragments_hv); |
| 2905 |
487 |
| gql_validation_validate_fragments(aTHX_ errors_av, compiled_sv, fragments_hv); |
| 2906 |
487 |
| gql_validation_validate_document_directives(aTHX_ errors_av, compiled_sv, ast_av, fragments_hv); |
| 2907 |
|
| |
| 2908 |
|
| { |
| 2909 |
487 |
| I32 fragment_len = av_len(fragment_cycle_errors_av); |
| 2910 |
488 |
▶ | for (i = 0; i <= fragment_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= fragment_len; i++) { |
1 |
487 |
488 |
|
| 2911 |
1 |
| SV **err_svp = av_fetch(fragment_cycle_errors_av, i, 0); |
| 2912 |
1 |
▶ | if (err_svp && SvOK(*err_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (err_svp && SvOK(*err_svp)) { |
1 |
0 |
1 |
| if (err_svp && SvOK(*err_svp)) { |
1 |
0 |
1 |
|
| 2913 |
1 |
| av_push(errors_av, newSVsv(*err_svp)); |
| 2914 |
|
| } |
| 2915 |
|
| } |
| 2916 |
|
| } |
| 2917 |
|
| |
| 2918 |
977 |
▶ | for (i = 0; i <= av_len(operations_av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(operations_av); i++) { |
490 |
487 |
977 |
|
| 2919 |
490 |
| SV **operation_svp = av_fetch(operations_av, i, 0); |
| 2920 |
490 |
▶ | if (operation_svp && SvROK(*operation_svp) && SvTYPE(SvRV(*operation_svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (operation_svp && SvROK(*operation_svp) && SvTYPE(SvRV(*operation_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
| if (operation_svp && SvROK(*operation_svp) && SvTYPE(SvRV(*operation_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
| if (operation_svp && SvROK(*operation_svp) && SvTYPE(SvRV(*operation_svp)) == SVt_PVHV) { |
490 |
0 |
490 |
|
| 2921 |
490 |
| SV **seed_svp = av_fetch(operation_errors_av, i, 0); |
| 2922 |
490 |
▶ | if (seed_svp && SvROK(*seed_svp) && SvTYPE(SvRV(*seed_svp)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (seed_svp && SvROK(*seed_svp) && SvTYPE(SvRV(*seed_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
| if (seed_svp && SvROK(*seed_svp) && SvTYPE(SvRV(*seed_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
| if (seed_svp && SvROK(*seed_svp) && SvTYPE(SvRV(*seed_svp)) == SVt_PVAV) { |
490 |
0 |
490 |
|
| 2923 |
490 |
| AV *seed_av = (AV *)SvRV(*seed_svp); |
| 2924 |
|
| I32 j; |
| 2925 |
492 |
▶ | for (j = 0; j <= av_len(seed_av); j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j <= av_len(seed_av); j++) { |
2 |
490 |
492 |
|
| 2926 |
2 |
| SV **err_svp = av_fetch(seed_av, j, 0); |
| 2927 |
2 |
▶ | if (err_svp && SvOK(*err_svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (err_svp && SvOK(*err_svp)) { |
2 |
0 |
2 |
| if (err_svp && SvOK(*err_svp)) { |
2 |
0 |
2 |
|
| 2928 |
2 |
| av_push(errors_av, newSVsv(*err_svp)); |
| 2929 |
|
| } |
| 2930 |
|
| } |
| 2931 |
|
| } |
| 2932 |
490 |
| gql_validation_validate_operation(aTHX_ errors_av, schema, compiled_sv, (HV *)SvRV(*operation_svp), fragments_hv); |
| 2933 |
|
| } |
| 2934 |
|
| } |
| 2935 |
|
| |
| 2936 |
487 |
| ret = newRV_noinc((SV *)errors_av); |
| 2937 |
|
| |
| 2938 |
487 |
| SvREFCNT_dec((SV *)operations_av); |
| 2939 |
487 |
| SvREFCNT_dec((SV *)fragments_hv); |
| 2940 |
487 |
| SvREFCNT_dec((SV *)operation_errors_av); |
| 2941 |
487 |
| SvREFCNT_dec((SV *)fragment_cycle_errors_av); |
| 2942 |
487 |
| SvREFCNT_dec(ast_sv); |
| 2943 |
487 |
| SvREFCNT_dec(compiled_sv); |
| 2944 |
|
| |
| 2945 |
487 |
| return ret; |
| 2946 |
|
| } |