UNPKG

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