UNPKG

@obelisk/client

Version:

Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.

47 lines (46 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphQLEndpoint = void 0; const util_1 = require("../util"); const operators_1 = require("rxjs/operators"); /** * Endpoint class represents an Obelisk API Endpoint. * For now just get(), but will support all http methods. */ class GraphQLEndpoint { constructor(client) { this.client = client; this._url = this.client.options.host + '/api/graphql'; } /** * Absolute url to use in requests */ get url() { return this._url; } /** * Creates an Endpoint instance, the client is used to add tokens and uri is relative path starting after /api/<version>. * Examples are: <code>/things/my_thing/metrics/my_metric/events?from=1530089953000</code> or <code>/locations/my_loc/metrics/my_metric/stats/unit</code> */ static create(client) { return new GraphQLEndpoint(client); } /** * Execute a GraphQLQuery * @param request The GraphQL request */ execute(request) { util_1.Logger.debug(this._url, 'AJAX'); const req = { responseType: 'json', url: this._url, method: 'post', headers: { 'Content-Type': 'application/json', }, body: request }; return util_1.InternalUtils.authRequest(this.client, req).pipe(operators_1.pluck('response')); } } exports.GraphQLEndpoint = GraphQLEndpoint;