Socket
Socket
Sign inDemoInstall

@urql/exchange-graphcache

Package Overview
Dependencies
Maintainers
4
Versions
294
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.0.3 to 1.0.4-debug-trace

8

dist/types/helpers/help.d.ts

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

import { ExecutableDefinitionNode, InlineFragmentNode } from 'graphql';
import { Ref } from '../types';
declare type DebugNode = ExecutableDefinitionNode | InlineFragmentNode;
export declare const currentDebugStack: Ref<string[]>;
export declare const pushDebugNode: (typename: string | void, node: DebugNode) => void;
export declare const invariant: (clause: any, message: string, code: number) => void;
export declare const warning: (clause: any, message: string, code: number) => void;
export declare const warn: (message: string, code: number) => void;
export {};
import { DocumentNode, FragmentDefinitionNode, SelectionNode } from 'graphql';
export declare type NullArray<T> = Array<null | T>;
export interface Ref<T> {
current: T;
}
export declare type SelectionSet = ReadonlyArray<SelectionNode>;

@@ -4,0 +7,0 @@ export interface Fragments {

84

dist/urql-exchange-graphcache.es.js

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

var currentDebugStack = {
current: []
};
var pushDebugNode = function(typename, node) {
var identifier = "";
if (node.kind === Kind.INLINE_FRAGMENT) {
identifier = typename ? 'Inline Fragment on "' + typename + '"' : "Inline Fragment";
} else if (node.kind === Kind.OPERATION_DEFINITION) {
identifier = (node.name ? '"' + node.name.value + '"' : "Unnamed") + " " + node.operation;
} else if (node.kind === Kind.FRAGMENT_DEFINITION) {
identifier = '"' + node.name.value + '" Fragment';
}
if (identifier) {
currentDebugStack.current.push(identifier);
}
};
var getDebugOutput = function() {
return currentDebugStack.current.length ? "\n(Caused At: " + currentDebugStack.current.join(", ") + ")" : "";
};
var invariant = function(clause, message, code) {
if (!clause) {
var error = new Error((message || "Minfied Error #" + code + "\n") + helpUrl + code);
var errorMessage = message || "Minfied Error #" + code + "\n";
if ("production" !== process.env.NODE_ENV) {
errorMessage += getDebugOutput();
}
var error = new Error(errorMessage + helpUrl + code);
error.name = "Graphcache Error";

@@ -102,5 +128,5 @@ throw error;

var warning = function(clause, message, code) {
if (!clause && !cache.has(message)) {
console.warn(message + helpUrl + code);
var warn = function(message, code) {
if (!cache.has(message)) {
console.warn(message + getDebugOutput() + helpUrl + code);
cache.add(message);

@@ -174,3 +200,3 @@ }

}
"production" !== process.env.NODE_ENV && warning(!1, "Heuristic Fragment Matching: A fragment is trying to match against the `" + typename + "` type, but the type condition is `" + typeCondition + "`. Since GraphQL allows for interfaces `" + typeCondition + "` may be aninterface.\nA schema needs to be defined for this match to be deterministic, otherwise the fragment will be matched heuristically!", 16);
"production" !== process.env.NODE_ENV && warn("Heuristic Fragment Matching: A fragment is trying to match against the `" + typename + "` type, but the type condition is `" + typeCondition + "`. Since GraphQL allows for interfaces `" + typeCondition + "` may be aninterface.\nA schema needs to be defined for this match to be deterministic, otherwise the fragment will be matched heuristically!", 16);
return !getSelectionSet(node).some((function(node) {

@@ -208,2 +234,5 @@ if (!isFieldNode(node)) {

if (void 0 !== fragmentNode) {
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(this.typename, fragmentNode);
}
if (void 0 !== this.context.schemaPredicates ? this.context.schemaPredicates.isInterfaceOfType(getTypeCondition(fragmentNode), this.typename) : isFragmentHeuristicallyMatching(fragmentNode, this.typename, this.entityKey, this.context)) {

@@ -257,2 +286,5 @@ this.indexStack.push(0);

};
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(operationName, operation);
}
if (operationName === ctx.store.getRootKey("query")) {

@@ -275,2 +307,5 @@ writeSelection(ctx, operationName, select, data);

invariant(operationName === mutationRootKey, "production" !== process.env.NODE_ENV ? "writeOptimistic(...) was called with an operation that is not a mutation.\nThis case is unsupported and should never occur." : "", 10);
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(operationName, operation);
}
var ctx = {

@@ -318,3 +353,3 @@ parentTypeName: mutationRootKey,

if (void 0 === fragment) {
return "production" !== process.env.NODE_ENV ? warning(!1, "writeFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 11) : void 0;
return "production" !== process.env.NODE_ENV ? warn("writeFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 11) : void 0;
}

@@ -327,4 +362,7 @@ var typename = getFragmentTypeName(fragment);

if (!entityKey) {
return "production" !== process.env.NODE_ENV ? warning(!1, "Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 12) : void 0;
return "production" !== process.env.NODE_ENV ? warn("Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 12) : void 0;
}
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(typename, fragment);
}
var ctx = {

@@ -366,3 +404,3 @@ parentTypeName: typename,

if (void 0 === fieldValue) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid undefined: 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.optimistic ? "\nYour optimistic result may be missing a field!" : ""), 13);
"production" !== process.env.NODE_ENV && warn("Invalid undefined: 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.optimistic ? "\nYour optimistic result may be missing a field!" : ""), 13);
continue;

@@ -381,3 +419,3 @@ } else if (ctx.schemaPredicates && typename) {

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `" + fieldKey + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nThe value will still be cached, however this may lead to undefined behavior!", 14);
"production" !== process.env.NODE_ENV && warn("Invalid value: The field at `" + fieldKey + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nThe value will still be cached, however this may lead to undefined behavior!", 14);
store.writeRecord(fieldValue, fieldKey);

@@ -403,5 +441,5 @@ }

var key = null !== entityKey ? entityKey : parentFieldKey;
if ("string" != typeof data.__typename || void 0 === ctx.store.keys[data.__typename] && null === entityKey) {
var typename = data.__typename;
"production" !== process.env.NODE_ENV && warning(typename.endsWith("Connection") || typename.endsWith("Edge") || "PageInfo" === typename, "Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.", 15);
var typename = data.__typename;
if (void 0 === ctx.store.keys[data.__typename] && null === entityKey && !typename.endsWith("Connection") && !typename.endsWith("Edge") && "PageInfo" !== typename) {
"production" !== process.env.NODE_ENV && warn("Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.", 15);
}

@@ -514,2 +552,5 @@ writeSelection(ctx, key, select, data);

currentOptimisticKey.current = optimisticKey;
if ("production" !== process.env.NODE_ENV) {
currentDebugStack.current = [];
}
};

@@ -520,2 +561,5 @@

currentOptimisticKey.current = null;
if ("production" !== process.env.NODE_ENV) {
currentDebugStack.current = [];
}
};

@@ -766,2 +810,5 @@

};
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(rootKey, operation);
}
var data = input || Object.create(null);

@@ -819,3 +866,3 @@ data = rootKey !== ctx.store.getRootKey("query") ? readRoot(ctx, rootKey, rootSelect, data) : readSelection(ctx, rootKey, rootSelect, data);

if (void 0 === fragment) {
"production" !== process.env.NODE_ENV && warning(!1, "readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 6);
"production" !== process.env.NODE_ENV && warn("readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 6);
return null;

@@ -831,5 +878,8 @@ }

if (!entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 7);
"production" !== process.env.NODE_ENV && warn("Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 7);
return null;
}
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(typename, fragment);
}
return readSelection({

@@ -944,3 +994,3 @@ parentTypeName: typename,

if ("string" != typeof typename || resolvedTypename && typename !== resolvedTypename) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver data: The resolver at `" + entityKey + "` returned an invalid typename that could not be reconciled with the cache.", 8);
"production" !== process.env.NODE_ENV && warn("Invalid resolver data: The resolver at `" + entityKey + "` returned an invalid typename that could not be reconciled with the cache.", 8);
return;

@@ -993,3 +1043,3 @@ }

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The field at `" + key + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.", 9);
"production" !== process.env.NODE_ENV && warn("Invalid resolver value: The field at `" + key + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.", 9);
return;

@@ -1068,3 +1118,3 @@ }

if (void 0 === field) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid field: The field `" + fieldName + "` does not exist on `" + typename + "`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", 4);
"production" !== process.env.NODE_ENV && warn("Invalid field: The field `" + fieldName + "` does not exist on `" + typename + "`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", 4);
return;

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

@@ -95,5 +95,31 @@ "use strict";

var currentDebugStack = {
current: []
};
var pushDebugNode = function(typename, node) {
var identifier = "";
if (node.kind === graphql.Kind.INLINE_FRAGMENT) {
identifier = typename ? 'Inline Fragment on "' + typename + '"' : "Inline Fragment";
} else if (node.kind === graphql.Kind.OPERATION_DEFINITION) {
identifier = (node.name ? '"' + node.name.value + '"' : "Unnamed") + " " + node.operation;
} else if (node.kind === graphql.Kind.FRAGMENT_DEFINITION) {
identifier = '"' + node.name.value + '" Fragment';
}
if (identifier) {
currentDebugStack.current.push(identifier);
}
};
var getDebugOutput = function() {
return currentDebugStack.current.length ? "\n(Caused At: " + currentDebugStack.current.join(", ") + ")" : "";
};
var invariant = function(clause, message, code) {
if (!clause) {
var error = new Error((message || "Minfied Error #" + code + "\n") + helpUrl + code);
var errorMessage = message || "Minfied Error #" + code + "\n";
if ("production" !== process.env.NODE_ENV) {
errorMessage += getDebugOutput();
}
var error = new Error(errorMessage + helpUrl + code);
error.name = "Graphcache Error";

@@ -104,5 +130,5 @@ throw error;

var warning = function(clause, message, code) {
if (!clause && !cache.has(message)) {
console.warn(message + helpUrl + code);
var warn = function(message, code) {
if (!cache.has(message)) {
console.warn(message + getDebugOutput() + helpUrl + code);
cache.add(message);

@@ -176,3 +202,3 @@ }

}
"production" !== process.env.NODE_ENV && warning(!1, "Heuristic Fragment Matching: A fragment is trying to match against the `" + typename + "` type, but the type condition is `" + typeCondition + "`. Since GraphQL allows for interfaces `" + typeCondition + "` may be aninterface.\nA schema needs to be defined for this match to be deterministic, otherwise the fragment will be matched heuristically!", 16);
"production" !== process.env.NODE_ENV && warn("Heuristic Fragment Matching: A fragment is trying to match against the `" + typename + "` type, but the type condition is `" + typeCondition + "`. Since GraphQL allows for interfaces `" + typeCondition + "` may be aninterface.\nA schema needs to be defined for this match to be deterministic, otherwise the fragment will be matched heuristically!", 16);
return !getSelectionSet(node).some((function(node) {

@@ -210,2 +236,5 @@ if (!isFieldNode(node)) {

if (void 0 !== fragmentNode) {
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(this.typename, fragmentNode);
}
if (void 0 !== this.context.schemaPredicates ? this.context.schemaPredicates.isInterfaceOfType(getTypeCondition(fragmentNode), this.typename) : isFragmentHeuristicallyMatching(fragmentNode, this.typename, this.entityKey, this.context)) {

@@ -259,2 +288,5 @@ this.indexStack.push(0);

};
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(operationName, operation);
}
if (operationName === ctx.store.getRootKey("query")) {

@@ -277,2 +309,5 @@ writeSelection(ctx, operationName, select, data);

invariant(operationName === mutationRootKey, "production" !== process.env.NODE_ENV ? "writeOptimistic(...) was called with an operation that is not a mutation.\nThis case is unsupported and should never occur." : "", 10);
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(operationName, operation);
}
var ctx = {

@@ -320,3 +355,3 @@ parentTypeName: mutationRootKey,

if (void 0 === fragment) {
return "production" !== process.env.NODE_ENV ? warning(!1, "writeFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 11) : void 0;
return "production" !== process.env.NODE_ENV ? warn("writeFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 11) : void 0;
}

@@ -329,4 +364,7 @@ var typename = getFragmentTypeName(fragment);

if (!entityKey) {
return "production" !== process.env.NODE_ENV ? warning(!1, "Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 12) : void 0;
return "production" !== process.env.NODE_ENV ? warn("Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 12) : void 0;
}
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(typename, fragment);
}
var ctx = {

@@ -368,3 +406,3 @@ parentTypeName: typename,

if (void 0 === fieldValue) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid undefined: 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.optimistic ? "\nYour optimistic result may be missing a field!" : ""), 13);
"production" !== process.env.NODE_ENV && warn("Invalid undefined: 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.optimistic ? "\nYour optimistic result may be missing a field!" : ""), 13);
continue;

@@ -383,3 +421,3 @@ } else if (ctx.schemaPredicates && typename) {

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `" + fieldKey + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nThe value will still be cached, however this may lead to undefined behavior!", 14);
"production" !== process.env.NODE_ENV && warn("Invalid value: The field at `" + fieldKey + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nThe value will still be cached, however this may lead to undefined behavior!", 14);
store.writeRecord(fieldValue, fieldKey);

@@ -405,5 +443,5 @@ }

var key = null !== entityKey ? entityKey : parentFieldKey;
if ("string" != typeof data.__typename || void 0 === ctx.store.keys[data.__typename] && null === entityKey) {
var typename = data.__typename;
"production" !== process.env.NODE_ENV && warning(typename.endsWith("Connection") || typename.endsWith("Edge") || "PageInfo" === typename, "Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.", 15);
var typename = data.__typename;
if (void 0 === ctx.store.keys[data.__typename] && null === entityKey && !typename.endsWith("Connection") && !typename.endsWith("Edge") && "PageInfo" !== typename) {
"production" !== process.env.NODE_ENV && warn("Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.", 15);
}

@@ -516,2 +554,5 @@ writeSelection(ctx, key, select, data);

currentOptimisticKey.current = optimisticKey;
if ("production" !== process.env.NODE_ENV) {
currentDebugStack.current = [];
}
};

@@ -522,2 +563,5 @@

currentOptimisticKey.current = null;
if ("production" !== process.env.NODE_ENV) {
currentDebugStack.current = [];
}
};

@@ -768,2 +812,5 @@

};
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(rootKey, operation);
}
var data = input || Object.create(null);

@@ -821,3 +868,3 @@ data = rootKey !== ctx.store.getRootKey("query") ? readRoot(ctx, rootKey, rootSelect, data) : readSelection(ctx, rootKey, rootSelect, data);

if (void 0 === fragment) {
"production" !== process.env.NODE_ENV && warning(!1, "readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 6);
"production" !== process.env.NODE_ENV && warn("readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.", 6);
return null;

@@ -833,5 +880,8 @@ }

if (!entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 7);
"production" !== process.env.NODE_ENV && warn("Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.", 7);
return null;
}
if ("production" !== process.env.NODE_ENV) {
pushDebugNode(typename, fragment);
}
return readSelection({

@@ -946,3 +996,3 @@ parentTypeName: typename,

if ("string" != typeof typename || resolvedTypename && typename !== resolvedTypename) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver data: The resolver at `" + entityKey + "` returned an invalid typename that could not be reconciled with the cache.", 8);
"production" !== process.env.NODE_ENV && warn("Invalid resolver data: The resolver at `" + entityKey + "` returned an invalid typename that could not be reconciled with the cache.", 8);
return;

@@ -995,3 +1045,3 @@ }

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The field at `" + key + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.", 9);
"production" !== process.env.NODE_ENV && warn("Invalid resolver value: The field at `" + key + "` is a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.", 9);
return;

@@ -1070,3 +1120,3 @@ }

if (void 0 === field) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid field: The field `" + fieldName + "` does not exist on `" + typename + "`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", 4);
"production" !== process.env.NODE_ENV && warn("Invalid field: The field `" + fieldName + "` does not exist on `" + typename + "`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", 4);
return;

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

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

{
"name": "@urql/exchange-graphcache",
"version": "1.0.3",
"version": "1.0.4-debug-trace",
"description": "A normalized and configurable cache exchange for urql",

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

@@ -13,3 +13,3 @@ import {

import { invariant, warning } from '../helpers/help';
import { invariant, warn } from '../helpers/help';

@@ -69,4 +69,3 @@ export class SchemaPredicates {

if (field === undefined) {
warning(
false,
warn(
'Invalid field: The field `' +

@@ -73,0 +72,0 @@ fieldName +

@@ -6,2 +6,7 @@ // These are guards that are used throughout the codebase to warn or error on

import { Kind, ExecutableDefinitionNode, InlineFragmentNode } from 'graphql';
import { Ref } from '../types';
type DebugNode = ExecutableDefinitionNode | InlineFragmentNode;
const helpUrl =

@@ -11,7 +16,35 @@ '\nhttps://github.com/FormidableLabs/urql-exchange-graphcache/blob/master/docs/help.md#';

export const currentDebugStack: Ref<string[]> = { current: [] };
export const pushDebugNode = (typename: void | string, node: DebugNode) => {
let identifier = '';
if (node.kind === Kind.INLINE_FRAGMENT) {
identifier = typename
? `Inline Fragment on "${typename}"`
: 'Inline Fragment';
} else if (node.kind === Kind.OPERATION_DEFINITION) {
const name = node.name ? `"${node.name.value}"` : 'Unnamed';
identifier = `${name} ${node.operation}`;
} else if (node.kind === Kind.FRAGMENT_DEFINITION) {
identifier = `"${node.name.value}" Fragment`;
}
if (identifier) {
currentDebugStack.current.push(identifier);
}
};
const getDebugOutput = (): string =>
currentDebugStack.current.length
? '\n(Caused At: ' + currentDebugStack.current.join(', ') + ')'
: '';
export const invariant = (clause: any, message: string, code: number) => {
if (!clause) {
const error = new Error(
(message || 'Minfied Error #' + code + '\n') + helpUrl + code
);
let errorMessage = message || 'Minfied Error #' + code + '\n';
if (process.env.NODE_ENV !== 'production') {
errorMessage += getDebugOutput();
}
const error = new Error(errorMessage + helpUrl + code);
error.name = 'Graphcache Error';

@@ -22,7 +55,7 @@ throw error;

export const warning = (clause: any, message: string, code: number) => {
if (!clause && !cache.has(message)) {
console.warn(message + helpUrl + code);
export const warn = (message: string, code: number) => {
if (!cache.has(message)) {
console.warn(message + getDebugOutput() + helpUrl + code);
cache.add(message);
}
};

@@ -31,3 +31,3 @@ import {

import { warning } from '../helpers/help';
import { warn, pushDebugNode } from '../helpers/help';
import { SelectionIterator, isScalar } from './shared';

@@ -88,2 +88,6 @@ import { joinKeys, keyOfField } from '../helpers';

if (process.env.NODE_ENV !== 'production') {
pushDebugNode(rootKey, operation);
}
let data = input || Object.create(null);

@@ -177,4 +181,3 @@ data =

if (fragment === undefined) {
warning(
false,
warn(
'readFragment(...) was called with an empty fragment.\n' +

@@ -199,4 +202,3 @@ 'You have to call it with at least one fragment in your GraphQL document.',

if (!entityKey) {
warning(
false,
warn(
"Can't generate a key for readFragment(...).\n" +

@@ -212,2 +214,6 @@ 'You have to pass an `id` or `_id` field or create a custom `keys` config for `' +

if (process.env.NODE_ENV !== 'production') {
pushDebugNode(typename, fragment);
}
const ctx: Context = {

@@ -385,4 +391,3 @@ parentTypeName: typename,

// TODO: This may be an invalid error for resolvers that return interfaces
warning(
false,
warn(
'Invalid resolver data: The resolver at `' +

@@ -531,4 +536,3 @@ entityKey +

} else {
warning(
false,
warn(
'Invalid resolver value: The field at `' +

@@ -535,0 +539,0 @@ key +

@@ -5,3 +5,4 @@ import { FieldNode, InlineFragmentNode, FragmentDefinitionNode } from 'graphql';

import { joinKeys, keyOfField } from '../helpers';
import { warning } from '../helpers/help';
import { warn, pushDebugNode } from '../helpers/help';
import { SchemaPredicates } from '../ast/schemaPredicates';

@@ -17,3 +18,2 @@ import {

} from '../ast';
import { SchemaPredicates } from '../ast/schemaPredicates';

@@ -37,4 +37,3 @@ interface Context {

warning(
false,
warn(
'Heuristic Fragment Matching: A fragment is trying to match against the `' +

@@ -102,2 +101,6 @@ typename +

if (fragmentNode !== undefined) {
if (process.env.NODE_ENV !== 'production') {
pushDebugNode(this.typename, fragmentNode);
}
const isMatching =

@@ -104,0 +107,0 @@ this.context.schemaPredicates !== undefined

@@ -32,3 +32,3 @@ import { DocumentNode, FragmentDefinitionNode } from 'graphql';

import { invariant, warning } from '../helpers/help';
import { invariant, warn, pushDebugNode } from '../helpers/help';
import { SelectionIterator, isScalar } from './shared';

@@ -90,2 +90,6 @@ import { joinKeys, keyOfField } from '../helpers';

if (process.env.NODE_ENV !== 'production') {
pushDebugNode(operationName, operation);
}
if (operationName === ctx.store.getRootKey('query')) {

@@ -119,2 +123,6 @@ writeSelection(ctx, operationName, select, data);

if (process.env.NODE_ENV !== 'production') {
pushDebugNode(operationName, operation);
}
const ctx: Context = {

@@ -185,4 +193,3 @@ parentTypeName: mutationRootKey,

if (fragment === undefined) {
return warning(
false,
return warn(
'writeFragment(...) was called with an empty fragment.\n' +

@@ -198,4 +205,3 @@ 'You have to call it with at least one fragment in your GraphQL document.',

if (!entityKey) {
return warning(
false,
return warn(
"Can't generate a key for writeFragment(...) data.\n" +

@@ -209,2 +215,6 @@ 'You have to pass an `id` or `_id` field or create a custom `keys` config for `' +

if (process.env.NODE_ENV !== 'production') {
pushDebugNode(typename, fragment);
}
const ctx: Context = {

@@ -260,4 +270,3 @@ parentTypeName: typename,

warning(
false,
warn(
'Invalid undefined: The field at `' +

@@ -294,4 +303,3 @@ fieldKey +

} else {
warning(
false,
warn(
'Invalid value: The field at `' +

@@ -336,13 +344,12 @@ fieldKey +

const key = entityKey !== null ? entityKey : parentFieldKey;
const typename = data.__typename;
if (
typeof data.__typename !== 'string' ||
(ctx.store.keys[data.__typename] === undefined && entityKey === null)
ctx.store.keys[data.__typename] === undefined &&
entityKey === null &&
!typename.endsWith('Connection') &&
!typename.endsWith('Edge') &&
typename !== 'PageInfo'
) {
const typename = data.__typename;
warning(
typename.endsWith('Connection') ||
typename.endsWith('Edge') ||
typename === 'PageInfo',
warn(
'Invalid key: The GraphQL query at the field at `' +

@@ -349,0 +356,0 @@ parentFieldKey +

@@ -6,2 +6,3 @@ import { DocumentNode } from 'graphql';

import {
Ref,
Cache,

@@ -22,3 +23,3 @@ EntityField,

import { joinKeys, keyOfField } from './helpers';
import { invariant } from './helpers/help';
import { invariant, currentDebugStack } from './helpers/help';
import { read, readFragment } from './operations/query';

@@ -29,11 +30,7 @@ import { writeFragment, startWrite } from './operations/write';

interface Ref<T> {
current: null | T;
}
const currentDependencies: Ref<null | Set<string>> = { current: null };
const currentOptimisticKey: Ref<null | number> = { current: null };
const currentDependencies: Ref<Set<string>> = { current: null };
const currentOptimisticKey: Ref<number> = { current: null };
// Resolve a ref value or throw when we're outside of a store run
const refValue = <T>(ref: Ref<T>): T => {
const refValue = <T>(ref: Ref<T | null>): T => {
invariant(

@@ -54,2 +51,6 @@ ref.current !== null,

currentOptimisticKey.current = optimisticKey;
if (process.env.NODE_ENV !== 'production') {
currentDebugStack.current = [];
}
};

@@ -61,2 +62,6 @@

currentOptimisticKey.current = null;
if (process.env.NODE_ENV !== 'production') {
currentDebugStack.current = [];
}
};

@@ -63,0 +68,0 @@

@@ -6,2 +6,6 @@ import { DocumentNode, FragmentDefinitionNode, SelectionNode } from 'graphql';

export interface Ref<T> {
current: T;
}
// GraphQL helper types

@@ -8,0 +12,0 @@ export type SelectionSet = ReadonlyArray<SelectionNode>;

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