@goteborgco/open-api-js-client
Version:
Official JavaScript client for the Göteborg & Co GraphQL API
114 lines (113 loc) • 3.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoteborgCoApi = void 0;
const Client_1 = require("./client/Client");
const Guides_1 = require("./types/Guides");
const Events_1 = require("./types/Events");
const Places_1 = require("./types/Places");
const Search_1 = require("./types/Search");
const Taxonomies_1 = require("./types/Taxonomies");
const Taxonomy_1 = require("./types/Taxonomy");
const gql_1 = require("./utils/gql");
/**
* Main API client class for interacting with the Göteborg & Co GraphQL API
*
* This class provides access to all API endpoints through type-safe methods
* and supports raw GraphQL queries for advanced use cases.
*/
class GoteborgCoApi {
/**
* Initialize the API client
*
* @param apiUrl The base URL for the GraphQL API
* @param subscriptionKey Your API subscription key
*/
constructor(apiUrl, subscriptionKey) {
if (!apiUrl || !subscriptionKey) {
throw new Error('API URL and subscription key are required');
}
this.client = new Client_1.Client(apiUrl, subscriptionKey);
}
/**
* Execute a raw GraphQL query
*
* @param query The complete GraphQL query string
* @returns The query result
* @throws Error If the query is empty or execution fails
*/
async query(query) {
if (!query?.trim()) {
throw new Error('Query cannot be empty');
}
// Use the same gql tag function that other types use
const formattedQuery = (0, gql_1.gql) `${query}`;
return this.client.execute(formattedQuery);
}
/**
* Get the Guides API for accessing guide content
*
* @returns The Guides API instance
*/
guides() {
if (!this.guidesInstance) {
this.guidesInstance = new Guides_1.Guides(this.client);
}
return this.guidesInstance;
}
/**
* Get the Events API for accessing event content
*
* @returns The Events API instance
*/
events() {
if (!this.eventsInstance) {
this.eventsInstance = new Events_1.Events(this.client);
}
return this.eventsInstance;
}
/**
* Get the Places API for accessing place content
*
* @returns The Places API instance
*/
places() {
if (!this.placesInstance) {
this.placesInstance = new Places_1.Places(this.client);
}
return this.placesInstance;
}
/**
* Get the Search API for performing content searches
*
* @returns The Search API instance
*/
search() {
if (!this.searchInstance) {
this.searchInstance = new Search_1.Search(this.client);
}
return this.searchInstance;
}
/**
* Get the Taxonomies API for listing available taxonomies
*
* @returns The Taxonomies API instance
*/
taxonomies() {
if (!this.taxonomiesInstance) {
this.taxonomiesInstance = new Taxonomies_1.Taxonomies(this.client);
}
return this.taxonomiesInstance;
}
/**
* Get the Taxonomy API for querying specific taxonomies
*
* @returns The Taxonomy API instance
*/
taxonomy() {
if (!this.taxonomyInstance) {
this.taxonomyInstance = new Taxonomy_1.Taxonomy(this.client);
}
return this.taxonomyInstance;
}
}
exports.GoteborgCoApi = GoteborgCoApi;