MCPcopy Create free account
hub / github.com/doggybee/mcp-server-leetcode / executeQuery

Method executeQuery

src/services/leetcode-service.ts:28–53  ·  view source on GitHub ↗

* Execute a GraphQL query against the LeetCode API

(query: string, variables: Record<string, any> = {})

Source from the content-addressed store, hash-verified

26 * Execute a GraphQL query against the LeetCode API
27 */
28 private async executeQuery(query: string, variables: Record<string, any> = {}) {
29 try {
30 const response = await this.http.post(this.API_URL, {
31 query,
32 variables
33 });
34
35 if (response.data.errors) {
36 throw new Error(response.data.errors[0].message);
37 }
38
39 return response.data.data;
40 } catch (error: unknown) {
41 if (error && typeof error === 'object' && 'response' in error && error.response) {
42 const axiosError = error as { response: { status: number, data?: any } };
43 throw new Error(`API Error: ${axiosError.response.status} - ${axiosError.response.data?.message || JSON.stringify(axiosError.response.data)}`);
44 } else if (error && typeof error === 'object' && 'request' in error) {
45 throw new Error("Network Error: No response received from LeetCode API");
46 }
47 // 如果是其他类型的错误,转换为Error类型
48 if (error instanceof Error) {
49 throw error;
50 }
51 throw new Error(String(error));
52 }
53 }
54
55 /**
56 * Fetch user profile data

Callers 7

fetchUserProfileMethod · 0.95
fetchUserSubmissionsMethod · 0.95
fetchDailyChallengeMethod · 0.95
fetchProblemMethod · 0.95
searchProblemsMethod · 0.95
fetchContestDetailsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected