Socket
Socket
Sign inDemoInstall

@urql/exchange-graphcache

Package Overview
Dependencies
13
Maintainers
3
Versions
292
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-rc.5 to 1.0.0-rc.6

4

dist/types/store.d.ts

@@ -42,4 +42,4 @@ import { DocumentNode } from 'graphql';

hasField(key: string): boolean;
updateQuery(ctx: {
query: DocumentNode;
updateQuery(input: {
query: string | DocumentNode;
variables?: Variables;

@@ -46,0 +46,0 @@ }, updater: (data: Data | null) => null | Data): void;

import { Kind, buildClientSchema, isNullableType, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType } from "graphql";
import { createRequest, formatDocument } from "urql";
import { asMutable, make, clearOptimistic, get, setOptimistic, remove } from "pessimism";

@@ -7,4 +9,2 @@

import { formatDocument } from "urql";
import { pipe, map, tap, share, filter, merge } from "wonka";

@@ -313,2 +313,5 @@

};
if ("development" === process.env.NODE_ENV) {
ctx.isOptimistic = !0;
}
var operationName = ctx.store.getRootKey(operation.operation);

@@ -384,4 +387,9 @@ if (operationName === ctx.store.getRootKey("mutation")) {

}
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates && typename) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
if ("production" !== process.env.NODE_ENV) {
if (void 0 === fieldValue) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `" + fieldKey + "` is `undefined`, but the GraphQL query expects a " + (void 0 === node.selectionSet ? "scalar (number, boolean, etc)" : "selection set") + " for this field." + (ctx.isOptimistic ? "\nYour optimistic result may be missing a field!" : ""));
continue;
} else if (ctx.schemaPredicates && typename) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
}

@@ -703,6 +711,7 @@ if (void 0 === node.selectionSet) {

Store.prototype.updateQuery = function updateQuery(ctx, updater) {
var output = updater(read(this, ctx).data);
Store.prototype.updateQuery = function updateQuery(input, updater) {
var request = createRequest(input.query, input.variables);
var output = updater(read(this, request).data);
if (null !== output) {
startWrite(this, ctx, output);
startWrite(this, request, output);
}

@@ -1053,4 +1062,6 @@ };

var op = ops.get(key);
ops.delete(key);
client.reexecuteOperation(op);
if (void 0 !== op) {
ops.delete(key);
client.reexecuteOperation(op);
}
}

@@ -1057,0 +1068,0 @@ });

@@ -1,2 +0,2 @@

