UNPKG

4.22 kBJavaScriptView Raw
1import{GraphQLError as r}from"graphql/error/GraphQLError.mjs";import{parse as e}from"graphql/language/parser.mjs";import{print as t}from"graphql/language/printer.mjs";import{Kind as n}from"graphql/language/kinds.mjs";import{make as o}from"wonka";function i(){return(i=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t,n=arguments[e];for(t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r}).apply(this,arguments)}function a(e){return"string"==typeof e?new r(e):"object"==typeof e&&e.message?new r(e.message,e.nodes,e.source,e.positions,e.path,e,e.extensions||{}):e}function s(){return this.message}var u=function(r){function e(e){var t=e.networkError,n=e.response,o=function(r,e){var t="";return void 0!==r?t="[Network] "+r.message:(void 0!==e&&e.forEach((function(r){t+="[GraphQL] "+r.message+"\n"})),t.trim())}(t,e=(e.graphQLErrors||[]).map(a));r.call(this,o),this.name="CombinedError",this.message=o,this.graphQLErrors=e,this.networkError=t,this.response=n}return r&&(e.__proto__=r),(e.prototype=Object.create(r&&r.prototype)).constructor=e,e.prototype.toString=s,e}(Error);function c(r,e){r|=0;for(var t=0,n=0|e.length;t<n;t++)r=(r<<5)+r+e.charCodeAt(t);return r}var f=new Set,p=new WeakMap;function l(r){if(null===r||f.has(r))return"null";if("object"!=typeof r)return JSON.stringify(r)||"";if(r.toJSON)return l(r.toJSON());if(Array.isArray(r)){for(var e="[",t=0,n=r.length;t<n;t++){0<t&&(e+=",");var o=l(r[t]);e+=0<o.length?o:"null"}return e+"]"}if(!(e=Object.keys(r).sort()).length&&r.constructor&&r.constructor!==Object)return e=p.get(r)||Math.random().toString(36).slice(2),p.set(r,e),'{"__key":"'+e+'"}';for(f.add(r),t="{",n=0,o=e.length;n<o;n++){var i=e[n],a=l(r[i]);a&&(1<t.length&&(t+=","),t+=l(i)+":"+a)}return f.delete(r),t+"}"}function h(r){return f.clear(),l(r)}function d(r){return c(5381,r.replace(/([\s,]|#[^\n\r]+)+/g," ").trim())>>>0}var m=Object.create(null);function v(r,e,t){return{operation:r,data:e.data,error:Array.isArray(e.errors)?new u({graphQLErrors:e.errors,response:t}):void 0,extensions:"object"==typeof e.extensions&&e.extensions||void 0}}function g(r,e,t){return{operation:r,data:void 0,error:new u({networkError:e,response:t}),extensions:void 0}}function y(r){var e=t(r.query);r:{for(var o=r.query,i=0,a=o.definitions.length;i<a;i++){var s=o.definitions[i];if(s.kind===n.OPERATION_DEFINITION&&s.name){o=s.name.value;break r}}o=void 0}return{query:e,operationName:o,variables:r.variables||void 0,extensions:void 0}}function b(r,e){var t=r.context.url;return"query"===r.kind&&r.context.preferGetMethod&&e?(r=[],e.operationName&&r.push("operationName="+encodeURIComponent(e.operationName)),e.query&&r.push("query="+encodeURIComponent(e.query.replace(/([\s,]|#[^\n\r]+)+/g," ").trim())),e.variables&&r.push("variables="+encodeURIComponent(h(e.variables))),e.extensions&&r.push("extensions="+encodeURIComponent(h(e.extensions))),t+"?"+r.join("&")):t}function x(r,e){var t="query"===r.kind&&!!r.context.preferGetMethod;return i({},r="function"==typeof r.context.fetchOptions?r.context.fetchOptions():r.context.fetchOptions||{},{body:!t&&e?JSON.stringify(e):void 0,method:t?"GET":"POST",headers:t?r.headers:i({},{"content-type":"application/json"},r.headers)})}function O(r,e,t){return o((function(n){var o=n.next,i=n.complete,a="undefined"!=typeof AbortController?new AbortController:null,s=!1;return Promise.resolve().then((function(){if(!s)return a&&(t.signal=a.signal),function(r,e,t){var n,o=!1;return(r.context.fetch||fetch)(e,t).then((function(r){return n=r,o=200>r.status||r.status>=("manual"===t.redirect?400:300),r.json()})).then((function(e){if(!("data"in e)&&!("errors"in e))throw Error("No Content");return v(r,e,n)})).catch((function(e){if("AbortError"!==e.name)return g(r,o?Error(n.statusText):e,n)}))}(r,e,t)})).then((function(r){s||(s=!0,r&&o(r),i())})),function(){s=!0,a&&a.abort()}}))}function k(r,n){if("string"==typeof r){var o=d(r);r=void 0!==m[o]?m[o]:e(r,{noLocation:!0})}else void 0!==r.__key?o=r.__key:(o=d(t(r)),r=void 0!==m[o]?m[o]:r);return m[o]=r,r.__key=o,{key:n?c(o,h(n))>>>0:o,query:r,variables:n||{}}}export{u as C,i as _,g as a,y as b,b as c,x as d,O as e,k as f,v as m,h as s};
2//# sourceMappingURL=7c059aaf.min.mjs.map