| | |
| | | const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql' |
| | | |
| | | // GraphQL请求函数 |
| | | async function graphqlRequest(query, variables = {}) { |
| | | const response = await fetch(GRAPHQL_ENDPOINT, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | body: JSON.stringify({ |
| | | query, |
| | | variables, |
| | | }), |
| | | }) |
| | | |
| | | if (!response.ok) { |
| | | throw new Error(`HTTP error! status: ${response.status}`) |
| | | } |
| | | |
| | | const result = await response.json() |
| | | |
| | | if (result.errors) { |
| | | throw new Error(result.errors[0].message) |
| | | } |
| | | |
| | | return result.data |
| | | } |
| | | import { graphqlRequest } from '../config/api.ts' |
| | | |
| | | // GraphQL 查询和变更 |
| | | const GET_CAROUSELS = ` |