import{Kind as e,buildClientSchema as t,isNullableType as r,isNonNullType as n,isListType as i}from"graphql";import{asMutable as o,make as a,clearOptimistic as u,get as s,setOptimistic as c,remove as l}from"pessimism";import f from"fast-json-stable-stringify";import{formatDocument as v}from"urql";import{pipe as d,map as y,tap as p,share as h,filter as m,merge as g}from"wonka";var k=function(e){return e.name.value},b=function(e){return void 0!==e.alias?e.alias.value:k(e)},O=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},w=function(e){var t=e.typeCondition;return void 0!==t?k(t):null},_=function(t){return t.kind===e.FIELD},x=function(t){return t.kind===e.INLINE_FRAGMENT},S=function(t,r){switch(t.kind){case e.NULL:return null;case e.INT:return parseInt(t.value,10);case e.FLOAT:return parseFloat(t.value);case e.LIST:for(var n=new Array(t.values.length),i=0,o=t.values.length;i<o;i++)n[i]=S(t.values[i],r);return n;case e.OBJECT:for(var a=Object.create(null),u=0,s=t.fields.length;u<s;u++){var c=t.fields[u];a[k(c)]=S(c.value,r)}return a;case e.VARIABLE:var l=r[k(t)];return void 0!==l?l:null;default:return t.value}},R=function(e,t){if(void 0===e.arguments||0===e.arguments.length)return null;for(var r=Object.create(null),n=0,i=e.arguments.length;n<i;n++){var o=e.arguments[n];r[k(o)]=S(o.value,t)}return r},A=function(e,t){if(void 0===e.variableDefinitions)return{};var r=t||{};return e.variableDefinitions.reduce(function(e,t){var n=k(t.variable),i=r[n];if(void 0===i){if(void 0===t.defaultValue)return e;i=S(t.defaultValue,r)}return e[n]=i,e},Object.create(null))},q=function(t){return t.kind===e.FRAGMENT_DEFINITION};function F(t){return t.kind===e.OPERATION_DEFINITION}var L=function(e){return e.definitions.find(F)};function N(e,t){return e[k(t)]=t,e}var P=function(e){return e.definitions.filter(q).reduce(N,{})},T=function(e,t){if(void 0===e.directives)return!0;for(var r=e.directives,n=0,i=r.length;n<i;n++){var o=r[n],a=k(o),u="include"===a;if(u||"skip"===a){var s=o.arguments?o.arguments[0]:null;if(s&&"if"===k(s)){var c=S(s.value,t);if("boolean"==typeof c||null===c)return u?!!c:!c}}}return!0},E=function(e,t){return t?e+"("+f(t)+")":e},j=function(e,t){return e+"."+t};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 K=function(e,t,r,n){return!(!t||t!==w(e)&&O(e).some(function(e){if(!_(e))return!1;var t=k(e),i=R(e,n.variables),o=E(t,i);return!n.store.hasField(j(r,o))}))},M=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};M.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(T(r,this.context.variables)){if(_(r)){if("__typename"===k(r))continue;return r}var n=x(r)?r:this.context.fragments[k(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(w(n),this.typename):K(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(O(n)))}}}};var Q=function(e){return Array.isArray(e)?e.some(Q):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},V=function(e,t,r){Y(0);var n=D(e,t,r);return Z(),n},D=function(e,t,r){var n=L(t.query),i={dependencies:$()},o={variables:A(n,t.variables),fragments:P(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=O(n),u=o.store.getRootKey(n.operation);return u===o.store.getRootKey("query")?G(o,u,a,r):J(o,u,a,r),i},C=function(e,t,r){Y(r);var n=L(t.query),i={dependencies:$()},o={variables:A(n,t.variables),fragments:P(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=o.store.getRootKey(n.operation);if(a===o.store.getRootKey("mutation"))for(var u,s=O(n),c=new M(a,a,s,o);void 0!==(u=c.next());)if(void 0!==u.selectionSet){var l=k(u),f=o.store.optimisticMutations[l];if(void 0!==f){var v=R(u,o.variables),d=O(u),y=f(v||{},o.store,o);Q(y)||U(o,y,d)}}return Z(),i},B=function(e,t,r){var n=P(t),i=n[Object.keys(n)[0]];if(void 0!==i){var o=O(i),a=I({},r,{__typename:i.typeCondition.name.value}),u=e.keyOfEntity(a);if(u){var s={variables:{},fragments:n,result:{dependencies:$()},store:e,schemaPredicates:e.schemaPredicates};G(s,u,o,a)}}},G=function(e,t,r,n){var i=e.store,o=e.variables,a=t===e.store.getRootKey("query"),u=n.__typename;a||ee(t),i.writeField(a?t:u,t,"__typename");for(var s,c=new M(u,t,r,e);void 0!==(s=c.next());){var l=k(s),f=R(s,o),v=j(t,E(l,f)),d=n[b(s)];if(a&&ee(v),void 0===s.selectionSet)i.writeRecord(d,v);else if(Q(d))i.writeRecord(d,v);else{var y=O(s),p=z(e,v,y,d);i.writeLink(p,v),i.removeRecord(v)}}},z=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 u=n[o],s=j(t,""+o),c=z(e,s,r,u);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t;return G(e,f,r,n),f},J=function(e,t,r,n){for(var i,o=new M(t,t,r,e);void 0!==(i=o.next());){var a=k(i),u=b(i),s=R(i,e.variables),c=n[u];if(void 0!==i.selectionSet&&null!==c&&!Q(c)){var l=O(i);U(e,c,l)}if(t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription")){var f=e.store.updates[t][a];void 0!==f&&f(n,s||{},e.store,e)}}},U=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]=U(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?G(e,a,r,t):J(e,t.__typename,r,t)}},H=function(e,t,r){var n,i=e.store,o=e.variables,a="Query"===t;if(a)n=t;else{if(ee(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(j(t,E("__typename")))}for(var u,s=new M(n,t,r,e);void 0!==(u=s.next());){var c=k(u),l=R(u,o),f=j(t,E(c,l));if(a&&ee(f),void 0===u.selectionSet)i.removeRecord(f);else{var v=O(u),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,p=d.length;y<p;y++){var h=d[y];null!==h&&H(e,h,v)}else null!==d&&H(e,d,v)}}},W={current:null},X={current:null},Y=function(e){W.current=new Set,X.current=e},Z=function(){W.current=null,X.current=null},$=function(){return W.current},ee=function(e){W.current.add(e)},te=function(e,t,r){return c(e,t,r,X.current||0)},re=function(e,t){var r=X.current||0;return r?c(e,t,void 0,r):l(e,t)},ne=function(e,t,r,n,i){var u;if(this.records=o(a()),this.links=o(a()),this.resolvers=t||{},this.optimisticMutations=n||{},this.keys=i||{},this.schemaPredicates=e,this.updates={Mutation:r&&r.Mutation||{},Subscription:r&&r.Subscription||{}},e){var s=e.schema,c=s.getQueryType(),l=s.getMutationType(),f=s.getSubscriptionType(),v=c?c.name:"Query",d=l?l.name:"Mutation",y=f?f.name:"Subscription";this.rootFields={query:v,mutation:d,subscription:y},this.rootNames=((u={})[v]="query",u[d]="mutation",u[y]="subscription",u)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};ne.prototype.getRootKey=function(e){return this.rootFields[e]},ne.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;if(!r)return null;if(this.rootNames[r])return this.rootNames[r];if(this.keys[r])t=this.keys[r](e);else if(null!=n)t=""+n;else{if(null==i)return null;t=""+i}return t?r+":"+t:null},ne.prototype.clearOptimistic=function(e){this.records=u(this.records,e),this.links=u(this.links,e)},ne.prototype.getRecord=function(e){return s(this.records,e)},ne.prototype.removeRecord=function(e){return this.records=re(this.records,e)},ne.prototype.writeRecord=function(e,t){return this.records=te(this.records,t,e)},ne.prototype.getField=function(e,t,r){var n=j(e,E(t,r));return this.getRecord(n)},ne.prototype.writeField=function(e,t,r,n){var i=j(t,E(r,n));return this.records=te(this.records,i,e)},ne.prototype.getLink=function(e){return s(this.links,e)},ne.prototype.removeLink=function(e){return this.links=re(this.links,e)},ne.prototype.writeLink=function(e,t){return this.links=te(this.links,t,e)},ne.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},ne.prototype.resolve=function(e,t,r){if("string"==typeof e)return ee(e),this.resolveValueOrLink(j(e,E(t,r)));var n=this.keyOfEntity(e);return null===n?null:(ee(n),this.resolveValueOrLink(j(n,E(t,r))))},ne.prototype.invalidateQuery=function(e,t){!function(e,t){Y(0);var r=L(t.query),n={variables:A(r,t.variables),fragments:P(t.query),store:e,schemaPredicates:e.schemaPredicates};H(n,n.store.getRootKey("query"),O(r)),Z()}(this,{query:e,variables:t})},ne.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},ne.prototype.updateQuery=function(e,t){var r=t(oe(this,e).data);null!==r&&D(this,e,r)},ne.prototype.writeFragment=function(e,t){B(this,e,t)};var ie=function(e,t,r){Y(0);var n=oe(e,t,r);return Z(),n},oe=function(e,t,r){var n=L(t.query),i=e.getRootKey(n.operation),o=O(n),a={variables:A(n,t.variables),fragments:P(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},u=r||Object.create(null);return u="Query"!==i?ae(a,i,o,u):se(a,i,o,u),{dependencies:$(),partial:void 0!==u&&a.partial,data:void 0===u?null:u}},ae=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 M(t,t,r,e);void 0!==(o=a.next());){var u=b(o),s=n[u];i[u]=void 0===o.selectionSet||null===s||Q(s)?s:ue(e,O(o),s)}return i},ue=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]=ue(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var u=Object.create(null),s=se(e,a,t,u);return void 0===s?null:s}return ae(e,r.__typename,t,r)},se=function(e,t,r,n){var i=e.store,o=e.variables,a=e.schemaPredicates,u=t===i.getRootKey("query");u||ee(t);var s=u?t:i.getField(t,"__typename");if("string"==typeof s){n.__typename=s;for(var c,l=new M(s,t,r,e),f=!1,v=!1;void 0!==(c=l.next());){var d=k(c),y=R(c,o),p=b(c),h=j(t,E(d,y)),m=i.getRecord(h);u&&ee(h);var g=void 0,w=i.resolvers[s];if(void 0!==w&&"function"==typeof w[d]){void 0!==m&&(n[p]=m);var _=w[d](n,y||{},i,e);void 0!==c.selectionSet&&(_=ce(e,_,s,d,h,O(c),n[p]));var x=null==_;g=x&&void 0!==a?void 0:x?null:_}else if(void 0===c.selectionSet)g=m;else{var S=O(c),A=i.getLink(h);void 0!==A?g=le(e,A,s,d,S,n[p]):"object"==typeof m&&null!==m&&(g=m)}if(void 0===g&&void 0!==a&&a.isFieldNullable(s,d))v=!0,n[p]=null;else{if(void 0===g)return;f=!0,n[p]=g}}return v&&(e.partial=!0),u&&v&&!f?void 0:n}},ce=function(e,t,r,n,i,o,a){if(Array.isArray(t)){for(var u=e.schemaPredicates,s=void 0!==u&&u.isListNullable(r,n),c=new Array(t.length),l=0,f=t.length;l<f;l++){var v=void 0!==a?a[l]:void 0,d=j(i,""+l),y=ce(e,t[l],r,n,d,o,v);if(void 0===y&&!s)return;t[l]=void 0!==y?y:null}return c}if(null===t)return null;if(fe(t)){var p=void 0===a?Object.create(null):a,h=("string"==typeof t?t:e.store.keyOfEntity(t))||i;return se(e,h,o,p)}},le=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,u=void 0!==a&&a.isListNullable(r,n),s=new Array(t.length),c=0,l=t.length;c<l;c++){var f=le(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!u)return;s[c]=void 0!==f?f:null}return s}if(null===t)return null;var v=void 0===o?Object.create(null):o;return se(e,t,i,v)},fe=function(e){return"string"==typeof e||"object"==typeof e&&null!==e&&"string"==typeof e.__typename},ve=function(e){this.schema=t(e)};ve.prototype.isFieldNullable=function(e,t){var n=de(this.schema,e,t);return void 0!==n&&r(n.type)},ve.prototype.isListNullable=function(e,t){var o=de(this.schema,e,t);if(void 0===o)return!1;var a=n(o.type)?o.type.ofType:o.type;return i(a)&&r(a.ofType)},ve.prototype.isFieldAvailableOnType=function(e,t){return!!de(this.schema,e,t)},ve.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e),n=this.schema.getType(t);return this.schema.isPossibleType(r,n)};var de=function(e,t,r){var n=e.getType(t);if(void 0!==n){var i=n.getFields()[r];if(void 0!==i)return i}},ye=function(e,t){return I({},e,{context:I({},e.context,{meta:I({},e.context.meta,{cacheOutcome:t})})})},pe=function(e){return I({},e,{query:v(e.query)})},he=function(e){return e.context.requestPolicy},me=function(e){return"query"===e.operationName},ge=function(e){var t=he(e);return me(e)&&"network-only"!==t},ke=function(e,t){return I({},e,{context:I({},e.context,{requestPolicy:t})})};function be(e){return ge(e)}function Oe(e){return"miss"===e.outcome}function we(e){return ye(e.operation,e.outcome)}function _e(e){return"miss"!==e.outcome}function xe(e){return!ge(e)}var Se=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new ne(e.schema?new ve(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),o=new Set,a=new Map,u=Object.create(null),s=function(e,t){var r=new Set;function i(e){return r.add(e)}t.forEach(function(e){var t=u[e];void 0!==t&&(u[e]=[],t.forEach(i))}),r.forEach(function(t){if(t!==e.key){var r=a.get(t);a.delete(t),n.reexecuteOperation(r)}})},c=function(e){if(a=he(n=e),function(e){return"mutation"===e.operationName}(n)&&"network-only"!==a){var t=e.key,r=C(i,e,t).dependencies;0!==r.size&&(o.add(t),s(e,r))}var n,a},l=function(e,t){t.forEach(function(t){(u[t]||(u[t]=[])).push(e.key),a.has(e.key)||a.set(e.key,"network-only"===e.context.requestPolicy?ke(e,"cache-and-network"):e)})},f=function(e){var t,r=he(e),n=ie(i,e),o=n.data,a=n.partial;return null===o?t="miss":(l(e,n.dependencies),t=a&&"cache-only"!==r?"partial":"hit"),{outcome:t,operation:e,data:o}},v=function(e){var t,r,n=e.operation,a=e.error,u=e.extensions,c=me(n),f=e.data,v=n.key;if(o.has(v)&&(o.delete(v),i.clearOptimistic(v)),null!=f)if(t=V(i,n,f).dependencies,c){var d=ie(i,n);f=d.data,r=d.dependencies}else f=ie(i,n,f).data;return void 0!==t&&s(e.operation,t),c&&void 0!==r&&l(e.operation,r),{data:f,error:a,extensions:u,operation:n}};function k(e){var t=e.operation,r=e.outcome,i=he(t);if("cache-and-network"===i||"cache-first"===i&&"partial"===r){var o=ke(t,"network-only");n.reexecuteOperation(o)}return{operation:ye(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=d(e,y(pe),p(c),h),n=d(t,m(be),y(f),h),i=d(n,m(Oe),y(we)),o=d(n,m(_e),y(k)),a=d(r(g([d(t,m(xe)),i])),y(v));return g([a,o])}}};export{ne as Store,Se as cacheExchange,ie as query,oe as read,V as write,B as writeFragment,C as writeOptimistic};
import{Kind as e,buildClientSchema as t,isNullableType as r,isNonNullType as n,isListType as i}from"graphql";import{createRequest as o,formatDocument as a}from"urql";import{asMutable as u,make as s,clearOptimistic as c,get as l,setOptimistic as f,remove as v}from"pessimism";import d from"fast-json-stable-stringify";import{pipe as y,map as p,tap as h,share as m,filter as g,merge as k}from"wonka";var b=function(e){return e.name.value},O=function(e){return void 0!==e.alias?e.alias.value:b(e)},w=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},_=function(e){var t=e.typeCondition;return void 0!==t?b(t):null},x=function(t){return t.kind===e.FIELD},S=function(t){return t.kind===e.INLINE_FRAGMENT},R=function(t,r){switch(t.kind){case e.NULL:return null;case e.INT:return parseInt(t.value,10);case e.FLOAT:return parseFloat(t.value);case e.LIST:for(var n=new Array(t.values.length),i=0,o=t.values.length;i<o;i++)n[i]=R(t.values[i],r);return n;case e.OBJECT:for(var a=Object.create(null),u=0,s=t.fields.length;u<s;u++){var c=t.fields[u];a[b(c)]=R(c.value,r)}return a;case e.VARIABLE:var l=r[b(t)];return void 0!==l?l:null;default:return t.value}},A=function(e,t){if(void 0===e.arguments||0===e.arguments.length)return null;for(var r=Object.create(null),n=0,i=e.arguments.length;n<i;n++){var o=e.arguments[n];r[b(o)]=R(o.value,t)}return r},q=function(e,t){if(void 0===e.variableDefinitions)return{};var r=t||{};return e.variableDefinitions.reduce(function(e,t){var n=b(t.variable),i=r[n];if(void 0===i){if(void 0===t.defaultValue)return e;i=R(t.defaultValue,r)}return e[n]=i,e},Object.create(null))},F=function(t){return t.kind===e.FRAGMENT_DEFINITION};function L(t){return t.kind===e.OPERATION_DEFINITION}var N=function(e){return e.definitions.find(L)};function P(e,t){return e[b(t)]=t,e}var T=function(e){return e.definitions.filter(F).reduce(P,{})},E=function(e,t){if(void 0===e.directives)return!0;for(var r=e.directives,n=0,i=r.length;n<i;n++){var o=r[n],a=b(o),u="include"===a;if(u||"skip"===a){var s=o.arguments?o.arguments[0]:null;if(s&&"if"===b(s)){var c=R(s.value,t);if("boolean"==typeof c||null===c)return u?!!c:!c}}}return!0},j=function(e,t){return t?e+"("+d(t)+")":e},I=function(e,t){return e+"."+t};function K(){return(K=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 M=function(e,t,r,n){return!(!t||t!==_(e)&&w(e).some(function(e){if(!x(e))return!1;var t=b(e),i=A(e,n.variables),o=j(t,i);return!n.store.hasField(I(r,o))}))},Q=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};Q.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(E(r,this.context.variables)){if(x(r)){if("__typename"===b(r))continue;return r}var n=S(r)?r:this.context.fragments[b(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(_(n),this.typename):M(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(w(n)))}}}};var V=function(e){return Array.isArray(e)?e.some(V):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},D=function(e,t,r){Z(0);var n=C(e,t,r);return $(),n},C=function(e,t,r){var n=N(t.query),i={dependencies:ee()},o={variables:q(n,t.variables),fragments:T(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=w(n),u=o.store.getRootKey(n.operation);return u===o.store.getRootKey("query")?z(o,u,a,r):U(o,u,a,r),i},B=function(e,t,r){Z(r);var n=N(t.query),i={dependencies:ee()},o={variables:q(n,t.variables),fragments:T(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=o.store.getRootKey(n.operation);if(a===o.store.getRootKey("mutation"))for(var u,s=w(n),c=new Q(a,a,s,o);void 0!==(u=c.next());)if(void 0!==u.selectionSet){var l=b(u),f=o.store.optimisticMutations[l];if(void 0!==f){var v=A(u,o.variables),d=w(u),y=f(v||{},o.store,o);V(y)||H(o,y,d)}}return $(),i},G=function(e,t,r){var n=T(t),i=n[Object.keys(n)[0]];if(void 0!==i){var o=w(i),a=K({},r,{__typename:i.typeCondition.name.value}),u=e.keyOfEntity(a);if(u){var s={variables:{},fragments:n,result:{dependencies:ee()},store:e,schemaPredicates:e.schemaPredicates};z(s,u,o,a)}}},z=function(e,t,r,n){var i=e.store,o=e.variables,a=t===e.store.getRootKey("query"),u=n.__typename;a||te(t),i.writeField(a?t:u,t,"__typename");for(var s,c=new Q(u,t,r,e);void 0!==(s=c.next());){var l=b(s),f=A(s,o),v=I(t,j(l,f)),d=n[O(s)];if(a&&te(v),void 0===s.selectionSet)i.writeRecord(d,v);else if(V(d))i.writeRecord(d,v);else{var y=w(s),p=J(e,v,y,d);i.writeLink(p,v),i.removeRecord(v)}}},J=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 u=n[o],s=I(t,""+o),c=J(e,s,r,u);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t;return z(e,f,r,n),f},U=function(e,t,r,n){for(var i,o=new Q(t,t,r,e);void 0!==(i=o.next());){var a=b(i),u=O(i),s=A(i,e.variables),c=n[u];if(void 0!==i.selectionSet&&null!==c&&!V(c)){var l=w(i);H(e,c,l)}if(t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription")){var f=e.store.updates[t][a];void 0!==f&&f(n,s||{},e.store,e)}}},H=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]=H(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?z(e,a,r,t):U(e,t.__typename,r,t)}},W=function(e,t,r){var n,i=e.store,o=e.variables,a="Query"===t;if(a)n=t;else{if(te(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(I(t,j("__typename")))}for(var u,s=new Q(n,t,r,e);void 0!==(u=s.next());){var c=b(u),l=A(u,o),f=I(t,j(c,l));if(a&&te(f),void 0===u.selectionSet)i.removeRecord(f);else{var v=w(u),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,p=d.length;y<p;y++){var h=d[y];null!==h&&W(e,h,v)}else null!==d&&W(e,d,v)}}},X={current:null},Y={current:null},Z=function(e){X.current=new Set,Y.current=e},$=function(){X.current=null,Y.current=null},ee=function(){return X.current},te=function(e){X.current.add(e)},re=function(e,t,r){return f(e,t,r,Y.current||0)},ne=function(e,t){var r=Y.current||0;return r?f(e,t,void 0,r):v(e,t)},ie=function(e,t,r,n,i){var o;if(this.records=u(s()),this.links=u(s()),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,c=a.getQueryType(),l=a.getMutationType(),f=a.getSubscriptionType(),v=c?c.name:"Query",d=l?l.name:"Mutation",y=f?f.name:"Subscription";this.rootFields={query:v,mutation:d,subscription:y},this.rootNames=((o={})[v]="query",o[d]="mutation",o[y]="subscription",o)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};ie.prototype.getRootKey=function(e){return this.rootFields[e]},ie.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;if(!r)return null;if(this.rootNames[r])return this.rootNames[r];if(this.keys[r])t=this.keys[r](e);else if(null!=n)t=""+n;else{if(null==i)return null;t=""+i}return t?r+":"+t:null},ie.prototype.clearOptimistic=function(e){this.records=c(this.records,e),this.links=c(this.links,e)},ie.prototype.getRecord=function(e){return l(this.records,e)},ie.prototype.removeRecord=function(e){return this.records=ne(this.records,e)},ie.prototype.writeRecord=function(e,t){return this.records=re(this.records,t,e)},ie.prototype.getField=function(e,t,r){var n=I(e,j(t,r));return this.getRecord(n)},ie.prototype.writeField=function(e,t,r,n){var i=I(t,j(r,n));return this.records=re(this.records,i,e)},ie.prototype.getLink=function(e){return l(this.links,e)},ie.prototype.removeLink=function(e){return this.links=ne(this.links,e)},ie.prototype.writeLink=function(e,t){return this.links=re(this.links,t,e)},ie.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},ie.prototype.resolve=function(e,t,r){if("string"==typeof e)return te(e),this.resolveValueOrLink(I(e,j(t,r)));var n=this.keyOfEntity(e);return null===n?null:(te(n),this.resolveValueOrLink(I(n,j(t,r))))},ie.prototype.invalidateQuery=function(e,t){!function(e,t){Z(0);var r=N(t.query),n={variables:q(r,t.variables),fragments:T(t.query),store:e,schemaPredicates:e.schemaPredicates};W(n,n.store.getRootKey("query"),w(r)),$()}(this,{query:e,variables:t})},ie.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},ie.prototype.updateQuery=function(e,t){var r=o(e.query,e.variables),n=t(ae(this,r).data);null!==n&&C(this,r,n)},ie.prototype.writeFragment=function(e,t){G(this,e,t)};var oe=function(e,t,r){Z(0);var n=ae(e,t,r);return $(),n},ae=function(e,t,r){var n=N(t.query),i=e.getRootKey(n.operation),o=w(n),a={variables:q(n,t.variables),fragments:T(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},u=r||Object.create(null);return u="Query"!==i?ue(a,i,o,u):ce(a,i,o,u),{dependencies:ee(),partial:void 0!==u&&a.partial,data:void 0===u?null:u}},ue=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 Q(t,t,r,e);void 0!==(o=a.next());){var u=O(o),s=n[u];i[u]=void 0===o.selectionSet||null===s||V(s)?s:se(e,w(o),s)}return i},se=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]=se(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var u=Object.create(null),s=ce(e,a,t,u);return void 0===s?null:s}return ue(e,r.__typename,t,r)},ce=function(e,t,r,n){var i=e.store,o=e.variables,a=e.schemaPredicates,u=t===i.getRootKey("query");u||te(t);var s=u?t:i.getField(t,"__typename");if("string"==typeof s){n.__typename=s;for(var c,l=new Q(s,t,r,e),f=!1,v=!1;void 0!==(c=l.next());){var d=b(c),y=A(c,o),p=O(c),h=I(t,j(d,y)),m=i.getRecord(h);u&&te(h);var g=void 0,k=i.resolvers[s];if(void 0!==k&&"function"==typeof k[d]){void 0!==m&&(n[p]=m);var _=k[d](n,y||{},i,e);void 0!==c.selectionSet&&(_=le(e,_,s,d,h,w(c),n[p]));var x=null==_;g=x&&void 0!==a?void 0:x?null:_}else if(void 0===c.selectionSet)g=m;else{var S=w(c),R=i.getLink(h);void 0!==R?g=fe(e,R,s,d,S,n[p]):"object"==typeof m&&null!==m&&(g=m)}if(void 0===g&&void 0!==a&&a.isFieldNullable(s,d))v=!0,n[p]=null;else{if(void 0===g)return;f=!0,n[p]=g}}return v&&(e.partial=!0),u&&v&&!f?void 0:n}},le=function(e,t,r,n,i,o,a){if(Array.isArray(t)){for(var u=e.schemaPredicates,s=void 0!==u&&u.isListNullable(r,n),c=new Array(t.length),l=0,f=t.length;l<f;l++){var v=void 0!==a?a[l]:void 0,d=I(i,""+l),y=le(e,t[l],r,n,d,o,v);if(void 0===y&&!s)return;t[l]=void 0!==y?y:null}return c}if(null===t)return null;if(ve(t)){var p=void 0===a?Object.create(null):a,h=("string"==typeof t?t:e.store.keyOfEntity(t))||i;return ce(e,h,o,p)}},fe=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,u=void 0!==a&&a.isListNullable(r,n),s=new Array(t.length),c=0,l=t.length;c<l;c++){var f=fe(e,t[c],r,n,i,void 0!==o?o[c]:void 0);if(void 0===f&&!u)return;s[c]=void 0!==f?f:null}return s}if(null===t)return null;var v=void 0===o?Object.create(null):o;return ce(e,t,i,v)},ve=function(e){return"string"==typeof e||"object"==typeof e&&null!==e&&"string"==typeof e.__typename},de=function(e){this.schema=t(e)};de.prototype.isFieldNullable=function(e,t){var n=ye(this.schema,e,t);return void 0!==n&&r(n.type)},de.prototype.isListNullable=function(e,t){var o=ye(this.schema,e,t);if(void 0===o)return!1;var a=n(o.type)?o.type.ofType:o.type;return i(a)&&r(a.ofType)},de.prototype.isFieldAvailableOnType=function(e,t){return!!ye(this.schema,e,t)},de.prototype.isInterfaceOfType=function(e,t){if(!t||!e)return!1;if(t===e)return!0;var r=this.schema.getType(e),n=this.schema.getType(t);return this.schema.isPossibleType(r,n)};var ye=function(e,t,r){var n=e.getType(t);if(void 0!==n){var i=n.getFields()[r];if(void 0!==i)return i}},pe=function(e,t){return K({},e,{context:K({},e.context,{meta:K({},e.context.meta,{cacheOutcome:t})})})},he=function(e){return K({},e,{query:a(e.query)})},me=function(e){return e.context.requestPolicy},ge=function(e){return"query"===e.operationName},ke=function(e){var t=me(e);return ge(e)&&"network-only"!==t},be=function(e,t){return K({},e,{context:K({},e.context,{requestPolicy:t})})};function Oe(e){return ke(e)}function we(e){return"miss"===e.outcome}function _e(e){return pe(e.operation,e.outcome)}function xe(e){return"miss"!==e.outcome}function Se(e){return!ke(e)}var Re=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new ie(e.schema?new de(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),o=new Set,a=new Map,u=Object.create(null),s=function(e,t){var r=new Set;function i(e){return r.add(e)}t.forEach(function(e){var t=u[e];void 0!==t&&(u[e]=[],t.forEach(i))}),r.forEach(function(t){if(t!==e.key){var r=a.get(t);void 0!==r&&(a.delete(t),n.reexecuteOperation(r))}})},c=function(e){if(a=me(n=e),function(e){return"mutation"===e.operationName}(n)&&"network-only"!==a){var t=e.key,r=B(i,e,t).dependencies;0!==r.size&&(o.add(t),s(e,r))}var n,a},l=function(e,t){t.forEach(function(t){(u[t]||(u[t]=[])).push(e.key),a.has(e.key)||a.set(e.key,"network-only"===e.context.requestPolicy?be(e,"cache-and-network"):e)})},f=function(e){var t,r=me(e),n=oe(i,e),o=n.data,a=n.partial;return null===o?t="miss":(l(e,n.dependencies),t=a&&"cache-only"!==r?"partial":"hit"),{outcome:t,operation:e,data:o}},v=function(e){var t,r,n=e.operation,a=e.error,u=e.extensions,c=ge(n),f=e.data,v=n.key;if(o.has(v)&&(o.delete(v),i.clearOptimistic(v)),null!=f)if(t=D(i,n,f).dependencies,c){var d=oe(i,n);f=d.data,r=d.dependencies}else f=oe(i,n,f).data;return void 0!==t&&s(e.operation,t),c&&void 0!==r&&l(e.operation,r),{data:f,error:a,extensions:u,operation:n}};function d(e){var t=e.operation,r=e.outcome,i=me(t);if("cache-and-network"===i||"cache-first"===i&&"partial"===r){var o=be(t,"network-only");n.reexecuteOperation(o)}return{operation:pe(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=y(e,p(he),h(c),m),n=y(t,g(Oe),p(f),m),i=y(n,g(we),p(_e)),o=y(n,g(xe),p(d)),a=y(r(k([y(t,g(Se)),i])),p(v));return k([a,o])}}};export{ie as Store,Re as cacheExchange,oe as query,ae as read,D as write,G as writeFragment,B as writeOptimistic};
//# sourceMappingURL=urql-exchange-graphcache.es.min.js.map

@@ -5,2 +5,4 @@ "use strict";

var urql = require("urql");
var Pessimism = require("pessimism");

@@ -12,4 +14,2 @@

var urql = require("urql");
var wonka = require("wonka");

@@ -318,2 +318,5 @@

};
if ("development" === process.env.NODE_ENV) {
ctx.isOptimistic = !0;
}
var operationName = ctx.store.getRootKey(operation.operation);

@@ -389,4 +392,9 @@ if (operationName === ctx.store.getRootKey("mutation")) {

}
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates && typename) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
if ("production" !== process.env.NODE_ENV) {
if (void 0 === fieldValue) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `" + fieldKey + "` is `undefined`, but the GraphQL query expects a " + (void 0 === node.selectionSet ? "scalar (number, boolean, etc)" : "selection set") + " for this field." + (ctx.isOptimistic ? "\nYour optimistic result may be missing a field!" : ""));
continue;
} else if (ctx.schemaPredicates && typename) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
}

@@ -708,6 +716,7 @@ if (void 0 === node.selectionSet) {

Store.prototype.updateQuery = function updateQuery(ctx, updater) {
var output = updater(read(this, ctx).data);
Store.prototype.updateQuery = function updateQuery(input, updater) {
var request = urql.createRequest(input.query, input.variables);
var output = updater(read(this, request).data);
if (null !== output) {
startWrite(this, ctx, output);
startWrite(this, request, output);
}

@@ -1060,4 +1069,6 @@ };

var op = ops.get(key);
ops.delete(key);
client.reexecuteOperation(op);
if (void 0 !== op) {
ops.delete(key);
client.reexecuteOperation(op);
}
}

@@ -1064,0 +1075,0 @@ });

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("graphql"),r=require("pessimism"),n=(e=require("fast-json-stable-stringify"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("urql"),o=require("wonka"),a=function(e){return e.name.value},u=function(e){return void 0!==e.alias?e.alias.value:a(e)},s=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},c=function(e){var t=e.typeCondition;return void 0!==t?a(t):null},l=function(e){return e.kind===t.Kind.FIELD},f=function(e){return e.kind===t.Kind.INLINE_FRAGMENT},v=function(e,r){switch(e.kind){case t.Kind.NULL:return null;case t.Kind.INT:return parseInt(e.value,10);case t.Kind.FLOAT:return parseFloat(e.value);case t.Kind.LIST:for(var n=new Array(e.values.length),i=0,o=e.values.length;i<o;i++)n[i]=v(e.values[i],r);return n;case t.Kind.OBJECT:for(var u=Object.create(null),s=0,c=e.fields.length;s<c;s++){var l=e.fields[s];u[a(l)]=v(l.value,r)}return u;case t.Kind.VARIABLE:var f=r[a(e)];return void 0!==f?f:null;default:return e.value}},d=function(e,t){if(void 0===e.arguments||0===e.arguments.length)return null;for(var r=Object.create(null),n=0,i=e.arguments.length;n<i;n++){var o=e.arguments[n];r[a(o)]=v(o.value,t)}return r},p=function(e,t){if(void 0===e.variableDefinitions)return{};var r=t||{};return e.variableDefinitions.reduce(function(e,t){var n=a(t.variable),i=r[n];if(void 0===i){if(void 0===t.defaultValue)return e;i=v(t.defaultValue,r)}return e[n]=i,e},Object.create(null))},y=function(e){return e.kind===t.Kind.FRAGMENT_DEFINITION};function h(e){return e.kind===t.Kind.OPERATION_DEFINITION}var m=function(e){return e.definitions.find(h)};function g(e,t){return e[a(t)]=t,e}var k=function(e){return e.definitions.filter(y).reduce(g,{})},b=function(e,t){if(void 0===e.directives)return!0;for(var r=e.directives,n=0,i=r.length;n<i;n++){var o=r[n],u=a(o),s="include"===u;if(s||"skip"===u){var c=o.arguments?o.arguments[0]:null;if(c&&"if"===a(c)){var l=v(c.value,t);if("boolean"==typeof l||null===l)return s?!!l:!l}}}return!0},O=function(e,t){return t?e+"("+n(t)+")":e},x=function(e,t){return e+"."+t};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 _=function(e,t,r,n){return!(!t||t!==c(e)&&s(e).some(function(e){if(!l(e))return!1;var t=a(e),i=d(e,n.variables),o=O(t,i);return!n.store.hasField(x(r,o))}))},S=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};S.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(b(r,this.context.variables)){if(l(r)){if("__typename"===a(r))continue;return r}var n=f(r)?r:this.context.fragments[a(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(c(n),this.typename):_(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(s(n)))}}}};var q=function(e){return Array.isArray(e)?e.some(q):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},R=function(e,t,r){M(0);var n=A(e,t,r);return Q(),n},A=function(e,t,r){var n=m(t.query),i={dependencies:D()},o={variables:p(n,t.variables),fragments:k(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=s(n),u=o.store.getRootKey(n.operation);return u===o.store.getRootKey("query")?F(o,u,a,r):L(o,u,a,r),i},N=function(e,t,r){M(r);var n=m(t.query),i={dependencies:D()},o={variables:p(n,t.variables),fragments:k(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},u=o.store.getRootKey(n.operation);if(u===o.store.getRootKey("mutation"))for(var c,l=s(n),f=new S(u,u,l,o);void 0!==(c=f.next());)if(void 0!==c.selectionSet){var v=a(c),y=o.store.optimisticMutations[v];if(void 0!==y){var h=d(c,o.variables),g=s(c),b=y(h||{},o.store,o);q(b)||P(o,b,g)}}return Q(),i},T=function(e,t,r){var n=k(t),i=n[Object.keys(n)[0]];if(void 0!==i){var o=s(i),a=w({},r,{__typename:i.typeCondition.name.value}),u=e.keyOfEntity(a);if(u){var c={variables:{},fragments:n,result:{dependencies:D()},store:e,schemaPredicates:e.schemaPredicates};F(c,u,o,a)}}},F=function(e,t,r,n){var i=e.store,o=e.variables,c=t===e.store.getRootKey("query"),l=n.__typename;c||V(t),i.writeField(c?t:l,t,"__typename");for(var f,v=new S(l,t,r,e);void 0!==(f=v.next());){var p=a(f),y=d(f,o),h=x(t,O(p,y)),m=n[u(f)];if(c&&V(h),void 0===f.selectionSet)i.writeRecord(m,h);else if(q(m))i.writeRecord(m,h);else{var g=s(f),k=K(e,h,g,m);i.writeLink(k,h),i.removeRecord(h)}}},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 u=n[o],s=x(t,""+o),c=K(e,s,r,u);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t;return F(e,f,r,n),f},L=function(e,t,r,n){for(var i,o=new S(t,t,r,e);void 0!==(i=o.next());){var c=a(i),l=u(i),f=d(i,e.variables),v=n[l];if(void 0!==i.selectionSet&&null!==v&&!q(v)){var p=s(i);P(e,v,p)}if(t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription")){var y=e.store.updates[t][c];void 0!==y&&y(n,f||{},e.store,e)}}},P=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]=P(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?F(e,a,r,t):L(e,t.__typename,r,t)}},E=function(e,t,r){var n,i=e.store,o=e.variables,u="Query"===t;if(u)n=t;else{if(V(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(x(t,O("__typename")))}for(var c,l=new S(n,t,r,e);void 0!==(c=l.next());){var f=a(c),v=d(c,o),p=x(t,O(f,v));if(u&&V(p),void 0===c.selectionSet)i.removeRecord(p);else{var y=s(c),h=i.getLink(p);if(i.removeLink(p),void 0===h)void 0!==i.getRecord(p)&&i.removeRecord(p);else if(Array.isArray(h))for(var m=0,g=h.length;m<g;m++){var k=h[m];null!==k&&E(e,k,y)}else null!==h&&E(e,h,y)}}},j={current:null},I={current:null},M=function(e){j.current=new Set,I.current=e},Q=function(){j.current=null,I.current=null},D=function(){return j.current},V=function(e){j.current.add(e)},C=function(e,t,n){return r.setOptimistic(e,t,n,I.current||0)},B=function(e,t){var n=I.current||0;return n?r.setOptimistic(e,t,void 0,n):r.remove(e,t)},G=function(e,t,n,i,o){var a;if(this.records=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 u=e.schema,s=u.getQueryType(),c=u.getMutationType(),l=u.getSubscriptionType(),f=s?s.name:"Query",v=c?c.name:"Mutation",d=l?l.name:"Subscription";this.rootFields={query:f,mutation:v,subscription:d},this.rootNames=((a={})[f]="query",a[v]="mutation",a[d]="subscription",a)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};G.prototype.getRootKey=function(e){return this.rootFields[e]},G.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;if(!r)return null;if(this.rootNames[r])return this.rootNames[r];if(this.keys[r])t=this.keys[r](e);else if(null!=n)t=""+n;else{if(null==i)return null;t=""+i}return t?r+":"+t:null},G.prototype.clearOptimistic=function(e){this.records=r.clearOptimistic(this.records,e),this.links=r.clearOptimistic(this.links,e)},G.prototype.getRecord=function(e){return r.get(this.records,e)},G.prototype.removeRecord=function(e){return this.records=B(this.records,e)},G.prototype.writeRecord=function(e,t){return this.records=C(this.records,t,e)},G.prototype.getField=function(e,t,r){var n=x(e,O(t,r));return this.getRecord(n)},G.prototype.writeField=function(e,t,r,n){var i=x(t,O(r,n));return this.records=C(this.records,i,e)},G.prototype.getLink=function(e){return r.get(this.links,e)},G.prototype.removeLink=function(e){return this.links=B(this.links,e)},G.prototype.writeLink=function(e,t){return this.links=C(this.links,t,e)},G.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},G.prototype.resolve=function(e,t,r){if("string"==typeof e)return V(e),this.resolveValueOrLink(x(e,O(t,r)));var n=this.keyOfEntity(e);return null===n?null:(V(n),this.resolveValueOrLink(x(n,O(t,r))))},G.prototype.invalidateQuery=function(e,t){!function(e,t){M(0);var r=m(t.query),n={variables:p(r,t.variables),fragments:k(t.query),store:e,schemaPredicates:e.schemaPredicates};E(n,n.store.getRootKey("query"),s(r)),Q()}(this,{query:e,variables:t})},G.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},G.prototype.updateQuery=function(e,t){var r=t(J(this,e).data);null!==r&&A(this,e,r)},G.prototype.writeFragment=function(e,t){T(this,e,t)};var z=function(e,t,r){M(0);var n=J(e,t,r);return Q(),n},J=function(e,t,r){var n=m(t.query),i=e.getRootKey(n.operation),o=s(n),a={variables:p(n,t.variables),fragments:k(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},u=r||Object.create(null);return u="Query"!==i?U(a,i,o,u):W(a,i,o,u),{dependencies:D(),partial:void 0!==u&&a.partial,data:void 0===u?null:u}},U=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 S(t,t,r,e);void 0!==(o=a.next());){var c=u(o),l=n[c];i[c]=void 0===o.selectionSet||null===l||q(l)?l:H(e,s(o),l)}return i},H=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]=H(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var u=Object.create(null),s=W(e,a,t,u);return void 0===s?null:s}return U(e,r.__typename,t,r)},W=function(e,t,r,n){var i=e.store,o=e.variables,c=e.schemaPredicates,l=t===i.getRootKey("query");l||V(t);var f=l?t:i.getField(t,"__typename");if("string"==typeof f){n.__typename=f;for(var v,p=new S(f,t,r,e),y=!1,h=!1;void 0!==(v=p.next());){var m=a(v),g=d(v,o),k=u(v),b=x(t,O(m,g)),w=i.getRecord(b);l&&V(b);var _=void 0,q=i.resolvers[f];if(void 0!==q&&"function"==typeof q[m]){void 0!==w&&(n[k]=w);var R=q[m](n,g||{},i,e);void 0!==v.selectionSet&&(R=X(e,R,f,m,b,s(v),n[k]));var A=null==R;_=A&&void 0!==c?void 0:A?null:R}else if(void 0===v.selectionSet)_=w;else{var N=s(v),T=i.getLink(b);void 0!==T?_=Y(e,T,f,m,N,n[k]):"object"==typeof w&&null!==w&&(_=w)}if(void 0===_&&void 0!==c&&c.isFieldNullable(f,m))h=!0,n[k]=null;else{if(void 0===_)return;y=!0,n[k]=_}}return h&&(e.partial=!0),l&&h&&!y?void 0:n}},X=function(e,t,r,n,i,o,a){if(Array.isArray(t)){for(var u=e.schemaPredicates,s=void 0!==u&&u.isListNullable(r,n),c=new Array(t.length),l=0,f=t.length;l<f;l++){var v=void 0!==a?a[l]:void 0,d=x(i,""+l),p=X(e,t[l],r,n,d,o,v);if(void 0===p&&!s)return;t[l]=void 0!==p?p:null}return c}if(null===t)return null;if(Z(t)){var y=void 0===a?Object.create(null):a,h=("string"==typeof t?t:e.store.keyOfEntity(t))||i;return W(e,h,o,y)}},Y=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,u=void 0!==a&&a.isListNullable(r,n),s=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&&!u)return;s[c]=void 0!==f?f:null}return s}if(null===t)return null;var v=void 0===o?Object.create(null):o;return W(e,t,i,v)},Z=function(e){return"string"==typeof e||"object"==typeof e&&null!==e&&"string"==typeof e.__typename},$=function(e){this.schema=t.buildClientSchema(e)};$.prototype.isFieldNullable=function(e,r){var n=ee(this.schema,e,r);return void 0!==n&&t.isNullableType(n.type)},$.prototype.isListNullable=function(e,r){var n=ee(this.schema,e,r);if(void 0===n)return!1;var i=t.isNonNullType(n.type)?n.type.ofType:n.type;return t.isListType(i)&&t.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),n=this.schema.getType(t);return this.schema.isPossibleType(r,n)};var ee=function(e,t,r){var n=e.getType(t);if(void 0!==n){var i=n.getFields()[r];if(void 0!==i)return i}},te=function(e,t){return w({},e,{context:w({},e.context,{meta:w({},e.context.meta,{cacheOutcome:t})})})},re=function(e){return w({},e,{query:i.formatDocument(e.query)})},ne=function(e){return e.context.requestPolicy},ie=function(e){return"query"===e.operationName},oe=function(e){var t=ne(e);return ie(e)&&"network-only"!==t},ae=function(e,t){return w({},e,{context:w({},e.context,{requestPolicy:t})})};function ue(e){return oe(e)}function se(e){return"miss"===e.outcome}function ce(e){return te(e.operation,e.outcome)}function le(e){return"miss"!==e.outcome}function fe(e){return!oe(e)}exports.Store=G,exports.cacheExchange=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new G(e.schema?new $(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),a=new Set,u=new Map,s=Object.create(null),c=function(e,t){var r=new Set;function i(e){return r.add(e)}t.forEach(function(e){var t=s[e];void 0!==t&&(s[e]=[],t.forEach(i))}),r.forEach(function(t){if(t!==e.key){var r=u.get(t);u.delete(t),n.reexecuteOperation(r)}})},l=function(e){if(o=ne(n=e),function(e){return"mutation"===e.operationName}(n)&&"network-only"!==o){var t=e.key,r=N(i,e,t).dependencies;0!==r.size&&(a.add(t),c(e,r))}var n,o},f=function(e,t){t.forEach(function(t){(s[t]||(s[t]=[])).push(e.key),u.has(e.key)||u.set(e.key,"network-only"===e.context.requestPolicy?ae(e,"cache-and-network"):e)})},v=function(e){var t,r=ne(e),n=z(i,e),o=n.data,a=n.partial;return null===o?t="miss":(f(e,n.dependencies),t=a&&"cache-only"!==r?"partial":"hit"),{outcome:t,operation:e,data:o}},d=function(e){var t,r,n=e.operation,o=e.error,u=e.extensions,s=ie(n),l=e.data,v=n.key;if(a.has(v)&&(a.delete(v),i.clearOptimistic(v)),null!=l)if(t=R(i,n,l).dependencies,s){var d=z(i,n);l=d.data,r=d.dependencies}else l=z(i,n,l).data;return void 0!==t&&c(e.operation,t),s&&void 0!==r&&f(e.operation,r),{data:l,error:o,extensions:u,operation:n}};function p(e){var t=e.operation,r=e.outcome,i=ne(t);if("cache-and-network"===i||"cache-first"===i&&"partial"===r){var o=ae(t,"network-only");n.reexecuteOperation(o)}return{operation:te(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=o.pipe(e,o.map(re),o.tap(l),o.share),n=o.pipe(t,o.filter(ue),o.map(v),o.share),i=o.pipe(n,o.filter(se),o.map(ce)),a=o.pipe(n,o.filter(le),o.map(p)),u=o.pipe(r(o.merge([o.pipe(t,o.filter(fe)),i])),o.map(d));return o.merge([u,a])}}},exports.query=z,exports.read=J,exports.write=R,exports.writeFragment=T,exports.writeOptimistic=N;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("graphql"),r=require("urql"),n=require("pessimism"),i=(e=require("fast-json-stable-stringify"))&&"object"==typeof e&&"default"in e?e.default:e,o=require("wonka"),a=function(e){return e.name.value},u=function(e){return void 0!==e.alias?e.alias.value:a(e)},s=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},c=function(e){var t=e.typeCondition;return void 0!==t?a(t):null},l=function(e){return e.kind===t.Kind.FIELD},f=function(e){return e.kind===t.Kind.INLINE_FRAGMENT},v=function(e,r){switch(e.kind){case t.Kind.NULL:return null;case t.Kind.INT:return parseInt(e.value,10);case t.Kind.FLOAT:return parseFloat(e.value);case t.Kind.LIST:for(var n=new Array(e.values.length),i=0,o=e.values.length;i<o;i++)n[i]=v(e.values[i],r);return n;case t.Kind.OBJECT:for(var u=Object.create(null),s=0,c=e.fields.length;s<c;s++){var l=e.fields[s];u[a(l)]=v(l.value,r)}return u;case t.Kind.VARIABLE:var f=r[a(e)];return void 0!==f?f:null;default:return e.value}},d=function(e,t){if(void 0===e.arguments||0===e.arguments.length)return null;for(var r=Object.create(null),n=0,i=e.arguments.length;n<i;n++){var o=e.arguments[n];r[a(o)]=v(o.value,t)}return r},p=function(e,t){if(void 0===e.variableDefinitions)return{};var r=t||{};return e.variableDefinitions.reduce(function(e,t){var n=a(t.variable),i=r[n];if(void 0===i){if(void 0===t.defaultValue)return e;i=v(t.defaultValue,r)}return e[n]=i,e},Object.create(null))},y=function(e){return e.kind===t.Kind.FRAGMENT_DEFINITION};function h(e){return e.kind===t.Kind.OPERATION_DEFINITION}var m=function(e){return e.definitions.find(h)};function g(e,t){return e[a(t)]=t,e}var k=function(e){return e.definitions.filter(y).reduce(g,{})},b=function(e,t){if(void 0===e.directives)return!0;for(var r=e.directives,n=0,i=r.length;n<i;n++){var o=r[n],u=a(o),s="include"===u;if(s||"skip"===u){var c=o.arguments?o.arguments[0]:null;if(c&&"if"===a(c)){var l=v(c.value,t);if("boolean"==typeof l||null===l)return s?!!l:!l}}}return!0},O=function(e,t){return t?e+"("+i(t)+")":e},x=function(e,t){return e+"."+t};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 _=function(e,t,r,n){return!(!t||t!==c(e)&&s(e).some(function(e){if(!l(e))return!1;var t=a(e),i=d(e,n.variables),o=O(t,i);return!n.store.hasField(x(r,o))}))},q=function(e,t,r,n){this.typename=e,this.entityKey=t,this.context=n,this.indexStack=[0],this.selectionStack=[r]};q.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(b(r,this.context.variables)){if(l(r)){if("__typename"===a(r))continue;return r}var n=f(r)?r:this.context.fragments[a(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(c(n),this.typename):_(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(s(n)))}}}};var S=function(e){return Array.isArray(e)?e.some(S):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},R=function(e,t,r){M(0);var n=A(e,t,r);return Q(),n},A=function(e,t,r){var n=m(t.query),i={dependencies:D()},o={variables:p(n,t.variables),fragments:k(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},a=s(n),u=o.store.getRootKey(n.operation);return u===o.store.getRootKey("query")?F(o,u,a,r):L(o,u,a,r),i},N=function(e,t,r){M(r);var n=m(t.query),i={dependencies:D()},o={variables:p(n,t.variables),fragments:k(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates},u=o.store.getRootKey(n.operation);if(u===o.store.getRootKey("mutation"))for(var c,l=s(n),f=new q(u,u,l,o);void 0!==(c=f.next());)if(void 0!==c.selectionSet){var v=a(c),y=o.store.optimisticMutations[v];if(void 0!==y){var h=d(c,o.variables),g=s(c),b=y(h||{},o.store,o);S(b)||P(o,b,g)}}return Q(),i},T=function(e,t,r){var n=k(t),i=n[Object.keys(n)[0]];if(void 0!==i){var o=s(i),a=w({},r,{__typename:i.typeCondition.name.value}),u=e.keyOfEntity(a);if(u){var c={variables:{},fragments:n,result:{dependencies:D()},store:e,schemaPredicates:e.schemaPredicates};F(c,u,o,a)}}},F=function(e,t,r,n){var i=e.store,o=e.variables,c=t===e.store.getRootKey("query"),l=n.__typename;c||V(t),i.writeField(c?t:l,t,"__typename");for(var f,v=new q(l,t,r,e);void 0!==(f=v.next());){var p=a(f),y=d(f,o),h=x(t,O(p,y)),m=n[u(f)];if(c&&V(h),void 0===f.selectionSet)i.writeRecord(m,h);else if(S(m))i.writeRecord(m,h);else{var g=s(f),k=K(e,h,g,m);i.writeLink(k,h),i.removeRecord(h)}}},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 u=n[o],s=x(t,""+o),c=K(e,s,r,u);i[o]=c}return i}if(null===n)return null;var l=e.store.keyOfEntity(n),f=null!==l?l:t;return F(e,f,r,n),f},L=function(e,t,r,n){for(var i,o=new q(t,t,r,e);void 0!==(i=o.next());){var c=a(i),l=u(i),f=d(i,e.variables),v=n[l];if(void 0!==i.selectionSet&&null!==v&&!S(v)){var p=s(i);P(e,v,p)}if(t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription")){var y=e.store.updates[t][c];void 0!==y&&y(n,f||{},e.store,e)}}},P=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]=P(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?F(e,a,r,t):L(e,t.__typename,r,t)}},E=function(e,t,r){var n,i=e.store,o=e.variables,u="Query"===t;if(u)n=t;else{if(V(t),"string"!=typeof(n=i.getField(t,"__typename")))return;i.removeRecord(x(t,O("__typename")))}for(var c,l=new q(n,t,r,e);void 0!==(c=l.next());){var f=a(c),v=d(c,o),p=x(t,O(f,v));if(u&&V(p),void 0===c.selectionSet)i.removeRecord(p);else{var y=s(c),h=i.getLink(p);if(i.removeLink(p),void 0===h)void 0!==i.getRecord(p)&&i.removeRecord(p);else if(Array.isArray(h))for(var m=0,g=h.length;m<g;m++){var k=h[m];null!==k&&E(e,k,y)}else null!==h&&E(e,h,y)}}},j={current:null},I={current:null},M=function(e){j.current=new Set,I.current=e},Q=function(){j.current=null,I.current=null},D=function(){return j.current},V=function(e){j.current.add(e)},C=function(e,t,r){return n.setOptimistic(e,t,r,I.current||0)},B=function(e,t){var r=I.current||0;return r?n.setOptimistic(e,t,void 0,r):n.remove(e,t)},G=function(e,t,r,i,o){var a;if(this.records=n.asMutable(n.make()),this.links=n.asMutable(n.make()),this.resolvers=t||{},this.optimisticMutations=i||{},this.keys=o||{},this.schemaPredicates=e,this.updates={Mutation:r&&r.Mutation||{},Subscription:r&&r.Subscription||{}},e){var u=e.schema,s=u.getQueryType(),c=u.getMutationType(),l=u.getSubscriptionType(),f=s?s.name:"Query",v=c?c.name:"Mutation",d=l?l.name:"Subscription";this.rootFields={query:f,mutation:v,subscription:d},this.rootNames=((a={})[f]="query",a[v]="mutation",a[d]="subscription",a)}else this.rootFields={query:"Query",mutation:"Mutation",subscription:"Subscription"},this.rootNames={Query:"query",Mutation:"mutation",Subscription:"subscription"}};G.prototype.getRootKey=function(e){return this.rootFields[e]},G.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;if(!r)return null;if(this.rootNames[r])return this.rootNames[r];if(this.keys[r])t=this.keys[r](e);else if(null!=n)t=""+n;else{if(null==i)return null;t=""+i}return t?r+":"+t:null},G.prototype.clearOptimistic=function(e){this.records=n.clearOptimistic(this.records,e),this.links=n.clearOptimistic(this.links,e)},G.prototype.getRecord=function(e){return n.get(this.records,e)},G.prototype.removeRecord=function(e){return this.records=B(this.records,e)},G.prototype.writeRecord=function(e,t){return this.records=C(this.records,t,e)},G.prototype.getField=function(e,t,r){var n=x(e,O(t,r));return this.getRecord(n)},G.prototype.writeField=function(e,t,r,n){var i=x(t,O(r,n));return this.records=C(this.records,i,e)},G.prototype.getLink=function(e){return n.get(this.links,e)},G.prototype.removeLink=function(e){return this.links=B(this.links,e)},G.prototype.writeLink=function(e,t){return this.links=C(this.links,t,e)},G.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},G.prototype.resolve=function(e,t,r){if("string"==typeof e)return V(e),this.resolveValueOrLink(x(e,O(t,r)));var n=this.keyOfEntity(e);return null===n?null:(V(n),this.resolveValueOrLink(x(n,O(t,r))))},G.prototype.invalidateQuery=function(e,t){!function(e,t){M(0);var r=m(t.query),n={variables:p(r,t.variables),fragments:k(t.query),store:e,schemaPredicates:e.schemaPredicates};E(n,n.store.getRootKey("query"),s(r)),Q()}(this,{query:e,variables:t})},G.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},G.prototype.updateQuery=function(e,t){var n=r.createRequest(e.query,e.variables),i=t(J(this,n).data);null!==i&&A(this,n,i)},G.prototype.writeFragment=function(e,t){T(this,e,t)};var z=function(e,t,r){M(0);var n=J(e,t,r);return Q(),n},J=function(e,t,r){var n=m(t.query),i=e.getRootKey(n.operation),o=s(n),a={variables:p(n,t.variables),fragments:k(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},u=r||Object.create(null);return u="Query"!==i?U(a,i,o,u):W(a,i,o,u),{dependencies:D(),partial:void 0!==u&&a.partial,data:void 0===u?null:u}},U=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 q(t,t,r,e);void 0!==(o=a.next());){var c=u(o),l=n[c];i[c]=void 0===o.selectionSet||null===l||S(l)?l:H(e,s(o),l)}return i},H=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]=H(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var u=Object.create(null),s=W(e,a,t,u);return void 0===s?null:s}return U(e,r.__typename,t,r)},W=function(e,t,r,n){var i=e.store,o=e.variables,c=e.schemaPredicates,l=t===i.getRootKey("query");l||V(t);var f=l?t:i.getField(t,"__typename");if("string"==typeof f){n.__typename=f;for(var v,p=new q(f,t,r,e),y=!1,h=!1;void 0!==(v=p.next());){var m=a(v),g=d(v,o),k=u(v),b=x(t,O(m,g)),w=i.getRecord(b);l&&V(b);var _=void 0,S=i.resolvers[f];if(void 0!==S&&"function"==typeof S[m]){void 0!==w&&(n[k]=w);var R=S[m](n,g||{},i,e);void 0!==v.selectionSet&&(R=X(e,R,f,m,b,s(v),n[k]));var A=null==R;_=A&&void 0!==c?void 0:A?null:R}else if(void 0===v.selectionSet)_=w;else{var N=s(v),T=i.getLink(b);void 0!==T?_=Y(e,T,f,m,N,n[k]):"object"==typeof w&&null!==w&&(_=w)}if(void 0===_&&void 0!==c&&c.isFieldNullable(f,m))h=!0,n[k]=null;else{if(void 0===_)return;y=!0,n[k]=_}}return h&&(e.partial=!0),l&&h&&!y?void 0:n}},X=function(e,t,r,n,i,o,a){if(Array.isArray(t)){for(var u=e.schemaPredicates,s=void 0!==u&&u.isListNullable(r,n),c=new Array(t.length),l=0,f=t.length;l<f;l++){var v=void 0!==a?a[l]:void 0,d=x(i,""+l),p=X(e,t[l],r,n,d,o,v);if(void 0===p&&!s)return;t[l]=void 0!==p?p:null}return c}if(null===t)return null;if(Z(t)){var y=void 0===a?Object.create(null):a,h=("string"==typeof t?t:e.store.keyOfEntity(t))||i;return W(e,h,o,y)}},Y=function(e,t,r,n,i,o){if(Array.isArray(t)){for(var a=e.schemaPredicates,u=void 0!==a&&a.isListNullable(r,n),s=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&&!u)return;s[c]=void 0!==f?f:null}return s}if(null===t)return null;var v=void 0===o?Object.create(null):o;return W(e,t,i,v)},Z=function(e){return"string"==typeof e||"object"==typeof e&&null!==e&&"string"==typeof e.__typename},$=function(e){this.schema=t.buildClientSchema(e)};$.prototype.isFieldNullable=function(e,r){var n=ee(this.schema,e,r);return void 0!==n&&t.isNullableType(n.type)},$.prototype.isListNullable=function(e,r){var n=ee(this.schema,e,r);if(void 0===n)return!1;var i=t.isNonNullType(n.type)?n.type.ofType:n.type;return t.isListType(i)&&t.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),n=this.schema.getType(t);return this.schema.isPossibleType(r,n)};var ee=function(e,t,r){var n=e.getType(t);if(void 0!==n){var i=n.getFields()[r];if(void 0!==i)return i}},te=function(e,t){return w({},e,{context:w({},e.context,{meta:w({},e.context.meta,{cacheOutcome:t})})})},re=function(e){return w({},e,{query:r.formatDocument(e.query)})},ne=function(e){return e.context.requestPolicy},ie=function(e){return"query"===e.operationName},oe=function(e){var t=ne(e);return ie(e)&&"network-only"!==t},ae=function(e,t){return w({},e,{context:w({},e.context,{requestPolicy:t})})};function ue(e){return oe(e)}function se(e){return"miss"===e.outcome}function ce(e){return te(e.operation,e.outcome)}function le(e){return"miss"!==e.outcome}function fe(e){return!oe(e)}exports.Store=G,exports.cacheExchange=function(e){return function(t){var r=t.forward,n=t.client;e||(e={});var i=new G(e.schema?new $(e.schema):void 0,e.resolvers,e.updates,e.optimistic,e.keys),a=new Set,u=new Map,s=Object.create(null),c=function(e,t){var r=new Set;function i(e){return r.add(e)}t.forEach(function(e){var t=s[e];void 0!==t&&(s[e]=[],t.forEach(i))}),r.forEach(function(t){if(t!==e.key){var r=u.get(t);void 0!==r&&(u.delete(t),n.reexecuteOperation(r))}})},l=function(e){if(o=ne(n=e),function(e){return"mutation"===e.operationName}(n)&&"network-only"!==o){var t=e.key,r=N(i,e,t).dependencies;0!==r.size&&(a.add(t),c(e,r))}var n,o},f=function(e,t){t.forEach(function(t){(s[t]||(s[t]=[])).push(e.key),u.has(e.key)||u.set(e.key,"network-only"===e.context.requestPolicy?ae(e,"cache-and-network"):e)})},v=function(e){var t,r=ne(e),n=z(i,e),o=n.data,a=n.partial;return null===o?t="miss":(f(e,n.dependencies),t=a&&"cache-only"!==r?"partial":"hit"),{outcome:t,operation:e,data:o}},d=function(e){var t,r,n=e.operation,o=e.error,u=e.extensions,s=ie(n),l=e.data,v=n.key;if(a.has(v)&&(a.delete(v),i.clearOptimistic(v)),null!=l)if(t=R(i,n,l).dependencies,s){var d=z(i,n);l=d.data,r=d.dependencies}else l=z(i,n,l).data;return void 0!==t&&c(e.operation,t),s&&void 0!==r&&f(e.operation,r),{data:l,error:o,extensions:u,operation:n}};function p(e){var t=e.operation,r=e.outcome,i=ne(t);if("cache-and-network"===i||"cache-first"===i&&"partial"===r){var o=ae(t,"network-only");n.reexecuteOperation(o)}return{operation:te(t,r),data:e.data,error:e.error,extensions:e.extensions}}return function(e){var t=o.pipe(e,o.map(re),o.tap(l),o.share),n=o.pipe(t,o.filter(ue),o.map(v),o.share),i=o.pipe(n,o.filter(se),o.map(ce)),a=o.pipe(n,o.filter(le),o.map(p)),u=o.pipe(r(o.merge([o.pipe(t,o.filter(fe)),i])),o.map(d));return o.merge([u,a])}}},exports.query=z,exports.read=J,exports.write=R,exports.writeFragment=T,exports.writeOptimistic=N;
//# sourceMappingURL=urql-exchange-graphcache.min.js.map
{
"name": "@urql/exchange-graphcache",
"version": "1.0.0-rc.5",
"version": "1.0.0-rc.6",
"description": "A normalized and configurable cache exchange for urql",

@@ -5,0 +5,0 @@ "repository": "https://github.com/FormidableLabs/urql-exchange-graphcache",

@@ -132,5 +132,7 @@ import {

if (key !== triggerOp.key) {
const op = ops.get(key) as Operation;
ops.delete(key);
client.reexecuteOperation(op);
const op = ops.get(key);
if (op !== undefined) {
ops.delete(key);
client.reexecuteOperation(op);
}
}

@@ -137,0 +139,0 @@ });

