class GraphQLClient {
  endpoint;
  headers;
  constructor(endpoint, headers = {}) {
    this.endpoint = endpoint;
    this.headers = headers;
  }
  async request(query, variables = {}) {
    const response = await fetch(this.endpoint, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        ...this.headers
      },
      body: JSON.stringify({ query, variables })
    });
    if (!response.ok && response.status !== 400) {
      throw new Error(`${response.status} ${response.statusText}`);
    }
    const body = await response.json();
    if (body.errors != null) {
      console.error(body);
      throw new Error("GraphQL response contains errors, check the console.");
    }
    return body.data;
  }
}
export {
  GraphQLClient
};
//# sourceMappingURL=client.js.map