Socket
Socket
Sign inDemoInstall

@urql/exchange-graphcache

Package Overview
Dependencies
Maintainers
4
Versions
296
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-graphcache - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2-fast

dist/types/map.d.ts

3

dist/types/ast/node.d.ts
import { NamedTypeNode, NameNode, SelectionNode, SelectionSetNode, InlineFragmentNode, FieldNode, FragmentDefinitionNode } from 'graphql';
import { SelectionSet } from '../types';
/** Returns the name of a given node */

@@ -13,3 +12,3 @@ export declare const getName: (node: {

selectionSet?: SelectionSetNode | undefined;
}) => SelectionSet;
}) => readonly SelectionNode[];
export declare const getTypeCondition: ({ typeCondition, }: {

@@ -16,0 +15,0 @@ typeCondition?: NamedTypeNode | undefined;

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

import { OperationRequest, Variables, Fragments, SelectionSet } from '../types';
import { OperationRequest, Variables, Fragments } from '../types';
import { Store } from '../store';

@@ -11,3 +11,3 @@ import { SchemaPredicates } from '../ast/schemaPredicates';

export declare const invalidate: (store: Store, request: OperationRequest) => void;
export declare const invalidateSelection: (ctx: Context, entityKey: string, select: SelectionSet) => void;
export declare const invalidateSelection: (ctx: Context, entityKey: string, select: readonly import("graphql").SelectionNode[]) => void;
export {};
import { DocumentNode } from 'graphql';
import * as Pessimism from 'pessimism';
import { Cache, EntityField, Link, Connection, ResolverConfig, DataField, Variables, Data, QueryInput, UpdatesConfig, OptimisticMutationConfig, KeyingConfig } from './types';
import * as KVMap from './map';
import { SchemaPredicates } from './ast/schemaPredicates';

@@ -11,5 +11,5 @@ export declare const initStoreState: (optimisticKey: number | null) => void;

export declare class Store implements Cache {
records: Pessimism.Map<EntityField>;
connections: Pessimism.Map<Connection[]>;
links: Pessimism.Map<Link>;
records: KVMap.KVMap<EntityField>;
connections: KVMap.KVMap<Connection[]>;
links: KVMap.KVMap<Link>;
resolvers: ResolverConfig;

@@ -33,10 +33,10 @@ updates: UpdatesConfig;

getRecord(fieldKey: string): EntityField;
removeRecord(fieldKey: string): Pessimism.Map<EntityField>;
writeRecord(field: EntityField, fieldKey: string): Pessimism.Map<EntityField>;
removeRecord(fieldKey: string): KVMap.KVMap<EntityField>;
writeRecord(field: EntityField, fieldKey: string): KVMap.KVMap<EntityField>;
getField(entityKey: string, fieldName: string, args?: Variables): EntityField;
writeField(field: EntityField, entityKey: string, fieldName: string, args?: Variables): Pessimism.Map<EntityField>;
writeField(field: EntityField, entityKey: string, fieldName: string, args?: Variables): KVMap.KVMap<EntityField>;
getLink(key: string): undefined | Link;
removeLink(key: string): Pessimism.Map<Link<string>>;
writeLink(link: Link, key: string): Pessimism.Map<Link<string>>;
writeConnection(key: string, linkKey: string, args: Variables | null): Pessimism.Map<Connection[]>;
removeLink(key: string): KVMap.KVMap<Link<string>>;
writeLink(link: Link, key: string): KVMap.KVMap<Link<string>>;
writeConnection(key: string, linkKey: string, args: Variables | null): KVMap.KVMap<[Variables, string][]>;
resolveValueOrLink(fieldKey: string): DataField;

@@ -43,0 +43,0 @@ resolve(entity: Data | string | null, field: string, args?: Variables): DataField;

@@ -5,4 +5,2 @@ import { Kind, valueFromASTUntyped, buildClientSchema, isNullableType, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType } from "graphql";

import { asMutable, make, clearOptimistic, get, setOptimistic, remove } from "pessimism";
import { share, tap, map, filter, merge } from "wonka";

@@ -183,2 +181,29 @@

var make = function() {
return {
optimistic: Object.create(null),
base: new Map,
keys: []
};
};
var clear = function(map, optimisticKey) {
var index = map.keys.indexOf(optimisticKey);
if (index > -1) {
delete map.optimistic[optimisticKey];
map.keys.splice(index, 1);
}
return map;
};
var get = function(map, key) {
for (var i = 0, l = map.keys.length; i < l; i++) {
var optimistic = map.optimistic[map.keys[i]];
if (optimistic.has(key)) {
return optimistic.get(key);
}
}
return map.base.get(key);
};
var keyOfField = function(fieldName, args) {

@@ -568,8 +593,29 @@ return args ? fieldName + "(" + stringifyVariables(args) + ")" : fieldName;

var mapSet = function(map, key, value) {
return setOptimistic(map, key, value, currentOptimisticKey.current || 0);
return function(map, key, value, optimisticKey) {
if (0 !== optimisticKey) {
if (void 0 === map.optimistic[optimisticKey]) {
map.optimistic[optimisticKey] = new Map;
map.keys.unshift(optimisticKey);
}
map.optimistic[optimisticKey].set(key, value);
} else {
map.base.set(key, value);
}
return map;
}(map, key, value, currentOptimisticKey.current || 0);
};
var mapRemove = function(map, key) {
var optimisticKey = currentOptimisticKey.current || 0;
return optimisticKey ? setOptimistic(map, key, void 0, optimisticKey) : remove(map, key);
return function(map, key, optimisticKey) {
if (0 !== optimisticKey) {
if (void 0 === map.optimistic[optimisticKey]) {
map.optimistic[optimisticKey] = new Map;
map.keys.unshift(optimisticKey);
}
map.optimistic[optimisticKey].set(key, void 0);
} else {
map.base.delete(key);
}
return map;
}(map, key, currentOptimisticKey.current || 0);
};

@@ -579,5 +625,5 @@

var obj;
this.records = asMutable(make());
this.connections = asMutable(make());
this.links = asMutable(make());
this.records = make();
this.connections = make();
this.links = make();
this.resolvers = resolvers || {};

@@ -644,6 +690,6 @@ this.optimisticMutations = optimisticMutations || {};

Store.prototype.clearOptimistic = function clearOptimistic$1(optimisticKey) {
this.records = clearOptimistic(this.records, optimisticKey);
this.connections = clearOptimistic(this.connections, optimisticKey);
this.links = clearOptimistic(this.links, optimisticKey);
Store.prototype.clearOptimistic = function clearOptimistic(optimisticKey) {
this.records = clear(this.records, optimisticKey);
this.connections = clear(this.connections, optimisticKey);
this.links = clear(this.links, optimisticKey);
};

@@ -650,0 +696,0 @@

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

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

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

@@ -185,2 +183,29 @@

var make = function() {
return {
optimistic: Object.create(null),
base: new Map,
keys: []
};
};
var clear = function(map, optimisticKey) {
var index = map.keys.indexOf(optimisticKey);
if (index > -1) {
delete map.optimistic[optimisticKey];
map.keys.splice(index, 1);
}
return map;
};
var get = function(map, key) {
for (var i = 0, l = map.keys.length; i < l; i++) {
var optimistic = map.optimistic[map.keys[i]];
if (optimistic.has(key)) {
return optimistic.get(key);
}
}
return map.base.get(key);
};
var keyOfField = function(fieldName, args) {

@@ -570,8 +595,29 @@ return args ? fieldName + "(" + urql.stringifyVariables(args) + ")" : fieldName;

var mapSet = function(map, key, value) {
return Pessimism.setOptimistic(map, key, value, currentOptimisticKey.current || 0);
return function(map, key, value, optimisticKey) {
if (0 !== optimisticKey) {
if (void 0 === map.optimistic[optimisticKey]) {
map.optimistic[optimisticKey] = new Map;
map.keys.unshift(optimisticKey);
}
map.optimistic[optimisticKey].set(key, value);
} else {
map.base.set(key, value);
}
return map;
}(map, key, value, currentOptimisticKey.current || 0);
};
var mapRemove = function(map, key) {
var optimisticKey = currentOptimisticKey.current || 0;
return optimisticKey ? Pessimism.setOptimistic(map, key, void 0, optimisticKey) : Pessimism.remove(map, key);
return function(map, key, optimisticKey) {
if (0 !== optimisticKey) {
if (void 0 === map.optimistic[optimisticKey]) {
map.optimistic[optimisticKey] = new Map;
map.keys.unshift(optimisticKey);
}
map.optimistic[optimisticKey].set(key, void 0);
} else {
map.base.delete(key);
}
return map;
}(map, key, currentOptimisticKey.current || 0);
};

@@ -581,5 +627,5 @@

var obj;
this.records = Pessimism.asMutable(Pessimism.make());
this.connections = Pessimism.asMutable(Pessimism.make());
this.links = Pessimism.asMutable(Pessimism.make());
this.records = make();
this.connections = make();
this.links = make();
this.resolvers = resolvers || {};

@@ -647,9 +693,9 @@ this.optimisticMutations = optimisticMutations || {};

Store.prototype.clearOptimistic = function clearOptimistic(optimisticKey) {
this.records = Pessimism.clearOptimistic(this.records, optimisticKey);
this.connections = Pessimism.clearOptimistic(this.connections, optimisticKey);
this.links = Pessimism.clearOptimistic(this.links, optimisticKey);
this.records = clear(this.records, optimisticKey);
this.connections = clear(this.connections, optimisticKey);
this.links = clear(this.links, optimisticKey);
};
Store.prototype.getRecord = function getRecord(fieldKey) {
return Pessimism.get(this.records, fieldKey);
return get(this.records, fieldKey);
};

@@ -674,3 +720,3 @@

Store.prototype.getLink = function getLink(key) {
return Pessimism.get(this.links, key);
return get(this.links, key);
};

@@ -690,3 +736,3 @@

}
var connections = Pessimism.get(this.connections, key);
var connections = get(this.connections, key);
var connection = [ args, linkKey ];

@@ -734,3 +780,3 @@ if (void 0 === connections) {

if ("string" == typeof entity) {
connections = Pessimism.get(this.connections, joinKeys(entity, field));
connections = get(this.connections, joinKeys(entity, field));
} else if (null !== entity) {

@@ -740,3 +786,3 @@ var entityKey = this.keyOfEntity(entity);

addDependency(entityKey);
connections = Pessimism.get(this.connections, joinKeys(entityKey, field));
connections = get(this.connections, joinKeys(entityKey, field));
}

@@ -743,0 +789,0 @@ }

@@ -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):j(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(_)||A(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},j=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)||A(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)}}},A=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]=A(e,t[i],r);return n}if(null!==t){var a=e.store.keyOfEntity(t);null!==a?R(e,a,r,t):j(e,t.__typename,r,t)}},L=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&&L(e,m,v)}else null!==d&&L(e,d,v)}}},P={current:null},E={current:null},M=function(e){P.current=new Set,E.current=e},I=function(){P.current=null,E.current=null},Q=function(){return d(null!==(e=P).current,"",2),e.current;var e},C=function(e){P.current.add(e)},G=function(e,t,n){return r.setOptimistic(e,t,n,E.current||0)},D=function(e,t){var n=E.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?void 0!==this.rootNames[r]?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=D(this.records,e)},V.prototype.writeRecord=function(e,t){return this.records=G(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=G(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=D(this.links,e)},V.prototype.writeLink=function(e,t){return this.links=G(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=G(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};L(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(t,r){if(!r||!t)return!1;if(r===t)return!0;var n=this.schema.getType(t),i=this.schema.getType(r);return n instanceof e.GraphQLObjectType?n===i:(re(n),te(i),this.schema.isPossibleType(n,i))};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;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("graphql"),t=require("urql"),r=require("wonka");function n(){return(n=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 i=function(e){return e.name.value},o=function(e){return e.typeCondition.name.value},a=function(e){return void 0!==e.alias?e.alias.value:i(e)},s=function(e){return void 0!==e.selectionSet?e.selectionSet.selections:[]},u=function(e){var t=e.typeCondition;return void 0!==t?i(t):null},c=function(t){return t.kind===e.Kind.FIELD},l=function(t){return t.kind===e.Kind.INLINE_FRAGMENT},f=function(t,r){if(void 0===t.arguments||0===t.arguments.length)return null;for(var n=Object.create(null),o=0,a=0,s=t.arguments.length;a<s;a++){var u=t.arguments[a],c=e.valueFromASTUntyped(u.value,r);null!=c&&(n[i(u)]=c,o++)}return o>0?n:null},p=function(t,r){if(void 0===t.variableDefinitions)return{};var n=r||{};return t.variableDefinitions.reduce((function(t,r){var o=i(r.variable),a=n[o];if(void 0===a){if(void 0===r.defaultValue)return t;a=e.valueFromASTUntyped(r.defaultValue,n)}return t[o]=a,t}),Object.create(null))},v=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}},d=function(t){return t.kind===e.Kind.FRAGMENT_DEFINITION};function y(t){return t.kind===e.Kind.OPERATION_DEFINITION}var h=function(e){var t=e.definitions.find(y);return v(!!t,"",1),t};function m(e,t){return e[i(t)]=t,e}var g=function(e){return e.definitions.filter(d).reduce(m,{})},b=function(t,r){var n=t.directives;if(void 0===n)return!0;for(var o=0,a=n.length;o<a;o++){var s=n[o],u=i(s),c="include"===u;if(c||"skip"===u){var l=s.arguments?s.arguments[0]:null;if(l&&"if"===i(l)){var f=e.valueFromASTUntyped(l.value,r);if("boolean"==typeof f||null===f)return c?!!f:!f}}}return!0},k=function(){return{optimistic:Object.create(null),base:new Map,keys:[]}},_=function(e,t){var r=e.keys.indexOf(t);return r>-1&&(delete e.optimistic[t],e.keys.splice(r,1)),e},O=function(e,t){for(var r=0,n=e.keys.length;r<n;r++){var i=e.optimistic[e.keys[r]];if(i.has(t))return i.get(t)}return e.base.get(t)},w=function(e,r){return r?e+"("+t.stringifyVariables(r)+")":e},x=function(e,t){return e+"."+t},N=function(e,t,r,n){return!(!t||t!==u(e)&&s(e).some((function(e){if(!c(e))return!1;var t=w(i(e),f(e,n.variables));return!n.store.hasField(x(r,t))})))},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(c(r)){if("__typename"===i(r))continue;return r}var n=l(r)?r:this.context.fragments[i(r)];void 0!==n&&(void 0!==this.context.schemaPredicates?this.context.schemaPredicates.isInterfaceOfType(u(n),this.typename):N(n,this.typename,this.entityKey,this.context))&&(this.indexStack.push(0),this.selectionStack.push(s(n)))}}}};var F=function(e){return Array.isArray(e)?e.some(F):"object"!=typeof e||null!==e&&"string"!=typeof e.__typename},T=function(e,t,r){Q(0);var n=q(e,t,r);return C(),n},q=function(e,t,r){var n=h(t.query),i={dependencies:G()},o=s(n),a=e.getRootKey(n.operation),u={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:p(n,t.variables),fragments:g(t.query),result:i,store:e,schemaPredicates:e.schemaPredicates};return a===u.store.getRootKey("query")?j(u,a,o,r):L(u,a,o,r),i},R=function(e,t,r){Q(r);var n=h(t.query),o={dependencies:G()},a=e.getRootKey("mutation"),u=e.getRootKey(n.operation);v(u===a,"",10);for(var c,l={parentTypeName:a,parentKey:a,parentFieldKey:"",fieldName:"",variables:p(n,t.variables),fragments:g(t.query),result:o,store:e,schemaPredicates:e.schemaPredicates,optimistic:!0},d=Object.create(null),y=new S(u,u,s(n),l);void 0!==(c=y.next());)if(void 0!==c.selectionSet){var m=i(c),b=l.store.optimisticMutations[m];if(void 0!==b){l.fieldName=m;var k=f(c,l.variables),_=b(k||Object.create(null),l.store,l);F(_)||P(l,_,s(c)),d[m]=_;var O=l.store.updates[a][m];void 0!==O&&O(d,k||Object.create(null),l.store,l)}}return C(),o},K=function(e,t,r,i){var a=g(t),u=a[Object.keys(a)[0]];if(void 0!==u){var c=o(u),l=n({__typename:c},r),f=e.keyOfEntity(l);if(f){var p={parentTypeName:c,parentKey:f,parentFieldKey:"",fieldName:"",variables:i||{},fragments:a,result:{dependencies:G()},store:e,schemaPredicates:e.schemaPredicates};j(p,f,s(u),l)}}},j=function(e,t,r,n){var o=e.store,u=t===e.store.getRootKey("query"),c=n.__typename;u||D(t),o.writeField(u?t:c,t,"__typename");for(var l,p=new S(c,t,r,e);void 0!==(l=p.next());){var v=i(l),d=f(l,e.variables),y=x(t,w(v,d)),h=n[a(l)];if(u&&D(y),void 0===l.selectionSet)o.writeRecord(h,y);else if(F(h))o.writeRecord(h,y);else{var m=A(e,y,s(l),h);o.writeConnection(x(t,v),y,d),o.writeLink(m,y),o.removeRecord(y)}}},A=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=x(t,""+o),c=A(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"),j(e,f,r,n),f},L=function(e,t,r,n){for(var o,u=t===e.store.getRootKey("mutation")||t===e.store.getRootKey("subscription"),c=new S(t,t,r,e);void 0!==(o=c.next());){var l=i(o),p=f(o,e.variables),v=n[a(o)];if(void 0===o.selectionSet||null===v||F(v)||P(e,v,s(o)),u){e.parentTypeName=t,e.parentKey=t,e.parentFieldKey=x(t,w(l,p)),e.fieldName=l;var d=e.store.updates[t][l];void 0!==d&&d(n,p||Object.create(null),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?j(e,a,r,t):L(e,t.__typename,r,t)}},E=function(e,t,r){var n,o=e.store,a="Query"===t;if(a)n=t;else{if(D(t),"string"!=typeof(n=o.getField(t,"__typename")))return;o.removeRecord(x(t,w("__typename")))}for(var u,c=new S(n,t,r,e);void 0!==(u=c.next());){var l=i(u),p=x(t,w(l,f(u,e.variables)));if(a&&D(p),void 0===u.selectionSet)o.removeRecord(p);else{var v=s(u),d=o.getLink(p);if(o.removeLink(p),void 0===d)void 0!==o.getRecord(p)&&o.removeRecord(p);else if(Array.isArray(d))for(var y=0,h=d.length;y<h;y++){var m=d[y];null!==m&&E(e,m,v)}else null!==d&&E(e,d,v)}}},M={current:null},I={current:null},Q=function(e){M.current=new Set,I.current=e},C=function(){M.current=null,I.current=null},G=function(){return v(null!==(e=M).current,"",2),e.current;var e},D=function(e){M.current.add(e)},V=function(e,t,r){return function(e,t,r,n){return 0!==n?(void 0===e.optimistic[n]&&(e.optimistic[n]=new Map,e.keys.unshift(n)),e.optimistic[n].set(t,r)):e.base.set(t,r),e}(e,t,r,I.current||0)},U=function(e,t){return function(e,t,r){return 0!==r?(void 0===e.optimistic[r]&&(e.optimistic[r]=new Map,e.keys.unshift(r)),e.optimistic[r].set(t,void 0)):e.base.delete(t),e}(e,t,I.current||0)},W=function(e,t,r,n,i){var o;if(this.records=k(),this.connections=k(),this.links=k(),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"}};W.prototype.getRootKey=function(e){return this.rootFields[e]},W.prototype.keyOfEntity=function(e){var t,r=e.__typename,n=e.id,i=e._id;return r?void 0!==this.rootNames[r]?r:(this.keys[r]?t=this.keys[r](e):null!=n?t=""+n:null!=i&&(t=""+i),t?r+":"+t:null):null},W.prototype.clearOptimistic=function(e){this.records=_(this.records,e),this.connections=_(this.connections,e),this.links=_(this.links,e)},W.prototype.getRecord=function(e){return O(this.records,e)},W.prototype.removeRecord=function(e){return this.records=U(this.records,e)},W.prototype.writeRecord=function(e,t){return this.records=V(this.records,t,e)},W.prototype.getField=function(e,t,r){return this.getRecord(x(e,w(t,r)))},W.prototype.writeField=function(e,t,r,n){return this.records=V(this.records,x(t,w(r,n)),e)},W.prototype.getLink=function(e){return O(this.links,e)},W.prototype.removeLink=function(e){return this.links=U(this.links,e)},W.prototype.writeLink=function(e,t){return this.links=V(this.links,t,e)},W.prototype.writeConnection=function(e,t,r){if(void 0!==this.getLink(t)||null===r)return this.connections;var n=O(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=V(this.connections,e,n)},W.prototype.resolveValueOrLink=function(e){var t=this.getRecord(e);return void 0!==t?t:this.getLink(e)||null},W.prototype.resolve=function(e,t,r){if(null===e)return null;if("string"==typeof e)return D(e),this.resolveValueOrLink(x(e,w(t,r)));var n=this.keyOfEntity(e);return null===n?null:(D(n),this.resolveValueOrLink(x(n,w(t,r))))},W.prototype.resolveConnections=function(e,t){var r;if("string"==typeof e)r=O(this.connections,x(e,t));else if(null!==e){var n=this.keyOfEntity(e);null!==n&&(D(n),r=O(this.connections,x(n,t)))}return void 0!==r?r:[]},W.prototype.invalidateQuery=function(e,r){!function(e,t){Q(0);var r=h(t.query),n={variables:p(r,t.variables),fragments:g(t.query),store:e,schemaPredicates:e.schemaPredicates};E(n,n.store.getRootKey("query"),s(r)),C()}(this,t.createRequest(e,r))},W.prototype.hasField=function(e){return void 0!==this.getRecord(e)||void 0!==this.getLink(e)},W.prototype.updateQuery=function(e,r){var n=t.createRequest(e.query,e.variables),i=r(this.readQuery(n));null!==i&&q(this,n,i)},W.prototype.readQuery=function(e){return B(this,t.createRequest(e.query,e.variables)).data},W.prototype.readFragment=function(e,t,r){return X(this,e,t,r)},W.prototype.writeFragment=function(e,t,r){K(this,e,t,r)};var z=function(e,t,r){Q(0);var n=B(e,t,r);return C(),n},B=function(e,t,r){var n=h(t.query),i=e.getRootKey(n.operation),o=s(n),a={parentTypeName:i,parentKey:i,parentFieldKey:"",fieldName:"",variables:p(n,t.variables),fragments:g(t.query),partial:!1,store:e,schemaPredicates:e.schemaPredicates},u=r||Object.create(null);return u=i!==a.store.getRootKey("query")?H(a,i,o,u):Y(a,i,o,u),{dependencies:G(),partial:void 0!==u&&a.partial,data:void 0===u?null:u}},H=function(e,t,r,n){if("string"!=typeof n.__typename)return n;var i=Object.create(null);i.__typename=n.__typename;for(var o,u=new S(t,t,r,e);void 0!==(o=u.next());){var c=a(o),l=n[c];i[c]=void 0===o.selectionSet||null===l||F(l)?l:J(e,s(o),l)}return i},J=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]=J(e,t,r[i]);return n}if(null===r)return null;var a=e.store.keyOfEntity(r);if(null!==a){var s=Y(e,a,t,Object.create(null));return void 0===s?null:s}return H(e,r.__typename,t,r)},X=function(e,t,r,i){var a=g(t),u=a[Object.keys(a)[0]];if(void 0===u)return null;var c=o(u);"string"==typeof r||r.__typename||(r.__typename=c);var l="string"!=typeof r?e.keyOfEntity(n({__typename:c},r)):r;return l&&Y({parentTypeName:c,parentKey:l,parentFieldKey:"",fieldName:"",variables:i||{},fragments:a,partial:!1,store:e,schemaPredicates:e.schemaPredicates},l,s(u),Object.create(null))||null},Y=function(e,t,r,n){var o=e.store,u=e.schemaPredicates,c=t===o.getRootKey("query");c||D(t);var l=c?t:o.getField(t,"__typename");if("string"==typeof l){n.__typename=l;for(var p,v=new S(l,t,r,e),d=!1,y=!1;void 0!==(p=v.next());){var h=i(p),m=f(p,e.variables),g=a(p),b=x(t,w(h,m)),k=o.getRecord(b);c&&D(b);var _=void 0,O=o.resolvers[l];if(void 0!==O&&"function"==typeof O[h]){e.parentTypeName=l,e.parentKey=t,e.parentFieldKey=b,e.fieldName=h,void 0!==k&&(n[g]=k);var N=O[h](n,m||Object.create(null),o,e);_=void 0!==p.selectionSet?Z(e,l,h,b,s(p),n[g]||Object.create(null),N):void 0===N&&void 0===u?null:N}else if(void 0===p.selectionSet)_=k;else{var F=o.getLink(b);void 0!==F?_=$(e,F,l,h,s(p),n[g]):"object"==typeof k&&null!==k&&(_=k)}if(void 0===_&&void 0!==u&&u.isFieldNullable(l,h))y=!0,n[g]=null;else{if(void 0===_)return;d=!0,n[g]=_}}return y&&(e.partial=!0),c&&y&&!d?void 0:n}},Z=function(e,t,r,n,o,u,c){if(Array.isArray(c)){for(var l=e.schemaPredicates,p=void 0===l||l.isListNullable(t,r),v=new Array(c.length),d=0,y=c.length;d<y;d++){var h=Z(e,t,r,x(n,""+d),o,void 0!==u?u[d]:void 0,c[d]);if(void 0===h&&!p)return;v[d]=void 0!==h?h:null}return v}if(null==c)return null;if(ee(c)){var m=void 0===u?Object.create(null):u;return"string"==typeof c?Y(e,c,o,m):function(e,t,r,n,o){var u=e.store,c=e.schemaPredicates,l=u.keyOfEntity(o)||t;D(l);var p=o.__typename,v=u.getField(l,"__typename")||p;if(!("string"!=typeof v||p&&v!==p)){n.__typename=v;for(var d,y=new S(v,l,r,e),h=!1,m=!1;void 0!==(d=y.next());){var g=i(d),b=a(d),k=x(l,w(g,f(d,e.variables))),_=u.getRecord(k),O=o[g],N=void 0;if(void 0!==O&&void 0===d.selectionSet)N=O;else if(void 0===d.selectionSet)N=_;else if(void 0!==O)N=Z(e,v,g,k,s(d),n[b],O);else{var F=u.getLink(k);void 0!==F?N=$(e,F,v,g,s(d),n[b]):"object"==typeof _&&null!==_&&(N=_)}if(void 0===N&&void 0!==c&&c.isFieldNullable(v,g))m=!0,n[b]=null;else{if(void 0===N)return;h=!0,n[b]=N}}return m&&(e.partial=!0),h?n:void 0}}(e,n,o,m,c)}},$=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=$(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:Y(e,t,i,void 0===o?Object.create(null):o)},ee=function(e){return"string"==typeof e||"object"==typeof e&&"string"==typeof e.__typename},te=function(t){this.schema=e.buildClientSchema(t)};te.prototype.isFieldNullable=function(t,r){var n=re(this.schema,t,r);return void 0!==n&&e.isNullableType(n.type)},te.prototype.isListNullable=function(t,r){var n=re(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)},te.prototype.isFieldAvailableOnType=function(e,t){return!!re(this.schema,e,t)},te.prototype.isInterfaceOfType=function(t,r){if(!r||!t)return!1;if(r===t)return!0;var n=this.schema.getType(t),i=this.schema.getType(r);return n instanceof e.GraphQLObjectType?n===i:(ie(n),ne(i),this.schema.isPossibleType(n,i))};var re=function(e,t,r){var n=e.getType(t);ne(n);var i=n.getFields()[r];if(void 0!==i)return i},ne=function(t,r){v(t instanceof e.GraphQLObjectType,"",3)},ie=function(t,r){v(t instanceof e.GraphQLInterfaceType||t instanceof e.GraphQLUnionType,"",5)},oe=function(e,t){return n(n({},e),{context:n(n({},e.context),{meta:n(n({},e.context.meta),{cacheOutcome:t})})})},ae=function(e){return n(n({},e),{query:t.formatDocument(e.query)})},se=function(e){return e.context.requestPolicy},ue=function(e){return"query"===e.operationName},ce=function(e){return ue(e)&&"network-only"!==se(e)},le=function(e,t){return n(n({},e),{context:n(n({},e.context),{requestPolicy:t})})};function fe(e){return ce(e)}function pe(e){return oe(e.operation,e.outcome)}function ve(e){return"miss"===e.outcome}function de(e){return"miss"!==e.outcome}function ye(e){return!ce(e)}exports.Store=W,exports.cacheExchange=function(e){return function(t){var n=t.forward,i=t.client;e||(e={});var o=new W(e.schema?new te(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(le(r,"cache-first")))}}))},f=function(e){if(function(e){return"mutation"===e.operationName}(i=e)&&"network-only"!==se(i)){var t=e.key,r=R(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"===se(e)?le(e,"cache-and-network"):e)}))},v=function(e){var t,r=z(o,e),n=r.data,i=r.partial;return null===n?t="miss":(p(e,r.dependencies),t=i&&"cache-only"!==se(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=ue(n),f=e.data,v=n.key;if(a.has(v)&&(a.delete(v),o.clearOptimistic(v)),null!=f)if(t=T(o,n,f).dependencies,u){var d=z(o,n);f=d.data,r=d.dependencies}else f=z(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=se(t),o={operation:oe(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(le(t,"network-only"))),o}return function(e){var t=r.share(r.tap(f)(r.map(ae)(e))),i=r.share(r.map(v)(r.filter(fe)(t))),o=r.map(pe)(r.filter(ve)(i)),a=r.map(y)(r.filter(de)(i)),s=r.map(d)(n(r.merge([r.filter(ye)(t),o])));return r.merge([s,a])}}},exports.query=z,exports.read=B,exports.write=T,exports.writeFragment=K,exports.writeOptimistic=R;
//# sourceMappingURL=urql-exchange-graphcache.min.js.map
{
"name": "@urql/exchange-graphcache-extras",
"version": "1.2.1",
"version": "1.2.2-fast",
"private": true,

@@ -5,0 +5,0 @@ "sideEffects": false,

{
"name": "@urql/exchange-graphcache",
"version": "1.2.1",
"version": "1.2.2-fast",
"description": "A normalized and configurable cache exchange for urql",

@@ -79,3 +79,2 @@ "repository": "https://github.com/FormidableLabs/urql-exchange-graphcache",

"dependencies": {
"pessimism": "^1.1.4",
"wonka": "^3.2.1"

@@ -82,0 +81,0 @@ },

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

@@ -21,2 +20,3 @@ import {

import * as KVMap from './map';
import { joinKeys, keyOfField } from './helpers';

@@ -72,13 +72,11 @@ import { invariant, currentDebugStack } from './helpers/help';

const mapSet = <T>(map: Pessimism.Map<T>, key: string, value: T) => {
const mapSet = <T>(map: KVMap.KVMap<T>, key: string, value: T) => {
const optimisticKey = currentOptimisticKey.current || 0;
return Pessimism.setOptimistic(map, key, value, optimisticKey);
return KVMap.set(map, key, value, optimisticKey);
};
// Used to remove a value from a Map optimistially (possible by setting it to undefined)
const mapRemove = <T>(map: Pessimism.Map<T>, key: string) => {
const mapRemove = <T>(map: KVMap.KVMap<T>, key: string) => {
const optimisticKey = currentOptimisticKey.current || 0;
return optimisticKey
? Pessimism.setOptimistic(map, key, undefined, optimisticKey)
: Pessimism.remove(map, key);
return KVMap.remove(map, key, optimisticKey);
};

@@ -89,5 +87,5 @@

export class Store implements Cache {
records: Pessimism.Map<EntityField>;
connections: Pessimism.Map<Connection[]>;
links: Pessimism.Map<Link>;
records: KVMap.KVMap<EntityField>;
connections: KVMap.KVMap<Connection[]>;
links: KVMap.KVMap<Link>;

@@ -110,5 +108,5 @@ resolvers: ResolverConfig;

) {
this.records = Pessimism.asMutable(Pessimism.make());
this.connections = Pessimism.asMutable(Pessimism.make());
this.links = Pessimism.asMutable(Pessimism.make());
this.records = KVMap.make();
this.connections = KVMap.make();
this.links = KVMap.make();

@@ -188,12 +186,9 @@ this.resolvers = resolvers || {};

clearOptimistic(optimisticKey: number) {
this.records = Pessimism.clearOptimistic(this.records, optimisticKey);
this.connections = Pessimism.clearOptimistic(
this.connections,
optimisticKey
);
this.links = Pessimism.clearOptimistic(this.links, optimisticKey);
this.records = KVMap.clear(this.records, optimisticKey);
this.connections = KVMap.clear(this.connections, optimisticKey);
this.links = KVMap.clear(this.links, optimisticKey);
}
getRecord(fieldKey: string): EntityField {
return Pessimism.get(this.records, fieldKey);
return KVMap.get(this.records, fieldKey);
}

@@ -231,3 +226,3 @@

getLink(key: string): undefined | Link {
return Pessimism.get(this.links, key);
return KVMap.get(this.links, key);
}

@@ -248,3 +243,3 @@

let connections = Pessimism.get(this.connections, key);
let connections = KVMap.get(this.connections, key);
const connection: Connection = [args, linkKey];

@@ -300,3 +295,3 @@ if (connections === undefined) {

if (typeof entity === 'string') {
connections = Pessimism.get(this.connections, joinKeys(entity, field));
connections = KVMap.get(this.connections, joinKeys(entity, field));
} else if (entity !== null) {

@@ -306,6 +301,3 @@ const entityKey = this.keyOfEntity(entity);

addDependency(entityKey);
connections = Pessimism.get(
this.connections,
joinKeys(entityKey, field)
);
connections = KVMap.get(this.connections, joinKeys(entityKey, field));
}

@@ -312,0 +304,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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc