UNPKG

@nhost/nhost-js

Version:

Nhost JavaScript SDK

2 lines 1.03 kB
import{c as e,s as n}from"./fetch-CaGArzje.js";var t=e=>{const n=e.loc?.source.body;if(!n)return"";if(!e.definitions.every((e=>e.loc)))return n;const t=/* @__PURE__ */new Set;return e.definitions.filter((e=>{if("FragmentDefinition"===e.kind&&"name"in e){const n=e.name.value;if(t.has(n))return!1;t.add(n)}return!0})).map((e=>n.slice(e.loc?.start,e.loc?.end))).join("\n\n")},r=(r,s=[])=>{let i=e(s);const a=async(e,t)=>{const s=new Headers(t?.headers);s.has("Content-Type")||s.set("Content-Type","application/json");const a=await i(`${r}`,{...t,method:"POST",headers:s,body:JSON.stringify(e)}),o=await a.text(),u=o?JSON.parse(o):{},c={body:u,status:a.status,headers:a.headers};if(u.errors)throw new n(u,a.status,a.headers);return c};return{request:function(e,n,r){if("object"==typeof e&&"kind"in e){const s=e.definitions[0];return a({query:t(e),variables:n,operationName:s&&"name"in s?s.name?.value:void 0},r)}return a(e,n)},url:r,pushChainFunction:n=>{s.push(n),i=e(s)}}};export{r as t}; //# sourceMappingURL=graphql-BMKt1R6b.js.map