Emit GRAPHQL_CALLS edge. Extract operation from first string arg if available. */
| 1905 | |
| 1906 | /* Emit GRAPHQL_CALLS edge. Extract operation from first string arg if available. */ |
| 1907 | static void emit_graphql_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call, |
| 1908 | const cbm_resolution_t *res) { |
| 1909 | const char *op = call->first_string_arg; |
| 1910 | if (!op || !op[0]) { |
| 1911 | op = call->callee_name; |
| 1912 | } |
| 1913 | /* Try to extract a query/mutation name from the operation string */ |
| 1914 | char op_name[CBM_SZ_256]; |
| 1915 | snprintf(op_name, sizeof(op_name), "%s", op); |
| 1916 | /* Trim leading whitespace and "query "/"mutation " prefix */ |
| 1917 | const char *p = op_name; |
| 1918 | while (*p == ' ' || *p == '\t' || *p == '\n') { |
| 1919 | p++; |
| 1920 | } |
| 1921 | if (strncmp(p, "query ", CBM_SZ_6) == 0) { |
| 1922 | p += CBM_SZ_6; |
| 1923 | } else if (strncmp(p, "mutation ", CBM_SZ_8) == 0) { |
| 1924 | p += CBM_SZ_8; |
| 1925 | } |
| 1926 | |
| 1927 | char route_qn[CBM_SZ_512]; |
| 1928 | snprintf(route_qn, sizeof(route_qn), "__graphql__%s", p); |
| 1929 | |
| 1930 | int64_t route_id = |
| 1931 | cbm_gbuf_upsert_node(gbuf, "Route", p, route_qn, "", 0, 0, "{\"source\":\"graphql\"}"); |
| 1932 | |
| 1933 | char esc_c[CBM_SZ_256]; |
| 1934 | cbm_json_escape(esc_c, sizeof(esc_c), call->callee_name); |
| 1935 | char props[CBM_SZ_1K]; |
| 1936 | snprintf(props, sizeof(props), "{\"callee\":\"%s\",\"operation\":\"%s\",\"confidence\":%.2f}", |
| 1937 | esc_c, p, res->confidence); |
| 1938 | cbm_gbuf_insert_edge(gbuf, source->id, route_id, "GRAPHQL_CALLS", props); |
| 1939 | } |
| 1940 | |
| 1941 | /* Emit TRPC_CALLS edge. Extract procedure path from callee chain. */ |
| 1942 | static void emit_trpc_edge(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call, |
no test coverage detected