UNPKG

@prismatic-io/embedded

Version:

Embed Prismatic's integration marketplace and workflow designer within your existing application.

24 lines (23 loc) 901 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.graphqlRequest = void 0; const prism_1 = require("./prism"); const graphqlRequest = async ({ query, variables, }) => { const accessToken = await (0, prism_1.getPrismAccessToken)(); const prismaticUrl = (0, prism_1.getPrismaticUrl)(); const response = await fetch(new URL("/api", prismaticUrl).toString(), { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json", Authorization: `Bearer ${accessToken}`, }, body: JSON.stringify({ query, variables }), }); const result = await response.json(); if (result.errors?.length) { throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(", ")}`); } return result.data; }; exports.graphqlRequest = graphqlRequest;