@urql/exchange-graphcache
Advanced tools
Comparing version 1.0.4-debug-trace to 1.1.0
@@ -11,2 +11,15 @@ # Changelog | ||
## [v1.1.0](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.3...v1.1.0) | ||
This is a minor release since it increases the peer dependency of `urql` to `>= 1.6.0`, due to the addition | ||
of the `stale` flag to partial responses and `cache-and-network` responses. This flag is useful to check | ||
whether more requests are being made in the background by `@urql/exchange-graphcache`. | ||
Additionally, this release adds a small stack to every error and warning that indicates where an | ||
error has occured. It lists out the query and all subsequent fragments it has been traversing | ||
so that errors and warnings can be traced more easily. | ||
- Add a query/fragment stack to all errors and warnings (see [#107](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/107)) | ||
- Add `stale: true` to all `cache-and-network` and partial responses (see [#108](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/108)) | ||
## [v1.0.3](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.2...v1.0.3) | ||
@@ -13,0 +26,0 @@ |
@@ -1287,6 +1287,3 @@ import { Kind, valueFromASTUntyped, buildClientSchema, isNullableType, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType } from "graphql"; | ||
var policy = getRequestPolicy(operation); | ||
if ("cache-and-network" === policy || "cache-first" === policy && "partial" === outcome) { | ||
client.reexecuteOperation(toRequestPolicy(operation, "network-only")); | ||
} | ||
return { | ||
var result = { | ||
operation: addCacheOutcome(operation, outcome), | ||
@@ -1297,2 +1294,7 @@ data: res.data, | ||
}; | ||
if ("cache-and-network" === policy || "cache-first" === policy && "partial" === outcome) { | ||
result.stale = !0; | ||
client.reexecuteOperation(toRequestPolicy(operation, "network-only")); | ||
} | ||
return result; | ||
} | ||
@@ -1299,0 +1301,0 @@ return function(ops$) { |
@@ -1,2 +0,2 @@ | ||
import{Kind as e,valueFromASTUntyped as t,buildClientSchema as r,isNullableType as n,isNonNullType as i,isListType as o,GraphQLObjectType as a,GraphQLInterfaceType as s,GraphQLUnionType as u}from"graphql";import{stringifyVariables as c,createRequest as l,formatDocument as f}from"urql";import{asMutable as v,make as d,clearOptimistic as p,get as y,setOptimistic as h,remove as m}from"pessimism";import{share as g,tap as b,map as k,filter as _,merge as O}from"wonka";function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var N=function(e){return e.name.value},x=function(e){return e.typeCondition.name.value},S=function(e){return void 0!==e.alias?e.alias.value:N(e)},F=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},R=function(e){var t=e.typeCondition;return void 0!==t?N(t):null},K=function(t){return t.kind===e.FIELD},q=function(t){return t.kind===e.INLINE_FRAGMENT},P=function(e,r){if(void 0===e.arguments||0===e.arguments.length)return null;for(var n=Object.create(null),i=0,o=0,a=e.arguments.length;o<a;o++){var s=e.arguments[o],u=t(s.value,r);null!=u&&(n[N(s)]=u,i++)}return i>0?n:null},T=function(e,r){if(void 0===e.variableDefinitions)return{};var n=r||{};return e.variableDefinitions.reduce((function(e,r){var i=N(r.variable),o=n[i];if(void 0===o){if(void 0===r.defaultValue)return e;o=t(r.defaultValue,n)}return e[i]=o,e}),Object.create(null))},j=function(e,t,r){if(!e){var n=new Error((t||"Minfied Error #"+r+"\n")+"\nhttps://github.com/FormidableLabs/urql-exchange-graphcache/blob/master/docs/help.md#"+r);throw n.name="Graphcache Error",n}},A=function(t){return t.kind===e.FRAGMENT_DEFINITION};function E(t){return t.kind===e.OPERATION_DEFINITION}var L=function(e){var t=e.definitions.find(E);return j(!!t,"",1),t};function I(e,t){return e[N(t)]=t,e}var M=function(e){return e.definitions.filter(A).reduce(I,{})},Q=function(e,r){var n=e.directives;if(void 0===n)return!0;for(var i=0,o=n.length;i<o;i++){var a=n[i],s=N(a),u="include"===s;if(u||"skip"===s){var c=a.arguments?a.arguments[0]:null;if(c&&"if"===N(c)){var l=t(c.value,r);if("boolean"==typeof l||null===l)return u?!!l:!l}}}return!0},C=function(e,t){return t?e+"("+c(t)+")":e},D=function(e,t){return e+"."+t},V=function(e,t,r,n){return!(!t||t!==R(e)&&F(e).some((function(e){if(!K(e))return!1;var t=C(N(e),P(e,n.variables));return!n.store.hasField(D(r,t))})))},G=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};G.prototype.next=function(){for(;0!==this.indexStack.length;){var e=this.indexStack[this.indexStack.length-1]++,t=this.selectionStack[this.selectionStack.length-1];if(e>=t.length)this.indexStack.pop(),this.selectionStack.pop();else{var r=t[e];if(Q(r,this.context.variables)){if(K(r)){if("__typename"===N(r))continue;return r}var n=q(r)?r:this.context.fragments[N(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(R(n),this.typename):V(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(F(n)))}}}};var W=function(e){return Array.isArray(e)?e.some(W):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},z=function(e,t,r){re(0);var n=B(e,t,r);return ne(),n},B=function(e,t,r){var n=L(t.query),i={dependencies:ie()},o=F(n),a=e.getRootKey(n.operation),s={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates};return a===s.store.getRootKey("query")?U(s,a,o,r):Y(s,a,o,r),i},H=function(e,t,r){re(r);var n=L(t.query),i={dependencies:ie()},o=e.getRootKey("mutation"),a=e.getRootKey(n.operation);j(a===o,"",10);for(var s,u={parentTypeName:o,parentKey:o,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates,optimistic:!0},c=Object.create(null),l=new G(a,a,F(n),u);void 0!==(s=l.next());)if(void 0!==s.selectionSet){var f=N(s),v=u.store.optimisticMutations[f];if(void 0!==v){u.fieldName=f;var d=P(s,u.variables),p=v(d||Object.create(null),u.store,u);W(p)||Z(u,p,F(s)),c[f]=p;var y=u.store.updates[o][f];void 0!==y&&y(c,d||Object.create(null),u.store,u)}}return ne(),i},J=function(e,t,r,n){var i=M(t),o=i[Object.keys(i)[0]];if(void 0!==o){var a=x(o),s=w({__typename:a},r),u=e.keyOfEntity(s);if(u){var c={parentTypeName:a,parentKey:u,parentFieldKey:"",fieldName:"",variables:n||{},fragments:i,result:{dependencies:ie()},store:e,schemaPredicates:e.schemaPredicates};U(c,u,F(o),s)}}},U=function(e,t,r,n){var i=e.store,o=t===e.store.getRootKey("query"),a=n.__typename;o||oe(t),i.writeField(o?t:a,t,"__typename");for(var s,u=new G(a,t,r,e);void 0!==(s=u.next());){var c=N(s),l=P(s,e.variables),f=D(t,C(c,l)),v=n[S(s)];if(o&&oe(f),void 0===s.selectionSet)i.writeRecord(v,f);else if(W(v))i.writeRecord(v,f);else{var d=X(e,f,F(s),v);i.writeConnection(D(t,c),f,l),i.writeLink(d,f),i.removeRecord(f)}}},X=function(e,t,r,n){if(Array.isArray(n)){for(var i=new Array(n.length),o=0,a=n.length;o<a;o++){var s=n[o],u=D(t,""+o),c=X(e,u,r,s);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t,v=n.__typename;return void 0===e.store.keys[n.__typename]&&null===l&&!v.endsWith("Connection")&&v.endsWith("Edge"),U(e,f,r,n),f},Y=function(e,t,r,n){for(var i,o=t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription"),a=new G(t,t,r,e);void 0!==(i=a.next());){var s=N(i),u=P(i,e.variables),c=n[S(i)];if(void 0===i.selectionSet||null===c||W(c)||Z(e,c,F(i)),o){e.parentTypeName=t,e.parentKey=t,e.parentFieldKey=D(t,C(s,u)),e.fieldName=s;var l=e.store.updates[t][s];void 0!==l&&l(n,u||Object.create(null),e.store,e)}}},Z=function(e,t,r){if(Array.isArray(t)){for(var n=new Array(t.length),i=0,o=t.length;i<o;i++)n[i]=Z(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?U(e,a,r,t):Y(e,t.__typename,r,t)}},$=function(e,t,r){var n,i=e.store,o="Query"===t;if(o)n=t;else{if(oe(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(D(t,C("__typename")))}for(var a,s=new G(n,t,r,e);void 0!==(a=s.next());){var u=N(a),c=D(t,C(u,P(a,e.variables)));if(o&&oe(c),void 0===a.selectionSet)i.removeRecord(c);else{var l=F(a),f=i.getLink(c);if(i.removeLink(c),void 0===f)void 0!==i.getRecord(c)&&i.removeRecord(c);else if(Array.isArray(f))for(var v=0,d=f.length;v<d;v++){var p=f[v];null!==p&&$(e,p,l)}else null!==f&&$(e,f,l)}}},ee={current:null},te={current:null},re=function(e){ee.current=new Set,te.current=e},ne=function(){ee.current=null,te.current=null},ie=function(){return j(null!==(e=ee).current,"",2),e.current;var e},oe=function(e){ee.current.add(e)},ae=function(e,t,r){return h(e,t,r,te.current||0)},se=function(e,t){var r=te.current||0;return r?h(e,t,void 0,r):m(e,t)},ue=function(e,t,r,n,i){var o;if(this.records=v(d()),this.connections=v(d()),this.links=v(d()),this.resolvers=t||{},this.optimisticMutations=n||{},this.keys=i||{},this.schemaPredicates=e,this.updates={Mutation:r&&r.Mutation||{},Subscription:r&&r.Subscription||{}},e){var a=e.schema,s=a.getQueryType(),u=a.getMutationType(),c=a.getSubscriptionType(),l=s?s.name:"Query",f=u?u.name:"Mutation",p=c?c.name:"Subscription";this.rootFields={query:l,mutation:f,subscription:p},this.rootNames=((o={})[l]="query",o[f]="mutation",o[p]="subscription",o)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};ue.prototype.getRootKey=function(e){return this.rootFields[e]},ue.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;return r?this.rootNames[r]?this.rootNames[r]:(this.keys[r]?t=this.keys[r](e):null!=n?t=""+n:null!=i&&(t=""+i),t?r+":"+t:null):null},ue.prototype.clearOptimistic=function(e){this.records=p(this.records,e),this.connections=p(this.connections,e),this.links=p(this.links,e)},ue.prototype.getRecord=function(e){return y(this.records,e)},ue.prototype.removeRecord=function(e){return this.records=se(this.records,e)},ue.prototype.writeRecord=function(e,t){return this.records=ae(this.records,t,e)},ue.prototype.getField=function(e,t,r){return this.getRecord(D(e,C(t,r)))},ue.prototype.writeField=function(e,t,r,n){return this.records=ae(this.records,D(t,C(r,n)),e)},ue.prototype.getLink=function(e){return y(this.links,e)},ue.prototype.removeLink=function(e){return this.links=se(this.links,e)},ue.prototype.writeLink=function(e,t){return this.links=ae(this.links,t,e)},ue.prototype.writeConnection=function(e,t,r){if(void 0!==this.getLink(t)||null===r)return this.connections;var n=y(this.connections,e),i=[r,t];if(void 0===n)n=[i];else{for(var o=0,a=n.length;o<a;o++)if(n[o][1]===t)return this.connections;(n=n.slice()).push(i)}return this.connections=ae(this.connections,e,n)},ue.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},ue.prototype.resolve=function(e,t,r){if(null===e)return null;if("string"==typeof e)return oe(e),this.resolveValueOrLink(D(e,C(t,r)));var n=this.keyOfEntity(e);return null===n?null:(oe(n),this.resolveValueOrLink(D(n,C(t,r))))},ue.prototype.resolveConnections=function(e,t){var r;if("string"==typeof e)r=y(this.connections,D(e,t));else if(null!==e){var n=this.keyOfEntity(e);null!==n&&(oe(n),r=y(this.connections,D(n,t)))}return void 0!==r?r:[]},ue.prototype.invalidateQuery=function(e,t){!function(e,t){re(0);var r=L(t.query),n={variables:T(r,t.variables),fragments:M(t.query),store:e,schemaPredicates:e.schemaPredicates};$(n,n.store.getRootKey("query"),F(r)),ne()}(this,l(e,t))},ue.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},ue.prototype.updateQuery=function(e,t){var r=l(e.query,e.variables),n=t(this.readQuery(r));null!==n&&B(this,r,n)},ue.prototype.readQuery=function(e){return le(this,l(e.query,e.variables)).data},ue.prototype.readFragment=function(e,t,r){return de(this,e,t,r)},ue.prototype.writeFragment=function(e,t,r){J(this,e,t,r)};var ce=function(e,t,r){re(0);var n=le(e,t,r);return ne(),n},le=function(e,t,r){var n=L(t.query),i=e.getRootKey(n.operation),o=F(n),a={parentTypeName:i,parentKey:i,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},s=r||Object.create(null);return s=i!==a.store.getRootKey("query")?fe(a,i,o,s):pe(a,i,o,s),{dependencies:ie(),partial:void 0!==s&&a.partial,data:void 0===s?null:s}},fe=function(e,t,r,n){if("string"!=typeof n.__typename)return n;var i=Object.create(null);i.__typename=n.__typename;for(var o,a=new G(t,t,r,e);void 0!==(o=a.next());){var s=S(o),u=n[s];i[s]=void 0===o.selectionSet||null===u||W(u)?u:ve(e,F(o),u)}return i},ve=function(e,t,r){if(Array.isArray(r)){for(var n=new Array(r.length),i=0,o=r.length;i<o;i++)n[i]=ve(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var s=pe(e,a,t,Object.create(null));return void 0===s?null:s}return fe(e,r.__typename,t,r)},de=function(e,t,r,n){var i=M(t),o=i[Object.keys(i)[0]];if(void 0===o)return null;var a=x(o);"string"==typeof r||r.__typename||(r.__typename=a);var s="string"!=typeof r?e.keyOfEntity(w({__typename:a},r)):r;return s&&pe({parentTypeName:a,parentKey:s,parentFieldKey:"",fieldName:"",variables:n||{},fragments:i,partial:!1,store:e,schemaPredicates:e.schemaPredicates},s,F(o),Object.create(null))||null},pe=function(e,t,r,n){var i=e.store,o=e.schemaPredicates,a=t===i.getRootKey("query");a||oe(t);var s=a?t:i.getField(t,"__typename");if("string"==typeof s){n.__typename=s;for(var u,c=new G(s,t,r,e),l=!1,f=!1;void 0!==(u=c.next());){var v=N(u),d=P(u,e.variables),p=S(u),y=D(t,C(v,d)),h=i.getRecord(y);a&&oe(y);var m=void 0,g=i.resolvers[s];if(void 0!==g&&"function"==typeof g[v]){e.parentTypeName=s,e.parentKey=t,e.parentFieldKey=y,e.fieldName=v,void 0!==h&&(n[p]=h);var b=g[v](n,d||Object.create(null),i,e);m=void 0!==u.selectionSet?ye(e,s,v,y,F(u),n[p]||Object.create(null),b):void 0===b&&void 0===o?null:b}else if(void 0===u.selectionSet)m=h;else{var k=i.getLink(y);void 0!==k?m=he(e,k,s,v,F(u),n[p]):"object"==typeof h&&null!==h&&(m=h)}if(void 0===m&&void 0!==o&&o.isFieldNullable(s,v))f=!0,n[p]=null;else{if(void 0===m)return;l=!0,n[p]=m}}return f&&(e.partial=!0),a&&f&&!l?void 0:n}},ye=function(e,t,r,n,i,o,a){if(Array.isArray(a)){for(var s=e.schemaPredicates,u=void 0===s||s.isListNullable(t,r),c=new Array(a.length),l=0,f=a.length;l<f;l++){var v=ye(e,t,r,D(n,""+l),i,void 0!==o?o[l]:void 0,a[l]);if(void 0===v&&!u)return;c[l]=void 0!==v?v:null}return c}if(null==a)return null;if(me(a)){var d=void 0===o?Object.create(null):o;return"string"==typeof a?pe(e,a,i,d):function(e,t,r,n,i){var o=e.store,a=e.schemaPredicates,s=o.keyOfEntity(i)||t;oe(s);var u=i.__typename,c=o.getField(s,"__typename")||u;if(!("string"!=typeof c||u&&c!==u)){n.__typename=c;for(var l,f=new G(c,s,r,e),v=!1,d=!1;void 0!==(l=f.next());){var p=N(l),y=S(l),h=D(s,C(p,P(l,e.variables))),m=o.getRecord(h),g=i[p],b=void 0;if(void 0!==g&&void 0===l.selectionSet)b=g;else if(void 0===l.selectionSet)b=m;else if(void 0!==g)b=ye(e,c,p,h,F(l),n[y],g);else{var k=o.getLink(h);void 0!==k?b=he(e,k,c,p,F(l),n[y]):"object"==typeof m&&null!==m&&(b=m)}if(void 0===b&&void 0!==a&&a.isFieldNullable(c,p))d=!0,n[y]=null;else{if(void 0===b)return;v=!0,n[y]=b}}return d&&(e.partial=!0),v?n:void 0}}(e,n,i,d,a)}},he=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,s=void 0!==a&&a.isListNullable(r,n),u=new Array(t.length),c=0,l=t.length;c<l;c++){var f=he(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!s)return;u[c]=void 0!==f?f:null}return u}return null===t?null:pe(e,t,i,void 0===o?Object.create(null):o)},me=function(e){return"string"==typeof e||"object"==typeof e&&"string"==typeof e.__typename},ge=function(e){this.schema=r(e)};ge.prototype.isFieldNullable=function(e,t){var r=be(this.schema,e,t);return void 0!==r&&n(r.type)},ge.prototype.isListNullable=function(e,t){var r=be(this.schema,e,t);if(void 0===r)return!1;var a=i(r.type)?r.type.ofType:r.type;return o(a)&&n(a.ofType)},ge.prototype.isFieldAvailableOnType=function(e,t){return!!be(this.schema,e,t)},ge.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e);_e(r);var n=this.schema.getType(t);return ke(n),this.schema.isPossibleType(r,n)};var be=function(e,t,r){var n=e.getType(t);ke(n);var i=n.getFields()[r];if(void 0!==i)return i},ke=function(e,t){j(e instanceof a,"",3)},_e=function(e,t){j(e instanceof s||e instanceof u,"",5)},Oe=function(e,t){return w(w({},e),{context:w(w({},e.context),{meta:w(w({},e.context.meta),{cacheOutcome:t})})})},we=function(e){return w(w({},e),{query:f(e.query)})},Ne=function(e){return e.context.requestPolicy},xe=function(e){return"query"===e.operationName},Se=function(e){return xe(e)&&"network-only"!==Ne(e)},Fe=function(e,t){return w(w({},e),{context:w(w({},e.context),{requestPolicy:t})})};function Re(e){return Se(e)}function Ke(e){return Oe(e.operation,e.outcome)}function qe(e){return"miss"===e.outcome}function Pe(e){return"miss"!==e.outcome}function Te(e){return!Se(e)}var je=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new ue(e.schema?new ge(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),o=new Set,a=new Map,s=Object.create(null),u=function(e,t){void 0!==t&&t.forEach((function(t){var r=s[t];if(void 0!==r){s[t]=[];for(var n=0,i=r.length;n<i;n++)e.add(r[n])}}))},c=function(e,t){t.forEach((function(t){if(t!==e.key){var r=a.get(t);void 0!==r&&(a.delete(t),n.reexecuteOperation(Fe(r,"cache-first")))}}))},l=function(e){if(function(e){return"mutation"===e.operationName}(a=e)&&"network-only"!==Ne(a)){var t=e.key,r=H(i,e,t).dependencies;if(0!==r.size){o.add(t);var n=new Set;u(n,r),c(e,n)}}var a},f=function(e,t){t.forEach((function(t){(s[t]||(s[t]=[])).push(e.key),a.has(e.key)||a.set(e.key,"network-only"===Ne(e)?Fe(e,"cache-and-network"):e)}))},v=function(e){var t,r=ce(i,e),n=r.data,o=r.partial;return null===n?t="miss":(f(e,r.dependencies),t=o&&"cache-only"!==Ne(e)?"partial":"hit"),{outcome:t,operation:e,data:n}},d=function(e){var t,r,n=e.operation,a=e.error,s=e.extensions,l=xe(n),v=e.data,d=n.key;if(o.has(d)&&(o.delete(d),i.clearOptimistic(d)),null!=v)if(t=z(i,n,v).dependencies,l){var p=ce(i,n);v=p.data,r=p.dependencies}else v=ce(i,n,v).data;var y=new Set;return u(y,t),l&&u(y,r),c(e.operation,y),l&&void 0!==r&&f(e.operation,r),{data:v,error:a,extensions:s,operation:n}};function p(e){var t=e.operation,r=e.outcome,i=Ne(t);return("cache-and-network"===i||"cache-first"===i&&"partial"===r)&&n.reexecuteOperation(Fe(t,"network-only")),{operation:Oe(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=g(b(l)(k(we)(e))),n=g(k(v)(_(Re)(t))),i=k(Ke)(_(qe)(n)),o=k(p)(_(Pe)(n)),a=k(d)(r(O([_(Te)(t),i])));return O([a,o])}}};export{ue as Store,je as cacheExchange,ce as query,le as read,z as write,J as writeFragment,H as writeOptimistic}; | ||
import{Kind as e,valueFromASTUntyped as t,buildClientSchema as r,isNullableType as n,isNonNullType as i,isListType as o,GraphQLObjectType as a,GraphQLInterfaceType as s,GraphQLUnionType as u}from"graphql";import{stringifyVariables as c,createRequest as l,formatDocument as f}from"urql";import{asMutable as v,make as d,clearOptimistic as p,get as y,setOptimistic as h,remove as m}from"pessimism";import{share as g,tap as b,map as k,filter as _,merge as O}from"wonka";function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var N=function(e){return e.name.value},x=function(e){return e.typeCondition.name.value},S=function(e){return void 0!==e.alias?e.alias.value:N(e)},F=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},R=function(e){var t=e.typeCondition;return void 0!==t?N(t):null},K=function(t){return t.kind===e.FIELD},q=function(t){return t.kind===e.INLINE_FRAGMENT},P=function(e,r){if(void 0===e.arguments||0===e.arguments.length)return null;for(var n=Object.create(null),i=0,o=0,a=e.arguments.length;o<a;o++){var s=e.arguments[o],u=t(s.value,r);null!=u&&(n[N(s)]=u,i++)}return i>0?n:null},T=function(e,r){if(void 0===e.variableDefinitions)return{};var n=r||{};return e.variableDefinitions.reduce((function(e,r){var i=N(r.variable),o=n[i];if(void 0===o){if(void 0===r.defaultValue)return e;o=t(r.defaultValue,n)}return e[i]=o,e}),Object.create(null))},j=function(e,t,r){if(!e){var n=new Error((t||"Minfied Error #"+r+"\n")+"\nhttps://github.com/FormidableLabs/urql-exchange-graphcache/blob/master/docs/help.md#"+r);throw n.name="Graphcache Error",n}},A=function(t){return t.kind===e.FRAGMENT_DEFINITION};function E(t){return t.kind===e.OPERATION_DEFINITION}var L=function(e){var t=e.definitions.find(E);return j(!!t,"",1),t};function I(e,t){return e[N(t)]=t,e}var M=function(e){return e.definitions.filter(A).reduce(I,{})},Q=function(e,r){var n=e.directives;if(void 0===n)return!0;for(var i=0,o=n.length;i<o;i++){var a=n[i],s=N(a),u="include"===s;if(u||"skip"===s){var c=a.arguments?a.arguments[0]:null;if(c&&"if"===N(c)){var l=t(c.value,r);if("boolean"==typeof l||null===l)return u?!!l:!l}}}return!0},C=function(e,t){return t?e+"("+c(t)+")":e},D=function(e,t){return e+"."+t},V=function(e,t,r,n){return!(!t||t!==R(e)&&F(e).some((function(e){if(!K(e))return!1;var t=C(N(e),P(e,n.variables));return!n.store.hasField(D(r,t))})))},G=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};G.prototype.next=function(){for(;0!==this.indexStack.length;){var e=this.indexStack[this.indexStack.length-1]++,t=this.selectionStack[this.selectionStack.length-1];if(e>=t.length)this.indexStack.pop(),this.selectionStack.pop();else{var r=t[e];if(Q(r,this.context.variables)){if(K(r)){if("__typename"===N(r))continue;return r}var n=q(r)?r:this.context.fragments[N(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(R(n),this.typename):V(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(F(n)))}}}};var W=function(e){return Array.isArray(e)?e.some(W):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},z=function(e,t,r){re(0);var n=B(e,t,r);return ne(),n},B=function(e,t,r){var n=L(t.query),i={dependencies:ie()},o=F(n),a=e.getRootKey(n.operation),s={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates};return a===s.store.getRootKey("query")?U(s,a,o,r):Y(s,a,o,r),i},H=function(e,t,r){re(r);var n=L(t.query),i={dependencies:ie()},o=e.getRootKey("mutation"),a=e.getRootKey(n.operation);j(a===o,"",10);for(var s,u={parentTypeName:o,parentKey:o,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates,optimistic:!0},c=Object.create(null),l=new G(a,a,F(n),u);void 0!==(s=l.next());)if(void 0!==s.selectionSet){var f=N(s),v=u.store.optimisticMutations[f];if(void 0!==v){u.fieldName=f;var d=P(s,u.variables),p=v(d||Object.create(null),u.store,u);W(p)||Z(u,p,F(s)),c[f]=p;var y=u.store.updates[o][f];void 0!==y&&y(c,d||Object.create(null),u.store,u)}}return ne(),i},J=function(e,t,r,n){var i=M(t),o=i[Object.keys(i)[0]];if(void 0!==o){var a=x(o),s=w({__typename:a},r),u=e.keyOfEntity(s);if(u){var c={parentTypeName:a,parentKey:u,parentFieldKey:"",fieldName:"",variables:n||{},fragments:i,result:{dependencies:ie()},store:e,schemaPredicates:e.schemaPredicates};U(c,u,F(o),s)}}},U=function(e,t,r,n){var i=e.store,o=t===e.store.getRootKey("query"),a=n.__typename;o||oe(t),i.writeField(o?t:a,t,"__typename");for(var s,u=new G(a,t,r,e);void 0!==(s=u.next());){var c=N(s),l=P(s,e.variables),f=D(t,C(c,l)),v=n[S(s)];if(o&&oe(f),void 0===s.selectionSet)i.writeRecord(v,f);else if(W(v))i.writeRecord(v,f);else{var d=X(e,f,F(s),v);i.writeConnection(D(t,c),f,l),i.writeLink(d,f),i.removeRecord(f)}}},X=function(e,t,r,n){if(Array.isArray(n)){for(var i=new Array(n.length),o=0,a=n.length;o<a;o++){var s=n[o],u=D(t,""+o),c=X(e,u,r,s);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t,v=n.__typename;return void 0===e.store.keys[n.__typename]&&null===l&&!v.endsWith("Connection")&&v.endsWith("Edge"),U(e,f,r,n),f},Y=function(e,t,r,n){for(var i,o=t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription"),a=new G(t,t,r,e);void 0!==(i=a.next());){var s=N(i),u=P(i,e.variables),c=n[S(i)];if(void 0===i.selectionSet||null===c||W(c)||Z(e,c,F(i)),o){e.parentTypeName=t,e.parentKey=t,e.parentFieldKey=D(t,C(s,u)),e.fieldName=s;var l=e.store.updates[t][s];void 0!==l&&l(n,u||Object.create(null),e.store,e)}}},Z=function(e,t,r){if(Array.isArray(t)){for(var n=new Array(t.length),i=0,o=t.length;i<o;i++)n[i]=Z(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?U(e,a,r,t):Y(e,t.__typename,r,t)}},$=function(e,t,r){var n,i=e.store,o="Query"===t;if(o)n=t;else{if(oe(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(D(t,C("__typename")))}for(var a,s=new G(n,t,r,e);void 0!==(a=s.next());){var u=N(a),c=D(t,C(u,P(a,e.variables)));if(o&&oe(c),void 0===a.selectionSet)i.removeRecord(c);else{var l=F(a),f=i.getLink(c);if(i.removeLink(c),void 0===f)void 0!==i.getRecord(c)&&i.removeRecord(c);else if(Array.isArray(f))for(var v=0,d=f.length;v<d;v++){var p=f[v];null!==p&&$(e,p,l)}else null!==f&&$(e,f,l)}}},ee={current:null},te={current:null},re=function(e){ee.current=new Set,te.current=e},ne=function(){ee.current=null,te.current=null},ie=function(){return j(null!==(e=ee).current,"",2),e.current;var e},oe=function(e){ee.current.add(e)},ae=function(e,t,r){return h(e,t,r,te.current||0)},se=function(e,t){var r=te.current||0;return r?h(e,t,void 0,r):m(e,t)},ue=function(e,t,r,n,i){var o;if(this.records=v(d()),this.connections=v(d()),this.links=v(d()),this.resolvers=t||{},this.optimisticMutations=n||{},this.keys=i||{},this.schemaPredicates=e,this.updates={Mutation:r&&r.Mutation||{},Subscription:r&&r.Subscription||{}},e){var a=e.schema,s=a.getQueryType(),u=a.getMutationType(),c=a.getSubscriptionType(),l=s?s.name:"Query",f=u?u.name:"Mutation",p=c?c.name:"Subscription";this.rootFields={query:l,mutation:f,subscription:p},this.rootNames=((o={})[l]="query",o[f]="mutation",o[p]="subscription",o)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};ue.prototype.getRootKey=function(e){return this.rootFields[e]},ue.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;return r?this.rootNames[r]?this.rootNames[r]:(this.keys[r]?t=this.keys[r](e):null!=n?t=""+n:null!=i&&(t=""+i),t?r+":"+t:null):null},ue.prototype.clearOptimistic=function(e){this.records=p(this.records,e),this.connections=p(this.connections,e),this.links=p(this.links,e)},ue.prototype.getRecord=function(e){return y(this.records,e)},ue.prototype.removeRecord=function(e){return this.records=se(this.records,e)},ue.prototype.writeRecord=function(e,t){return this.records=ae(this.records,t,e)},ue.prototype.getField=function(e,t,r){return this.getRecord(D(e,C(t,r)))},ue.prototype.writeField=function(e,t,r,n){return this.records=ae(this.records,D(t,C(r,n)),e)},ue.prototype.getLink=function(e){return y(this.links,e)},ue.prototype.removeLink=function(e){return this.links=se(this.links,e)},ue.prototype.writeLink=function(e,t){return this.links=ae(this.links,t,e)},ue.prototype.writeConnection=function(e,t,r){if(void 0!==this.getLink(t)||null===r)return this.connections;var n=y(this.connections,e),i=[r,t];if(void 0===n)n=[i];else{for(var o=0,a=n.length;o<a;o++)if(n[o][1]===t)return this.connections;(n=n.slice()).push(i)}return this.connections=ae(this.connections,e,n)},ue.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},ue.prototype.resolve=function(e,t,r){if(null===e)return null;if("string"==typeof e)return oe(e),this.resolveValueOrLink(D(e,C(t,r)));var n=this.keyOfEntity(e);return null===n?null:(oe(n),this.resolveValueOrLink(D(n,C(t,r))))},ue.prototype.resolveConnections=function(e,t){var r;if("string"==typeof e)r=y(this.connections,D(e,t));else if(null!==e){var n=this.keyOfEntity(e);null!==n&&(oe(n),r=y(this.connections,D(n,t)))}return void 0!==r?r:[]},ue.prototype.invalidateQuery=function(e,t){!function(e,t){re(0);var r=L(t.query),n={variables:T(r,t.variables),fragments:M(t.query),store:e,schemaPredicates:e.schemaPredicates};$(n,n.store.getRootKey("query"),F(r)),ne()}(this,l(e,t))},ue.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},ue.prototype.updateQuery=function(e,t){var r=l(e.query,e.variables),n=t(this.readQuery(r));null!==n&&B(this,r,n)},ue.prototype.readQuery=function(e){return le(this,l(e.query,e.variables)).data},ue.prototype.readFragment=function(e,t,r){return de(this,e,t,r)},ue.prototype.writeFragment=function(e,t,r){J(this,e,t,r)};var ce=function(e,t,r){re(0);var n=le(e,t,r);return ne(),n},le=function(e,t,r){var n=L(t.query),i=e.getRootKey(n.operation),o=F(n),a={parentTypeName:i,parentKey:i,parentFieldKey:"",fieldName:"",variables:T(n,t.variables),fragments:M(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},s=r||Object.create(null);return s=i!==a.store.getRootKey("query")?fe(a,i,o,s):pe(a,i,o,s),{dependencies:ie(),partial:void 0!==s&&a.partial,data:void 0===s?null:s}},fe=function(e,t,r,n){if("string"!=typeof n.__typename)return n;var i=Object.create(null);i.__typename=n.__typename;for(var o,a=new G(t,t,r,e);void 0!==(o=a.next());){var s=S(o),u=n[s];i[s]=void 0===o.selectionSet||null===u||W(u)?u:ve(e,F(o),u)}return i},ve=function(e,t,r){if(Array.isArray(r)){for(var n=new Array(r.length),i=0,o=r.length;i<o;i++)n[i]=ve(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var s=pe(e,a,t,Object.create(null));return void 0===s?null:s}return fe(e,r.__typename,t,r)},de=function(e,t,r,n){var i=M(t),o=i[Object.keys(i)[0]];if(void 0===o)return null;var a=x(o);"string"==typeof r||r.__typename||(r.__typename=a);var s="string"!=typeof r?e.keyOfEntity(w({__typename:a},r)):r;return s&&pe({parentTypeName:a,parentKey:s,parentFieldKey:"",fieldName:"",variables:n||{},fragments:i,partial:!1,store:e,schemaPredicates:e.schemaPredicates},s,F(o),Object.create(null))||null},pe=function(e,t,r,n){var i=e.store,o=e.schemaPredicates,a=t===i.getRootKey("query");a||oe(t);var s=a?t:i.getField(t,"__typename");if("string"==typeof s){n.__typename=s;for(var u,c=new G(s,t,r,e),l=!1,f=!1;void 0!==(u=c.next());){var v=N(u),d=P(u,e.variables),p=S(u),y=D(t,C(v,d)),h=i.getRecord(y);a&&oe(y);var m=void 0,g=i.resolvers[s];if(void 0!==g&&"function"==typeof g[v]){e.parentTypeName=s,e.parentKey=t,e.parentFieldKey=y,e.fieldName=v,void 0!==h&&(n[p]=h);var b=g[v](n,d||Object.create(null),i,e);m=void 0!==u.selectionSet?ye(e,s,v,y,F(u),n[p]||Object.create(null),b):void 0===b&&void 0===o?null:b}else if(void 0===u.selectionSet)m=h;else{var k=i.getLink(y);void 0!==k?m=he(e,k,s,v,F(u),n[p]):"object"==typeof h&&null!==h&&(m=h)}if(void 0===m&&void 0!==o&&o.isFieldNullable(s,v))f=!0,n[p]=null;else{if(void 0===m)return;l=!0,n[p]=m}}return f&&(e.partial=!0),a&&f&&!l?void 0:n}},ye=function(e,t,r,n,i,o,a){if(Array.isArray(a)){for(var s=e.schemaPredicates,u=void 0===s||s.isListNullable(t,r),c=new Array(a.length),l=0,f=a.length;l<f;l++){var v=ye(e,t,r,D(n,""+l),i,void 0!==o?o[l]:void 0,a[l]);if(void 0===v&&!u)return;c[l]=void 0!==v?v:null}return c}if(null==a)return null;if(me(a)){var d=void 0===o?Object.create(null):o;return"string"==typeof a?pe(e,a,i,d):function(e,t,r,n,i){var o=e.store,a=e.schemaPredicates,s=o.keyOfEntity(i)||t;oe(s);var u=i.__typename,c=o.getField(s,"__typename")||u;if(!("string"!=typeof c||u&&c!==u)){n.__typename=c;for(var l,f=new G(c,s,r,e),v=!1,d=!1;void 0!==(l=f.next());){var p=N(l),y=S(l),h=D(s,C(p,P(l,e.variables))),m=o.getRecord(h),g=i[p],b=void 0;if(void 0!==g&&void 0===l.selectionSet)b=g;else if(void 0===l.selectionSet)b=m;else if(void 0!==g)b=ye(e,c,p,h,F(l),n[y],g);else{var k=o.getLink(h);void 0!==k?b=he(e,k,c,p,F(l),n[y]):"object"==typeof m&&null!==m&&(b=m)}if(void 0===b&&void 0!==a&&a.isFieldNullable(c,p))d=!0,n[y]=null;else{if(void 0===b)return;v=!0,n[y]=b}}return d&&(e.partial=!0),v?n:void 0}}(e,n,i,d,a)}},he=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,s=void 0!==a&&a.isListNullable(r,n),u=new Array(t.length),c=0,l=t.length;c<l;c++){var f=he(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!s)return;u[c]=void 0!==f?f:null}return u}return null===t?null:pe(e,t,i,void 0===o?Object.create(null):o)},me=function(e){return"string"==typeof e||"object"==typeof e&&"string"==typeof e.__typename},ge=function(e){this.schema=r(e)};ge.prototype.isFieldNullable=function(e,t){var r=be(this.schema,e,t);return void 0!==r&&n(r.type)},ge.prototype.isListNullable=function(e,t){var r=be(this.schema,e,t);if(void 0===r)return!1;var a=i(r.type)?r.type.ofType:r.type;return o(a)&&n(a.ofType)},ge.prototype.isFieldAvailableOnType=function(e,t){return!!be(this.schema,e,t)},ge.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e);_e(r);var n=this.schema.getType(t);return ke(n),this.schema.isPossibleType(r,n)};var be=function(e,t,r){var n=e.getType(t);ke(n);var i=n.getFields()[r];if(void 0!==i)return i},ke=function(e,t){j(e instanceof a,"",3)},_e=function(e,t){j(e instanceof s||e instanceof u,"",5)},Oe=function(e,t){return w(w({},e),{context:w(w({},e.context),{meta:w(w({},e.context.meta),{cacheOutcome:t})})})},we=function(e){return w(w({},e),{query:f(e.query)})},Ne=function(e){return e.context.requestPolicy},xe=function(e){return"query"===e.operationName},Se=function(e){return xe(e)&&"network-only"!==Ne(e)},Fe=function(e,t){return w(w({},e),{context:w(w({},e.context),{requestPolicy:t})})};function Re(e){return Se(e)}function Ke(e){return Oe(e.operation,e.outcome)}function qe(e){return"miss"===e.outcome}function Pe(e){return"miss"!==e.outcome}function Te(e){return!Se(e)}var je=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new ue(e.schema?new ge(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),o=new Set,a=new Map,s=Object.create(null),u=function(e,t){void 0!==t&&t.forEach((function(t){var r=s[t];if(void 0!==r){s[t]=[];for(var n=0,i=r.length;n<i;n++)e.add(r[n])}}))},c=function(e,t){t.forEach((function(t){if(t!==e.key){var r=a.get(t);void 0!==r&&(a.delete(t),n.reexecuteOperation(Fe(r,"cache-first")))}}))},l=function(e){if(function(e){return"mutation"===e.operationName}(a=e)&&"network-only"!==Ne(a)){var t=e.key,r=H(i,e,t).dependencies;if(0!==r.size){o.add(t);var n=new Set;u(n,r),c(e,n)}}var a},f=function(e,t){t.forEach((function(t){(s[t]||(s[t]=[])).push(e.key),a.has(e.key)||a.set(e.key,"network-only"===Ne(e)?Fe(e,"cache-and-network"):e)}))},v=function(e){var t,r=ce(i,e),n=r.data,o=r.partial;return null===n?t="miss":(f(e,r.dependencies),t=o&&"cache-only"!==Ne(e)?"partial":"hit"),{outcome:t,operation:e,data:n}},d=function(e){var t,r,n=e.operation,a=e.error,s=e.extensions,l=xe(n),v=e.data,d=n.key;if(o.has(d)&&(o.delete(d),i.clearOptimistic(d)),null!=v)if(t=z(i,n,v).dependencies,l){var p=ce(i,n);v=p.data,r=p.dependencies}else v=ce(i,n,v).data;var y=new Set;return u(y,t),l&&u(y,r),c(e.operation,y),l&&void 0!==r&&f(e.operation,r),{data:v,error:a,extensions:s,operation:n}};function p(e){var t=e.operation,r=e.outcome,i=Ne(t),o={operation:Oe(t,r),data:e.data,error:e.error,extensions:e.extensions};return("cache-and-network"===i||"cache-first"===i&&"partial"===r)&&(o.stale=!0,n.reexecuteOperation(Fe(t,"network-only"))),o}return function(e){var t=g(b(l)(k(we)(e))),n=g(k(v)(_(Re)(t))),i=k(Ke)(_(qe)(n)),o=k(p)(_(Pe)(n)),a=k(d)(r(O([_(Te)(t),i])));return O([a,o])}}};export{ue as Store,je as cacheExchange,ce as query,le as read,z as write,J as writeFragment,H as writeOptimistic}; | ||
//# sourceMappingURL=urql-exchange-graphcache.es.min.js.map |
@@ -1291,6 +1291,3 @@ "use strict"; | ||
var policy = getRequestPolicy(operation); | ||
if ("cache-and-network" === policy || "cache-first" === policy && "partial" === outcome) { | ||
client.reexecuteOperation(toRequestPolicy(operation, "network-only")); | ||
} | ||
return { | ||
var result = { | ||
operation: addCacheOutcome(operation, outcome), | ||
@@ -1301,2 +1298,7 @@ data: res.data, | ||
}; | ||
if ("cache-and-network" === policy || "cache-first" === policy && "partial" === outcome) { | ||
result.stale = !0; | ||
client.reexecuteOperation(toRequestPolicy(operation, "network-only")); | ||
} | ||
return result; | ||
} | ||
@@ -1303,0 +1305,0 @@ return function(ops$) { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("graphql"),t=require("urql"),r=require("pessimism"),n=require("wonka");function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var o=function(e){return e.name.value},a=function(e){return e.typeCondition.name.value},s=function(e){return void 0!==e.alias?e.alias.value:o(e)},u=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},c=function(e){var t=e.typeCondition;return void 0!==t?o(t):null},l=function(t){return t.kind===e.Kind.FIELD},f=function(t){return t.kind===e.Kind.INLINE_FRAGMENT},p=function(t,r){if(void 0===t.arguments||0===t.arguments.length)return null;for(var n=Object.create(null),i=0,a=0,s=t.arguments.length;a<s;a++){var u=t.arguments[a],c=e.valueFromASTUntyped(u.value,r);null!=c&&(n[o(u)]=c,i++)}return i>0?n:null},v=function(t,r){if(void 0===t.variableDefinitions)return{};var n=r||{};return t.variableDefinitions.reduce((function(t,r){var i=o(r.variable),a=n[i];if(void 0===a){if(void 0===r.defaultValue)return t;a=e.valueFromASTUntyped(r.defaultValue,n)}return t[i]=a,t}),Object.create(null))},d=function(e,t,r){if(!e){var n=new Error((t||"Minfied Error #"+r+"\n")+"\nhttps://github.com/FormidableLabs/urql-exchange-graphcache/blob/master/docs/help.md#"+r);throw n.name="Graphcache Error",n}},y=function(t){return t.kind===e.Kind.FRAGMENT_DEFINITION};function h(t){return t.kind===e.Kind.OPERATION_DEFINITION}var m=function(e){var t=e.definitions.find(h);return d(!!t,"",1),t};function g(e,t){return e[o(t)]=t,e}var b=function(e){return e.definitions.filter(y).reduce(g,{})},k=function(t,r){var n=t.directives;if(void 0===n)return!0;for(var i=0,a=n.length;i<a;i++){var s=n[i],u=o(s),c="include"===u;if(c||"skip"===u){var l=s.arguments?s.arguments[0]:null;if(l&&"if"===o(l)){var f=e.valueFromASTUntyped(l.value,r);if("boolean"==typeof f||null===f)return c?!!f:!f}}}return!0},_=function(e,r){return r?e+"("+t.stringifyVariables(r)+")":e},O=function(e,t){return e+"."+t},w=function(e,t,r,n){return!(!t||t!==c(e)&&u(e).some((function(e){if(!l(e))return!1;var t=_(o(e),p(e,n.variables));return!n.store.hasField(O(r,t))})))},x=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};x.prototype.next=function(){for(;0!==this.indexStack.length;){var e=this.indexStack[this.indexStack.length-1]++,t=this.selectionStack[this.selectionStack.length-1];if(e>=t.length)this.indexStack.pop(),this.selectionStack.pop();else{var r=t[e];if(k(r,this.context.variables)){if(l(r)){if("__typename"===o(r))continue;return r}var n=f(r)?r:this.context.fragments[o(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(c(n),this.typename):w(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(u(n)))}}}};var N=function(e){return Array.isArray(e)?e.some(N):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},S=function(e,t,r){M(0);var n=q(e,t,r);return I(),n},q=function(e,t,r){var n=m(t.query),i={dependencies:Q()},o=u(n),a=e.getRootKey(n.operation),s={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates};return a===s.store.getRootKey("query")?R(s,a,o,r):A(s,a,o,r),i},F=function(e,t,r){M(r);var n=m(t.query),i={dependencies:Q()},a=e.getRootKey("mutation"),s=e.getRootKey(n.operation);d(s===a,"",10);for(var c,l={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates,optimistic:!0},f=Object.create(null),y=new x(s,s,u(n),l);void 0!==(c=y.next());)if(void 0!==c.selectionSet){var h=o(c),g=l.store.optimisticMutations[h];if(void 0!==g){l.fieldName=h;var k=p(c,l.variables),_=g(k||Object.create(null),l.store,l);N(_)||j(l,_,u(c)),f[h]=_;var O=l.store.updates[a][h];void 0!==O&&O(f,k||Object.create(null),l.store,l)}}return I(),i},T=function(e,t,r,n){var o=b(t),s=o[Object.keys(o)[0]];if(void 0!==s){var c=a(s),l=i({__typename:c},r),f=e.keyOfEntity(l);if(f){var p={parentTypeName:c,parentKey:f,parentFieldKey:"",fieldName:"",variables:n||{},fragments:o,result:{dependencies:Q()},store:e,schemaPredicates:e.schemaPredicates};R(p,f,u(s),l)}}},R=function(e,t,r,n){var i=e.store,a=t===e.store.getRootKey("query"),c=n.__typename;a||C(t),i.writeField(a?t:c,t,"__typename");for(var l,f=new x(c,t,r,e);void 0!==(l=f.next());){var v=o(l),d=p(l,e.variables),y=O(t,_(v,d)),h=n[s(l)];if(a&&C(y),void 0===l.selectionSet)i.writeRecord(h,y);else if(N(h))i.writeRecord(h,y);else{var m=K(e,y,u(l),h);i.writeConnection(O(t,v),y,d),i.writeLink(m,y),i.removeRecord(y)}}},K=function(e,t,r,n){if(Array.isArray(n)){for(var i=new Array(n.length),o=0,a=n.length;o<a;o++){var s=n[o],u=O(t,""+o),c=K(e,u,r,s);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t,p=n.__typename;return void 0===e.store.keys[n.__typename]&&null===l&&!p.endsWith("Connection")&&p.endsWith("Edge"),R(e,f,r,n),f},A=function(e,t,r,n){for(var i,a=t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription"),c=new x(t,t,r,e);void 0!==(i=c.next());){var l=o(i),f=p(i,e.variables),v=n[s(i)];if(void 0===i.selectionSet||null===v||N(v)||j(e,v,u(i)),a){e.parentTypeName=t,e.parentKey=t,e.parentFieldKey=O(t,_(l,f)),e.fieldName=l;var d=e.store.updates[t][l];void 0!==d&&d(n,f||Object.create(null),e.store,e)}}},j=function(e,t,r){if(Array.isArray(t)){for(var n=new Array(t.length),i=0,o=t.length;i<o;i++)n[i]=j(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?R(e,a,r,t):A(e,t.__typename,r,t)}},P=function(e,t,r){var n,i=e.store,a="Query"===t;if(a)n=t;else{if(C(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(O(t,_("__typename")))}for(var s,c=new x(n,t,r,e);void 0!==(s=c.next());){var l=o(s),f=O(t,_(l,p(s,e.variables)));if(a&&C(f),void 0===s.selectionSet)i.removeRecord(f);else{var v=u(s),d=i.getLink(f);if(i.removeLink(f),void 0===d)void 0!==i.getRecord(f)&&i.removeRecord(f);else if(Array.isArray(d))for(var y=0,h=d.length;y<h;y++){var m=d[y];null!==m&&P(e,m,v)}else null!==d&&P(e,d,v)}}},E={current:null},L={current:null},M=function(e){E.current=new Set,L.current=e},I=function(){E.current=null,L.current=null},Q=function(){return d(null!==(e=E).current,"",2),e.current;var e},C=function(e){E.current.add(e)},D=function(e,t,n){return r.setOptimistic(e,t,n,L.current||0)},G=function(e,t){var n=L.current||0;return n?r.setOptimistic(e,t,void 0,n):r.remove(e,t)},V=function(e,t,n,i,o){var a;if(this.records=r.asMutable(r.make()),this.connections=r.asMutable(r.make()),this.links=r.asMutable(r.make()),this.resolvers=t||{},this.optimisticMutations=i||{},this.keys=o||{},this.schemaPredicates=e,this.updates={Mutation:n&&n.Mutation||{},Subscription:n&&n.Subscription||{}},e){var s=e.schema,u=s.getQueryType(),c=s.getMutationType(),l=s.getSubscriptionType(),f=u?u.name:"Query",p=c?c.name:"Mutation",v=l?l.name:"Subscription";this.rootFields={query:f,mutation:p,subscription:v},this.rootNames=((a={})[f]="query",a[p]="mutation",a[v]="subscription",a)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};V.prototype.getRootKey=function(e){return this.rootFields[e]},V.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;return r?this.rootNames[r]?this.rootNames[r]:(this.keys[r]?t=this.keys[r](e):null!=n?t=""+n:null!=i&&(t=""+i),t?r+":"+t:null):null},V.prototype.clearOptimistic=function(e){this.records=r.clearOptimistic(this.records,e),this.connections=r.clearOptimistic(this.connections,e),this.links=r.clearOptimistic(this.links,e)},V.prototype.getRecord=function(e){return r.get(this.records,e)},V.prototype.removeRecord=function(e){return this.records=G(this.records,e)},V.prototype.writeRecord=function(e,t){return this.records=D(this.records,t,e)},V.prototype.getField=function(e,t,r){return this.getRecord(O(e,_(t,r)))},V.prototype.writeField=function(e,t,r,n){return this.records=D(this.records,O(t,_(r,n)),e)},V.prototype.getLink=function(e){return r.get(this.links,e)},V.prototype.removeLink=function(e){return this.links=G(this.links,e)},V.prototype.writeLink=function(e,t){return this.links=D(this.links,t,e)},V.prototype.writeConnection=function(e,t,n){if(void 0!==this.getLink(t)||null===n)return this.connections;var i=r.get(this.connections,e),o=[n,t];if(void 0===i)i=[o];else{for(var a=0,s=i.length;a<s;a++)if(i[a][1]===t)return this.connections;(i=i.slice()).push(o)}return this.connections=D(this.connections,e,i)},V.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},V.prototype.resolve=function(e,t,r){if(null===e)return null;if("string"==typeof e)return C(e),this.resolveValueOrLink(O(e,_(t,r)));var n=this.keyOfEntity(e);return null===n?null:(C(n),this.resolveValueOrLink(O(n,_(t,r))))},V.prototype.resolveConnections=function(e,t){var n;if("string"==typeof e)n=r.get(this.connections,O(e,t));else if(null!==e){var i=this.keyOfEntity(e);null!==i&&(C(i),n=r.get(this.connections,O(i,t)))}return void 0!==n?n:[]},V.prototype.invalidateQuery=function(e,r){!function(e,t){M(0);var r=m(t.query),n={variables:v(r,t.variables),fragments:b(t.query),store:e,schemaPredicates:e.schemaPredicates};P(n,n.store.getRootKey("query"),u(r)),I()}(this,t.createRequest(e,r))},V.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},V.prototype.updateQuery=function(e,r){var n=t.createRequest(e.query,e.variables),i=r(this.readQuery(n));null!==i&&q(this,n,i)},V.prototype.readQuery=function(e){return W(this,t.createRequest(e.query,e.variables)).data},V.prototype.readFragment=function(e,t,r){return H(this,e,t,r)},V.prototype.writeFragment=function(e,t,r){T(this,e,t,r)};var U=function(e,t,r){M(0);var n=W(e,t,r);return I(),n},W=function(e,t,r){var n=m(t.query),i=e.getRootKey(n.operation),o=u(n),a={parentTypeName:i,parentKey:i,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},s=r||Object.create(null);return s=i!==a.store.getRootKey("query")?z(a,i,o,s):J(a,i,o,s),{dependencies:Q(),partial:void 0!==s&&a.partial,data:void 0===s?null:s}},z=function(e,t,r,n){if("string"!=typeof n.__typename)return n;var i=Object.create(null);i.__typename=n.__typename;for(var o,a=new x(t,t,r,e);void 0!==(o=a.next());){var c=s(o),l=n[c];i[c]=void 0===o.selectionSet||null===l||N(l)?l:B(e,u(o),l)}return i},B=function(e,t,r){if(Array.isArray(r)){for(var n=new Array(r.length),i=0,o=r.length;i<o;i++)n[i]=B(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var s=J(e,a,t,Object.create(null));return void 0===s?null:s}return z(e,r.__typename,t,r)},H=function(e,t,r,n){var o=b(t),s=o[Object.keys(o)[0]];if(void 0===s)return null;var c=a(s);"string"==typeof r||r.__typename||(r.__typename=c);var l="string"!=typeof r?e.keyOfEntity(i({__typename:c},r)):r;return l&&J({parentTypeName:c,parentKey:l,parentFieldKey:"",fieldName:"",variables:n||{},fragments:o,partial:!1,store:e,schemaPredicates:e.schemaPredicates},l,u(s),Object.create(null))||null},J=function(e,t,r,n){var i=e.store,a=e.schemaPredicates,c=t===i.getRootKey("query");c||C(t);var l=c?t:i.getField(t,"__typename");if("string"==typeof l){n.__typename=l;for(var f,v=new x(l,t,r,e),d=!1,y=!1;void 0!==(f=v.next());){var h=o(f),m=p(f,e.variables),g=s(f),b=O(t,_(h,m)),k=i.getRecord(b);c&&C(b);var w=void 0,N=i.resolvers[l];if(void 0!==N&&"function"==typeof N[h]){e.parentTypeName=l,e.parentKey=t,e.parentFieldKey=b,e.fieldName=h,void 0!==k&&(n[g]=k);var S=N[h](n,m||Object.create(null),i,e);w=void 0!==f.selectionSet?X(e,l,h,b,u(f),n[g]||Object.create(null),S):void 0===S&&void 0===a?null:S}else if(void 0===f.selectionSet)w=k;else{var q=i.getLink(b);void 0!==q?w=Y(e,q,l,h,u(f),n[g]):"object"==typeof k&&null!==k&&(w=k)}if(void 0===w&&void 0!==a&&a.isFieldNullable(l,h))y=!0,n[g]=null;else{if(void 0===w)return;d=!0,n[g]=w}}return y&&(e.partial=!0),c&&y&&!d?void 0:n}},X=function(e,t,r,n,i,a,c){if(Array.isArray(c)){for(var l=e.schemaPredicates,f=void 0===l||l.isListNullable(t,r),v=new Array(c.length),d=0,y=c.length;d<y;d++){var h=X(e,t,r,O(n,""+d),i,void 0!==a?a[d]:void 0,c[d]);if(void 0===h&&!f)return;v[d]=void 0!==h?h:null}return v}if(null==c)return null;if(Z(c)){var m=void 0===a?Object.create(null):a;return"string"==typeof c?J(e,c,i,m):function(e,t,r,n,i){var a=e.store,c=e.schemaPredicates,l=a.keyOfEntity(i)||t;C(l);var f=i.__typename,v=a.getField(l,"__typename")||f;if(!("string"!=typeof v||f&&v!==f)){n.__typename=v;for(var d,y=new x(v,l,r,e),h=!1,m=!1;void 0!==(d=y.next());){var g=o(d),b=s(d),k=O(l,_(g,p(d,e.variables))),w=a.getRecord(k),N=i[g],S=void 0;if(void 0!==N&&void 0===d.selectionSet)S=N;else if(void 0===d.selectionSet)S=w;else if(void 0!==N)S=X(e,v,g,k,u(d),n[b],N);else{var q=a.getLink(k);void 0!==q?S=Y(e,q,v,g,u(d),n[b]):"object"==typeof w&&null!==w&&(S=w)}if(void 0===S&&void 0!==c&&c.isFieldNullable(v,g))m=!0,n[b]=null;else{if(void 0===S)return;h=!0,n[b]=S}}return m&&(e.partial=!0),h?n:void 0}}(e,n,i,m,c)}},Y=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,s=void 0!==a&&a.isListNullable(r,n),u=new Array(t.length),c=0,l=t.length;c<l;c++){var f=Y(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!s)return;u[c]=void 0!==f?f:null}return u}return null===t?null:J(e,t,i,void 0===o?Object.create(null):o)},Z=function(e){return"string"==typeof e||"object"==typeof e&&"string"==typeof e.__typename},$=function(t){this.schema=e.buildClientSchema(t)};$.prototype.isFieldNullable=function(t,r){var n=ee(this.schema,t,r);return void 0!==n&&e.isNullableType(n.type)},$.prototype.isListNullable=function(t,r){var n=ee(this.schema,t,r);if(void 0===n)return!1;var i=e.isNonNullType(n.type)?n.type.ofType:n.type;return e.isListType(i)&&e.isNullableType(i.ofType)},$.prototype.isFieldAvailableOnType=function(e,t){return!!ee(this.schema,e,t)},$.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e);re(r);var n=this.schema.getType(t);return te(n),this.schema.isPossibleType(r,n)};var ee=function(e,t,r){var n=e.getType(t);te(n);var i=n.getFields()[r];if(void 0!==i)return i},te=function(t,r){d(t instanceof e.GraphQLObjectType,"",3)},re=function(t,r){d(t instanceof e.GraphQLInterfaceType||t instanceof e.GraphQLUnionType,"",5)},ne=function(e,t){return i(i({},e),{context:i(i({},e.context),{meta:i(i({},e.context.meta),{cacheOutcome:t})})})},ie=function(e){return i(i({},e),{query:t.formatDocument(e.query)})},oe=function(e){return e.context.requestPolicy},ae=function(e){return"query"===e.operationName},se=function(e){return ae(e)&&"network-only"!==oe(e)},ue=function(e,t){return i(i({},e),{context:i(i({},e.context),{requestPolicy:t})})};function ce(e){return se(e)}function le(e){return ne(e.operation,e.outcome)}function fe(e){return"miss"===e.outcome}function pe(e){return"miss"!==e.outcome}function ve(e){return!se(e)}exports.Store=V,exports.cacheExchange=function(e){return function(t){var r=t.forward,i=t.client;e||(e={});var o=new V(e.schema?new $(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),a=new Set,s=new Map,u=Object.create(null),c=function(e,t){void 0!==t&&t.forEach((function(t){var r=u[t];if(void 0!==r){u[t]=[];for(var n=0,i=r.length;n<i;n++)e.add(r[n])}}))},l=function(e,t){t.forEach((function(t){if(t!==e.key){var r=s.get(t);void 0!==r&&(s.delete(t),i.reexecuteOperation(ue(r,"cache-first")))}}))},f=function(e){if(function(e){return"mutation"===e.operationName}(i=e)&&"network-only"!==oe(i)){var t=e.key,r=F(o,e,t).dependencies;if(0!==r.size){a.add(t);var n=new Set;c(n,r),l(e,n)}}var i},p=function(e,t){t.forEach((function(t){(u[t]||(u[t]=[])).push(e.key),s.has(e.key)||s.set(e.key,"network-only"===oe(e)?ue(e,"cache-and-network"):e)}))},v=function(e){var t,r=U(o,e),n=r.data,i=r.partial;return null===n?t="miss":(p(e,r.dependencies),t=i&&"cache-only"!==oe(e)?"partial":"hit"),{outcome:t,operation:e,data:n}},d=function(e){var t,r,n=e.operation,i=e.error,s=e.extensions,u=ae(n),f=e.data,v=n.key;if(a.has(v)&&(a.delete(v),o.clearOptimistic(v)),null!=f)if(t=S(o,n,f).dependencies,u){var d=U(o,n);f=d.data,r=d.dependencies}else f=U(o,n,f).data;var y=new Set;return c(y,t),u&&c(y,r),l(e.operation,y),u&&void 0!==r&&p(e.operation,r),{data:f,error:i,extensions:s,operation:n}};function y(e){var t=e.operation,r=e.outcome,n=oe(t);return("cache-and-network"===n||"cache-first"===n&&"partial"===r)&&i.reexecuteOperation(ue(t,"network-only")),{operation:ne(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=n.share(n.tap(f)(n.map(ie)(e))),i=n.share(n.map(v)(n.filter(ce)(t))),o=n.map(le)(n.filter(fe)(i)),a=n.map(y)(n.filter(pe)(i)),s=n.map(d)(r(n.merge([n.filter(ve)(t),o])));return n.merge([s,a])}}},exports.query=U,exports.read=W,exports.write=S,exports.writeFragment=T,exports.writeOptimistic=F; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("graphql"),t=require("urql"),r=require("pessimism"),n=require("wonka");function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var o=function(e){return e.name.value},a=function(e){return e.typeCondition.name.value},s=function(e){return void 0!==e.alias?e.alias.value:o(e)},u=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},c=function(e){var t=e.typeCondition;return void 0!==t?o(t):null},l=function(t){return t.kind===e.Kind.FIELD},f=function(t){return t.kind===e.Kind.INLINE_FRAGMENT},p=function(t,r){if(void 0===t.arguments||0===t.arguments.length)return null;for(var n=Object.create(null),i=0,a=0,s=t.arguments.length;a<s;a++){var u=t.arguments[a],c=e.valueFromASTUntyped(u.value,r);null!=c&&(n[o(u)]=c,i++)}return i>0?n:null},v=function(t,r){if(void 0===t.variableDefinitions)return{};var n=r||{};return t.variableDefinitions.reduce((function(t,r){var i=o(r.variable),a=n[i];if(void 0===a){if(void 0===r.defaultValue)return t;a=e.valueFromASTUntyped(r.defaultValue,n)}return t[i]=a,t}),Object.create(null))},d=function(e,t,r){if(!e){var n=new Error((t||"Minfied Error #"+r+"\n")+"\nhttps://github.com/FormidableLabs/urql-exchange-graphcache/blob/master/docs/help.md#"+r);throw n.name="Graphcache Error",n}},y=function(t){return t.kind===e.Kind.FRAGMENT_DEFINITION};function h(t){return t.kind===e.Kind.OPERATION_DEFINITION}var m=function(e){var t=e.definitions.find(h);return d(!!t,"",1),t};function g(e,t){return e[o(t)]=t,e}var b=function(e){return e.definitions.filter(y).reduce(g,{})},k=function(t,r){var n=t.directives;if(void 0===n)return!0;for(var i=0,a=n.length;i<a;i++){var s=n[i],u=o(s),c="include"===u;if(c||"skip"===u){var l=s.arguments?s.arguments[0]:null;if(l&&"if"===o(l)){var f=e.valueFromASTUntyped(l.value,r);if("boolean"==typeof f||null===f)return c?!!f:!f}}}return!0},_=function(e,r){return r?e+"("+t.stringifyVariables(r)+")":e},O=function(e,t){return e+"."+t},w=function(e,t,r,n){return!(!t||t!==c(e)&&u(e).some((function(e){if(!l(e))return!1;var t=_(o(e),p(e,n.variables));return!n.store.hasField(O(r,t))})))},x=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};x.prototype.next=function(){for(;0!==this.indexStack.length;){var e=this.indexStack[this.indexStack.length-1]++,t=this.selectionStack[this.selectionStack.length-1];if(e>=t.length)this.indexStack.pop(),this.selectionStack.pop();else{var r=t[e];if(k(r,this.context.variables)){if(l(r)){if("__typename"===o(r))continue;return r}var n=f(r)?r:this.context.fragments[o(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(c(n),this.typename):w(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(u(n)))}}}};var N=function(e){return Array.isArray(e)?e.some(N):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},S=function(e,t,r){M(0);var n=q(e,t,r);return I(),n},q=function(e,t,r){var n=m(t.query),i={dependencies:Q()},o=u(n),a=e.getRootKey(n.operation),s={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates};return a===s.store.getRootKey("query")?R(s,a,o,r):A(s,a,o,r),i},F=function(e,t,r){M(r);var n=m(t.query),i={dependencies:Q()},a=e.getRootKey("mutation"),s=e.getRootKey(n.operation);d(s===a,"",10);for(var c,l={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates,optimistic:!0},f=Object.create(null),y=new x(s,s,u(n),l);void 0!==(c=y.next());)if(void 0!==c.selectionSet){var h=o(c),g=l.store.optimisticMutations[h];if(void 0!==g){l.fieldName=h;var k=p(c,l.variables),_=g(k||Object.create(null),l.store,l);N(_)||j(l,_,u(c)),f[h]=_;var O=l.store.updates[a][h];void 0!==O&&O(f,k||Object.create(null),l.store,l)}}return I(),i},T=function(e,t,r,n){var o=b(t),s=o[Object.keys(o)[0]];if(void 0!==s){var c=a(s),l=i({__typename:c},r),f=e.keyOfEntity(l);if(f){var p={parentTypeName:c,parentKey:f,parentFieldKey:"",fieldName:"",variables:n||{},fragments:o,result:{dependencies:Q()},store:e,schemaPredicates:e.schemaPredicates};R(p,f,u(s),l)}}},R=function(e,t,r,n){var i=e.store,a=t===e.store.getRootKey("query"),c=n.__typename;a||C(t),i.writeField(a?t:c,t,"__typename");for(var l,f=new x(c,t,r,e);void 0!==(l=f.next());){var v=o(l),d=p(l,e.variables),y=O(t,_(v,d)),h=n[s(l)];if(a&&C(y),void 0===l.selectionSet)i.writeRecord(h,y);else if(N(h))i.writeRecord(h,y);else{var m=K(e,y,u(l),h);i.writeConnection(O(t,v),y,d),i.writeLink(m,y),i.removeRecord(y)}}},K=function(e,t,r,n){if(Array.isArray(n)){for(var i=new Array(n.length),o=0,a=n.length;o<a;o++){var s=n[o],u=O(t,""+o),c=K(e,u,r,s);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t,p=n.__typename;return void 0===e.store.keys[n.__typename]&&null===l&&!p.endsWith("Connection")&&p.endsWith("Edge"),R(e,f,r,n),f},A=function(e,t,r,n){for(var i,a=t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription"),c=new x(t,t,r,e);void 0!==(i=c.next());){var l=o(i),f=p(i,e.variables),v=n[s(i)];if(void 0===i.selectionSet||null===v||N(v)||j(e,v,u(i)),a){e.parentTypeName=t,e.parentKey=t,e.parentFieldKey=O(t,_(l,f)),e.fieldName=l;var d=e.store.updates[t][l];void 0!==d&&d(n,f||Object.create(null),e.store,e)}}},j=function(e,t,r){if(Array.isArray(t)){for(var n=new Array(t.length),i=0,o=t.length;i<o;i++)n[i]=j(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?R(e,a,r,t):A(e,t.__typename,r,t)}},P=function(e,t,r){var n,i=e.store,a="Query"===t;if(a)n=t;else{if(C(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(O(t,_("__typename")))}for(var s,c=new x(n,t,r,e);void 0!==(s=c.next());){var l=o(s),f=O(t,_(l,p(s,e.variables)));if(a&&C(f),void 0===s.selectionSet)i.removeRecord(f);else{var v=u(s),d=i.getLink(f);if(i.removeLink(f),void 0===d)void 0!==i.getRecord(f)&&i.removeRecord(f);else if(Array.isArray(d))for(var y=0,h=d.length;y<h;y++){var m=d[y];null!==m&&P(e,m,v)}else null!==d&&P(e,d,v)}}},E={current:null},L={current:null},M=function(e){E.current=new Set,L.current=e},I=function(){E.current=null,L.current=null},Q=function(){return d(null!==(e=E).current,"",2),e.current;var e},C=function(e){E.current.add(e)},D=function(e,t,n){return r.setOptimistic(e,t,n,L.current||0)},G=function(e,t){var n=L.current||0;return n?r.setOptimistic(e,t,void 0,n):r.remove(e,t)},V=function(e,t,n,i,o){var a;if(this.records=r.asMutable(r.make()),this.connections=r.asMutable(r.make()),this.links=r.asMutable(r.make()),this.resolvers=t||{},this.optimisticMutations=i||{},this.keys=o||{},this.schemaPredicates=e,this.updates={Mutation:n&&n.Mutation||{},Subscription:n&&n.Subscription||{}},e){var s=e.schema,u=s.getQueryType(),c=s.getMutationType(),l=s.getSubscriptionType(),f=u?u.name:"Query",p=c?c.name:"Mutation",v=l?l.name:"Subscription";this.rootFields={query:f,mutation:p,subscription:v},this.rootNames=((a={})[f]="query",a[p]="mutation",a[v]="subscription",a)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};V.prototype.getRootKey=function(e){return this.rootFields[e]},V.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;return r?this.rootNames[r]?this.rootNames[r]:(this.keys[r]?t=this.keys[r](e):null!=n?t=""+n:null!=i&&(t=""+i),t?r+":"+t:null):null},V.prototype.clearOptimistic=function(e){this.records=r.clearOptimistic(this.records,e),this.connections=r.clearOptimistic(this.connections,e),this.links=r.clearOptimistic(this.links,e)},V.prototype.getRecord=function(e){return r.get(this.records,e)},V.prototype.removeRecord=function(e){return this.records=G(this.records,e)},V.prototype.writeRecord=function(e,t){return this.records=D(this.records,t,e)},V.prototype.getField=function(e,t,r){return this.getRecord(O(e,_(t,r)))},V.prototype.writeField=function(e,t,r,n){return this.records=D(this.records,O(t,_(r,n)),e)},V.prototype.getLink=function(e){return r.get(this.links,e)},V.prototype.removeLink=function(e){return this.links=G(this.links,e)},V.prototype.writeLink=function(e,t){return this.links=D(this.links,t,e)},V.prototype.writeConnection=function(e,t,n){if(void 0!==this.getLink(t)||null===n)return this.connections;var i=r.get(this.connections,e),o=[n,t];if(void 0===i)i=[o];else{for(var a=0,s=i.length;a<s;a++)if(i[a][1]===t)return this.connections;(i=i.slice()).push(o)}return this.connections=D(this.connections,e,i)},V.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},V.prototype.resolve=function(e,t,r){if(null===e)return null;if("string"==typeof e)return C(e),this.resolveValueOrLink(O(e,_(t,r)));var n=this.keyOfEntity(e);return null===n?null:(C(n),this.resolveValueOrLink(O(n,_(t,r))))},V.prototype.resolveConnections=function(e,t){var n;if("string"==typeof e)n=r.get(this.connections,O(e,t));else if(null!==e){var i=this.keyOfEntity(e);null!==i&&(C(i),n=r.get(this.connections,O(i,t)))}return void 0!==n?n:[]},V.prototype.invalidateQuery=function(e,r){!function(e,t){M(0);var r=m(t.query),n={variables:v(r,t.variables),fragments:b(t.query),store:e,schemaPredicates:e.schemaPredicates};P(n,n.store.getRootKey("query"),u(r)),I()}(this,t.createRequest(e,r))},V.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},V.prototype.updateQuery=function(e,r){var n=t.createRequest(e.query,e.variables),i=r(this.readQuery(n));null!==i&&q(this,n,i)},V.prototype.readQuery=function(e){return W(this,t.createRequest(e.query,e.variables)).data},V.prototype.readFragment=function(e,t,r){return H(this,e,t,r)},V.prototype.writeFragment=function(e,t,r){T(this,e,t,r)};var U=function(e,t,r){M(0);var n=W(e,t,r);return I(),n},W=function(e,t,r){var n=m(t.query),i=e.getRootKey(n.operation),o=u(n),a={parentTypeName:i,parentKey:i,parentFieldKey:"",fieldName:"",variables:v(n,t.variables),fragments:b(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},s=r||Object.create(null);return s=i!==a.store.getRootKey("query")?z(a,i,o,s):J(a,i,o,s),{dependencies:Q(),partial:void 0!==s&&a.partial,data:void 0===s?null:s}},z=function(e,t,r,n){if("string"!=typeof n.__typename)return n;var i=Object.create(null);i.__typename=n.__typename;for(var o,a=new x(t,t,r,e);void 0!==(o=a.next());){var c=s(o),l=n[c];i[c]=void 0===o.selectionSet||null===l||N(l)?l:B(e,u(o),l)}return i},B=function(e,t,r){if(Array.isArray(r)){for(var n=new Array(r.length),i=0,o=r.length;i<o;i++)n[i]=B(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var s=J(e,a,t,Object.create(null));return void 0===s?null:s}return z(e,r.__typename,t,r)},H=function(e,t,r,n){var o=b(t),s=o[Object.keys(o)[0]];if(void 0===s)return null;var c=a(s);"string"==typeof r||r.__typename||(r.__typename=c);var l="string"!=typeof r?e.keyOfEntity(i({__typename:c},r)):r;return l&&J({parentTypeName:c,parentKey:l,parentFieldKey:"",fieldName:"",variables:n||{},fragments:o,partial:!1,store:e,schemaPredicates:e.schemaPredicates},l,u(s),Object.create(null))||null},J=function(e,t,r,n){var i=e.store,a=e.schemaPredicates,c=t===i.getRootKey("query");c||C(t);var l=c?t:i.getField(t,"__typename");if("string"==typeof l){n.__typename=l;for(var f,v=new x(l,t,r,e),d=!1,y=!1;void 0!==(f=v.next());){var h=o(f),m=p(f,e.variables),g=s(f),b=O(t,_(h,m)),k=i.getRecord(b);c&&C(b);var w=void 0,N=i.resolvers[l];if(void 0!==N&&"function"==typeof N[h]){e.parentTypeName=l,e.parentKey=t,e.parentFieldKey=b,e.fieldName=h,void 0!==k&&(n[g]=k);var S=N[h](n,m||Object.create(null),i,e);w=void 0!==f.selectionSet?X(e,l,h,b,u(f),n[g]||Object.create(null),S):void 0===S&&void 0===a?null:S}else if(void 0===f.selectionSet)w=k;else{var q=i.getLink(b);void 0!==q?w=Y(e,q,l,h,u(f),n[g]):"object"==typeof k&&null!==k&&(w=k)}if(void 0===w&&void 0!==a&&a.isFieldNullable(l,h))y=!0,n[g]=null;else{if(void 0===w)return;d=!0,n[g]=w}}return y&&(e.partial=!0),c&&y&&!d?void 0:n}},X=function(e,t,r,n,i,a,c){if(Array.isArray(c)){for(var l=e.schemaPredicates,f=void 0===l||l.isListNullable(t,r),v=new Array(c.length),d=0,y=c.length;d<y;d++){var h=X(e,t,r,O(n,""+d),i,void 0!==a?a[d]:void 0,c[d]);if(void 0===h&&!f)return;v[d]=void 0!==h?h:null}return v}if(null==c)return null;if(Z(c)){var m=void 0===a?Object.create(null):a;return"string"==typeof c?J(e,c,i,m):function(e,t,r,n,i){var a=e.store,c=e.schemaPredicates,l=a.keyOfEntity(i)||t;C(l);var f=i.__typename,v=a.getField(l,"__typename")||f;if(!("string"!=typeof v||f&&v!==f)){n.__typename=v;for(var d,y=new x(v,l,r,e),h=!1,m=!1;void 0!==(d=y.next());){var g=o(d),b=s(d),k=O(l,_(g,p(d,e.variables))),w=a.getRecord(k),N=i[g],S=void 0;if(void 0!==N&&void 0===d.selectionSet)S=N;else if(void 0===d.selectionSet)S=w;else if(void 0!==N)S=X(e,v,g,k,u(d),n[b],N);else{var q=a.getLink(k);void 0!==q?S=Y(e,q,v,g,u(d),n[b]):"object"==typeof w&&null!==w&&(S=w)}if(void 0===S&&void 0!==c&&c.isFieldNullable(v,g))m=!0,n[b]=null;else{if(void 0===S)return;h=!0,n[b]=S}}return m&&(e.partial=!0),h?n:void 0}}(e,n,i,m,c)}},Y=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,s=void 0!==a&&a.isListNullable(r,n),u=new Array(t.length),c=0,l=t.length;c<l;c++){var f=Y(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!s)return;u[c]=void 0!==f?f:null}return u}return null===t?null:J(e,t,i,void 0===o?Object.create(null):o)},Z=function(e){return"string"==typeof e||"object"==typeof e&&"string"==typeof e.__typename},$=function(t){this.schema=e.buildClientSchema(t)};$.prototype.isFieldNullable=function(t,r){var n=ee(this.schema,t,r);return void 0!==n&&e.isNullableType(n.type)},$.prototype.isListNullable=function(t,r){var n=ee(this.schema,t,r);if(void 0===n)return!1;var i=e.isNonNullType(n.type)?n.type.ofType:n.type;return e.isListType(i)&&e.isNullableType(i.ofType)},$.prototype.isFieldAvailableOnType=function(e,t){return!!ee(this.schema,e,t)},$.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e);re(r);var n=this.schema.getType(t);return te(n),this.schema.isPossibleType(r,n)};var ee=function(e,t,r){var n=e.getType(t);te(n);var i=n.getFields()[r];if(void 0!==i)return i},te=function(t,r){d(t instanceof e.GraphQLObjectType,"",3)},re=function(t,r){d(t instanceof e.GraphQLInterfaceType||t instanceof e.GraphQLUnionType,"",5)},ne=function(e,t){return i(i({},e),{context:i(i({},e.context),{meta:i(i({},e.context.meta),{cacheOutcome:t})})})},ie=function(e){return i(i({},e),{query:t.formatDocument(e.query)})},oe=function(e){return e.context.requestPolicy},ae=function(e){return"query"===e.operationName},se=function(e){return ae(e)&&"network-only"!==oe(e)},ue=function(e,t){return i(i({},e),{context:i(i({},e.context),{requestPolicy:t})})};function ce(e){return se(e)}function le(e){return ne(e.operation,e.outcome)}function fe(e){return"miss"===e.outcome}function pe(e){return"miss"!==e.outcome}function ve(e){return!se(e)}exports.Store=V,exports.cacheExchange=function(e){return function(t){var r=t.forward,i=t.client;e||(e={});var o=new V(e.schema?new $(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),a=new Set,s=new Map,u=Object.create(null),c=function(e,t){void 0!==t&&t.forEach((function(t){var r=u[t];if(void 0!==r){u[t]=[];for(var n=0,i=r.length;n<i;n++)e.add(r[n])}}))},l=function(e,t){t.forEach((function(t){if(t!==e.key){var r=s.get(t);void 0!==r&&(s.delete(t),i.reexecuteOperation(ue(r,"cache-first")))}}))},f=function(e){if(function(e){return"mutation"===e.operationName}(i=e)&&"network-only"!==oe(i)){var t=e.key,r=F(o,e,t).dependencies;if(0!==r.size){a.add(t);var n=new Set;c(n,r),l(e,n)}}var i},p=function(e,t){t.forEach((function(t){(u[t]||(u[t]=[])).push(e.key),s.has(e.key)||s.set(e.key,"network-only"===oe(e)?ue(e,"cache-and-network"):e)}))},v=function(e){var t,r=U(o,e),n=r.data,i=r.partial;return null===n?t="miss":(p(e,r.dependencies),t=i&&"cache-only"!==oe(e)?"partial":"hit"),{outcome:t,operation:e,data:n}},d=function(e){var t,r,n=e.operation,i=e.error,s=e.extensions,u=ae(n),f=e.data,v=n.key;if(a.has(v)&&(a.delete(v),o.clearOptimistic(v)),null!=f)if(t=S(o,n,f).dependencies,u){var d=U(o,n);f=d.data,r=d.dependencies}else f=U(o,n,f).data;var y=new Set;return c(y,t),u&&c(y,r),l(e.operation,y),u&&void 0!==r&&p(e.operation,r),{data:f,error:i,extensions:s,operation:n}};function y(e){var t=e.operation,r=e.outcome,n=oe(t),o={operation:ne(t,r),data:e.data,error:e.error,extensions:e.extensions};return("cache-and-network"===n||"cache-first"===n&&"partial"===r)&&(o.stale=!0,i.reexecuteOperation(ue(t,"network-only"))),o}return function(e){var t=n.share(n.tap(f)(n.map(ie)(e))),i=n.share(n.map(v)(n.filter(ce)(t))),o=n.map(le)(n.filter(fe)(i)),a=n.map(y)(n.filter(pe)(i)),s=n.map(d)(r(n.merge([n.filter(ve)(t),o])));return n.merge([s,a])}}},exports.query=U,exports.read=W,exports.write=S,exports.writeFragment=T,exports.writeOptimistic=F; | ||
//# sourceMappingURL=urql-exchange-graphcache.min.js.map |
{ | ||
"name": "@urql/exchange-graphcache-extras", | ||
"version": "1.0.4-debug-trace", | ||
"version": "1.1.0", | ||
"private": true, | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
{ | ||
"name": "@urql/exchange-graphcache", | ||
"version": "1.0.4-debug-trace", | ||
"version": "1.1.0", | ||
"description": "A normalized and configurable cache exchange for urql", | ||
@@ -84,16 +84,16 @@ "repository": "https://github.com/FormidableLabs/urql-exchange-graphcache", | ||
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0", | ||
"urql": ">= 1.5.1" | ||
"urql": ">= 1.6.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.6.2", | ||
"@babel/core": "^7.6.4", | ||
"@babel/plugin-transform-object-assign": "^7.2.0", | ||
"@babel/plugin-transform-react-jsx": "^7.3.0", | ||
"@testing-library/react": "^9.1.4", | ||
"@testing-library/react": "^9.3.0", | ||
"@types/enzyme": "3.10.3", | ||
"@types/graphql": "^14.5.0", | ||
"@types/jest": "^24.0.18", | ||
"@types/react": "16.9.3", | ||
"@types/react": "16.9.5", | ||
"@types/react-test-renderer": "16.9.0", | ||
"@typescript-eslint/eslint-plugin": "^2.3.1", | ||
"@typescript-eslint/parser": "^2.3.1", | ||
"@typescript-eslint/eslint-plugin": "^2.3.3", | ||
"@typescript-eslint/parser": "^2.3.3", | ||
"babel-plugin-closure-elimination": "^1.3.0", | ||
@@ -103,24 +103,24 @@ "babel-plugin-transform-async-to-promises": "^0.8.14", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.14.0", | ||
"enzyme-to-json": "^3.4.0", | ||
"eslint": "^6.4.0", | ||
"eslint-config-prettier": "^6.3.0", | ||
"enzyme-adapter-react-16": "^1.15.1", | ||
"enzyme-to-json": "^3.4.2", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.4.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-react": "^7.14.3", | ||
"eslint-plugin-react-hooks": "^2.0.1", | ||
"eslint-plugin-react": "^7.16.0", | ||
"eslint-plugin-react-hooks": "^2.1.2", | ||
"graphql": "^14.5.8", | ||
"graphql-tag": "^2.10.1", | ||
"husky": "^3.0.4", | ||
"husky": "^3.0.8", | ||
"jest": "^24.9.0", | ||
"lint-staged": "^9.4.0", | ||
"lint-staged": "^9.4.2", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^1.17.1", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react": "^16.10.2", | ||
"react-dom": "^16.10.2", | ||
"react-hooks-testing-library": "^0.6.0", | ||
"react-is": "^16.9.0", | ||
"react-is": "^16.10.2", | ||
"react-ssr-prepass": "^1.0.7", | ||
"react-test-renderer": "^16.9.0", | ||
"react-test-renderer": "^16.10.2", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^1.21.4", | ||
"rollup": "^1.23.1", | ||
"rollup-plugin-babel": "^4.3.3", | ||
@@ -132,8 +132,8 @@ "rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"rollup-plugin-typescript2": "^0.24.2", | ||
"terser": "^4.3.2", | ||
"rollup-plugin-typescript2": "^0.24.3", | ||
"terser": "^4.3.8", | ||
"ts-jest": "^24.1.0", | ||
"typescript": "^3.6.3", | ||
"urql": "^1.5.1" | ||
"typescript": "^3.6.4", | ||
"urql": "^1.6.0" | ||
} | ||
} |
@@ -747,2 +747,3 @@ import gql from 'graphql-tag'; | ||
expect(reexec).toHaveBeenCalledTimes(1); | ||
expect(result.mock.calls[1][0].stale).toBe(true); | ||
expect(result.mock.calls[1][0].data).toEqual({ | ||
@@ -749,0 +750,0 @@ __typename: 'Query', |
@@ -275,2 +275,9 @@ import { | ||
const policy = getRequestPolicy(operation); | ||
const result: OperationResult = { | ||
operation: addCacheOutcome(operation, outcome), | ||
data: res.data, | ||
error: res.error, | ||
extensions: res.extensions, | ||
}; | ||
if ( | ||
@@ -280,2 +287,3 @@ policy === 'cache-and-network' || | ||
) { | ||
result.stale = true; | ||
client.reexecuteOperation( | ||
@@ -286,8 +294,3 @@ toRequestPolicy(operation, 'network-only') | ||
return { | ||
operation: addCacheOutcome(operation, outcome), | ||
data: res.data, | ||
error: res.error, | ||
extensions: res.extensions, | ||
}; | ||
return result; | ||
} | ||
@@ -294,0 +297,0 @@ ) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
721421
8681
1