UNPKG

@urql/devtools

Version:
3 lines (2 loc) 3.55 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("graphql"),n=require("wonka");function t(){return(t=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var r=function(e){return{type:"debug-event",source:"exchange",data:t(t({},e),{source:"devtoolsExchange",timestamp:Date.now()})}},o=function(){var e=Error.stackTraceLimit;Error.stackTraceLimit=Infinity;var n=(new Error).stack||"";Error.stackTraceLimit=e;var t=/(useQuery|useMutation|useSubscription).*\n\s*at (\w+)/.exec(n);return null===t?"Unknown":t[2]},a={source:"exchange",type:"connection-init",version:"2.0.3"};function i(e){return window.postMessage(JSON.parse(JSON.stringify(e)),window.location.origin)}var s,u,c={"execute-query":function(t){var r=t.client;return function(t){var o,a=/(^|\W)+mutation\W/.test(t.query),i=r.createRequestOperation(a?"mutation":"query",{key:(o=JSON.stringify(t.query),function(e,n){e|=0;for(var t=0,r=0|n.length;t<r;t++)e=(e<<5)+e+n.charCodeAt(t);return e}(5381,o)>>>0),query:e.parse(t.query)},{meta:{source:"Devtools"}});n.pipe(r.executeRequestOperation(i),n.take(1),n.toPromise)}},"connection-init":function(e){var n=e.sendMessage;return function(){return n({type:"connection-acknowledge",source:"exchange",version:"2.0.3"})}}},d=(u=!(s="undefined"!=typeof navigator&&"ReactNative"===(null===navigator||void 0===navigator?void 0:navigator.product))&&"undefined"==typeof window,"production"===process.env.NODE_ENV||u?function(e){var t=e.forward;return function(e){return n.pipe(e,t)}}:function(e){var t=e.sendMessage,a=e.addMessageListener;function i(e){return t({type:"debug-event",source:"exchange",data:e})}return function(e){var s=e.client,u=e.forward;return a((function(e){"devtools"===e.source&&e.type in c&&c[e.type]({client:s,sendMessage:t})(e)})),s.subscribeToDebugTarget&&s.subscribeToDebugTarget(i),function(e){return n.pipe(e,n.tap(function(e){var n=e.sendMessage;return function(e){if("teardown"===e.kind){var t=r({type:"teardown",message:"The operation has been torn down",operation:e,data:void 0});return n(t)}var a=r({type:"execution",message:"The client has received an execute command.",operation:e,data:{sourceComponent:o()}});return n(a)}}({client:s,sendMessage:t})),u,n.tap(function(e){var n=e.sendMessage;return function(e){var t=e.operation,o=e.data,a=e.error;if(a){var i=r({type:"error",message:"The operation has returned a new error.",operation:t,data:{value:a}});return n(i)}var s=r({type:"update",message:"The operation has returned a new response.",operation:t,data:{value:o}});n(s)}}({client:s,sendMessage:t})))}}}(s?function(){var e,n,t=[];function r(){e.send(JSON.stringify(a))}function o(){n=n||setTimeout(u,500)}function i(){n=n||setTimeout(u,500)}function s(e){try{if(!e.data)return;t.forEach((function(n){return n(JSON.parse(e.data))}))}catch(e){console.warn(e)}}var u=function(){n=void 0,(e=new WebSocket("ws://localhost:7700")).onopen=r,e.onclose=o,e.onerror=i,e.onmessage=s};return u(),{addMessageListener:function(e){t=t.concat([e])},sendMessage:function(n){e.readyState===e.OPEN&&e.send(JSON.stringify(n))}}}():function(){var e=[];window.addEventListener("message",(function(n){var t=n.data;n.isTrusted&&(null==t?void 0:t.source)&&e.forEach((function(e){return e(t)}))}));var n=i;return n(a),{addMessageListener:function(n){return e=e.concat([n])},sendMessage:n}}()));exports.devtoolsExchange=d; //# sourceMappingURL=urql-devtools-exchange.min.js.map