| 5 | |
| 6 | // Query graphQL - note that the main client needs to be running to query the challenges |
| 7 | export async function queryGraphQL(query: string) { |
| 8 | const response = await fetch(GRAPHQL_ENDPOINT, { |
| 9 | method: 'POST', |
| 10 | headers: { |
| 11 | 'Content-Type': 'application/json' |
| 12 | }, |
| 13 | body: JSON.stringify({ query }) |
| 14 | }); |
| 15 | |
| 16 | const json = (await response.json()) as QueryResult; |
| 17 | |
| 18 | if (!json?.data?.allChallengeNode?.edges?.length) { |
| 19 | throw new Error( |
| 20 | 'Failed to find any challenges with GraphQL query. The client needs to be running' |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | return json; |
| 25 | } |
| 26 | |
| 27 | export async function fetchChallenges(language: 'javascript' | 'python') { |
| 28 | const query = ` |