@@ -140,2 +140,19 @@ import { Store } from '../store';

});
it('should skip undefined values that are expected', () => {
const query = gql`
{
field
}
`;
write(store, { query }, { field: 'test' } as any);
// This should not overwrite the field
write(store, { query }, { field: undefined } as any);
// Because of us writing an undefined field
expect(console.warn).toHaveBeenCalledTimes(1);
expect((console.warn as any).mock.calls[0][0]).toMatch(/undefined/);
// The field must still be `'test'`
expect(store.getRecord('Query.field')).toBe('test');
});
});

@@ -46,2 +46,3 @@ import { warning } from '../helpers/warning';

fragments: Fragments;
isOptimistic?: boolean;
schemaPredicates?: SchemaPredicates;

@@ -57,7 +58,4 @@ }

initStoreState(0);
const result = startWrite(store, request, data);
clearStoreState();
return result;

@@ -112,2 +110,6 @@ };

if (process.env.NODE_ENV === 'development') {
ctx.isOptimistic = true;
}
const operationName = ctx.store.getRootKey(operation.operation);

@@ -210,8 +212,27 @@ if (operationName === ctx.store.getRootKey('mutation')) {

if (
process.env.NODE_ENV !== 'production' &&
ctx.schemaPredicates &&
typename
) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
if (process.env.NODE_ENV !== 'production') {
if (fieldValue === undefined) {
const advice = ctx.isOptimistic
? '\nYour optimistic result may be missing a field!'
: '';
const expected =
node.selectionSet === undefined
? 'scalar (number, boolean, etc)'
: 'selection set';
warning(
false,
'Invalid value: The field at `' +
fieldKey +
'` is `undefined`, but the GraphQL query expects a ' +
expected +
' for this field.' +
advice
);
continue; // Skip this field
} else if (ctx.schemaPredicates && typename) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
}

@@ -218,0 +239,0 @@

import invariant from 'invariant';
import { DocumentNode } from 'graphql';
import { createRequest } from 'urql';
import * as Pessimism from 'pessimism';

@@ -255,8 +256,9 @@

updateQuery(
ctx: { query: DocumentNode; variables?: Variables },
input: { query: string | DocumentNode; variables?: Variables },
updater: (data: Data | null) => null | Data
): void {
const output = updater(read(this, ctx).data);
const request = createRequest(input.query, input.variables);
const output = updater(read(this, request).data);
if (output !== null) {
startWrite(this, ctx, output);
startWrite(this, request, output);
}

@@ -263,0 +265,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc