UNPKG

@mysten/sui

Version:

Sui TypeScript API(Work in Progress)

74 lines (73 loc) 2.26 kB
var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; var _url, _queries, _headers, _fetch; import { print } from "graphql"; class SuiGraphQLRequestError extends Error { } class SuiGraphQLClient { constructor({ url, fetch: fetchFn = fetch, headers = {}, queries = {} }) { __privateAdd(this, _url, void 0); __privateAdd(this, _queries, void 0); __privateAdd(this, _headers, void 0); __privateAdd(this, _fetch, void 0); __privateSet(this, _url, url); __privateSet(this, _queries, queries); __privateSet(this, _headers, headers); __privateSet(this, _fetch, (...args) => fetchFn(...args)); } async query(options) { const res = await __privateGet(this, _fetch).call(this, __privateGet(this, _url), { method: "POST", headers: { "Content-Type": "application/json", ...__privateGet(this, _headers) }, body: JSON.stringify({ query: typeof options.query === "string" ? String(options.query) : print(options.query), variables: options.variables, extensions: options.extensions, operationName: options.operationName }) }); if (!res.ok) { throw new SuiGraphQLRequestError(`GraphQL request failed: ${res.statusText} (${res.status})`); } return await res.json(); } async execute(query, options) { return this.query({ ...options, query: __privateGet(this, _queries)[query] }); } } _url = new WeakMap(); _queries = new WeakMap(); _headers = new WeakMap(); _fetch = new WeakMap(); export { SuiGraphQLClient, SuiGraphQLRequestError }; //# sourceMappingURL=client.js.map