Socket
Socket
Sign inDemoInstall

@urql/exchange-graphcache

Package Overview
Dependencies
Maintainers
3
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.0-rc.1 to 1.0.0-rc.2

dist/types/helpers/warning.d.ts

1

dist/types/ast/schemaPredicates.d.ts

@@ -7,3 +7,4 @@ import { GraphQLSchema } from 'graphql';

isListNullable(typename: string, fieldName: string): boolean;
isFieldAvailableOnType(typename: string, fieldname: string): boolean;
isInterfaceOfType(typeCondition: null | string, typename: string | void): boolean;
}

40

dist/urql-exchange-graphcache.es.js

@@ -1,3 +0,1 @@

import warning from "warning";
import { Kind, buildClientSchema, isNullableType, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType } from "graphql";

@@ -13,2 +11,11 @@

var cache = {};
var warning = function(clause, msg) {
if (!clause && !cache[msg]) {
console.warn(msg);
cache[msg] = !0;
}
};
var getName = function(node) {

@@ -206,3 +213,3 @@ return node.name.value;

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

@@ -344,3 +351,3 @@ if (!isFieldNode(node)) {

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 `%s`.", typeName) : void 0;
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 + "`.") : void 0;
}

@@ -378,2 +385,5 @@ var ctx = {

}
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (void 0 === node.selectionSet) {

@@ -387,3 +397,3 @@ store.writeRecord(fieldValue, fieldKey);

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `%s` 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!", fieldKey);
"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!");
store.writeRecord(fieldValue, fieldKey);

@@ -409,3 +419,5 @@ }

var key = null !== entityKey ? entityKey : parentFieldKey;
"production" !== process.env.NODE_ENV && warning("string" != typeof data.__typename || void 0 !== ctx.store.keys[data.__typename] || null !== entityKey, "Invalid key: The GraphQL query at the field at `%s` 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 `%s`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `%s` that always returns null.", parentFieldKey, data.__typename, data.__typename);
if ("string" != typeof data.__typename || void 0 !== ctx.store.keys[data.__typename] || null !== entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "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 `" + data.__typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + data.__typename + "` that always returns null.");
}
writeSelection(ctx, key, select, data);

@@ -475,2 +487,5 @@ return key;

var fieldKey = joinKeys(entityKey, keyOfField(fieldName, fieldArgs));
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (isQuery) {

@@ -796,2 +811,5 @@ addDependency(fieldKey);

}
if ("production" !== process.env.NODE_ENV && schemaPredicates) {
schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
var dataFieldValue = void 0;

@@ -863,3 +881,3 @@ var resolvers = store.resolvers[typename];

}
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The resolver at `%s` returned a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nIf necessary, use Cache.resolve() to resolve a link or entity from the cache.", key);
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The resolver at `" + key + "` returned a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nIf necessary, use Cache.resolve() to resolve a link or entity from the cache.");
return;

@@ -915,2 +933,6 @@ };

SchemaPredicates.prototype.isFieldAvailableOnType = function isFieldAvailableOnType(typename, fieldname) {
return !!getField(this.schema, typename, fieldname);
};
SchemaPredicates.prototype.isInterfaceOfType = function isInterfaceOfType(typeCondition, typename) {

@@ -935,3 +957,3 @@ if (!typename || !typeCondition) {

if (void 0 === object) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid type: The type `%s` is not a type in the defined schema, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", typename);
"production" !== process.env.NODE_ENV && warning(!1, "Invalid type: The type `" + typename + "` is not a type in the defined schema, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!");
return;

@@ -941,3 +963,3 @@ }

if (void 0 === field) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid field: The field `%s` does not exist on `%s`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", fieldName, typename);
"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!");
return;

@@ -944,0 +966,0 @@ }

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

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

@@ -13,3 +7,5 @@

var stringify = _interopDefault(require("fast-json-stable-stringify"));
var stringify = function _interopDefault(ex) {
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
}(require("fast-json-stable-stringify"));

@@ -20,2 +16,11 @@ var urql = require("urql");

var cache = {};
var warning = function(clause, msg) {
if (!clause && !cache[msg]) {
console.warn(msg);
cache[msg] = !0;
}
};
var getName = function(node) {

@@ -213,3 +218,3 @@ return node.name.value;

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

@@ -351,3 +356,3 @@ if (!isFieldNode(node)) {

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 `%s`.", typeName) : void 0;
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 + "`.") : void 0;
}

@@ -385,2 +390,5 @@ var ctx = {

}
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (void 0 === node.selectionSet) {

@@ -394,3 +402,3 @@ store.writeRecord(fieldValue, fieldKey);

} else {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid value: The field at `%s` 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!", fieldKey);
"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!");
store.writeRecord(fieldValue, fieldKey);

@@ -416,3 +424,5 @@ }

var key = null !== entityKey ? entityKey : parentFieldKey;
"production" !== process.env.NODE_ENV && warning("string" != typeof data.__typename || void 0 !== ctx.store.keys[data.__typename] || null !== entityKey, "Invalid key: The GraphQL query at the field at `%s` 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 `%s`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `%s` that always returns null.", parentFieldKey, data.__typename, data.__typename);
if ("string" != typeof data.__typename || void 0 !== ctx.store.keys[data.__typename] || null !== entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "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 `" + data.__typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + data.__typename + "` that always returns null.");
}
writeSelection(ctx, key, select, data);

@@ -482,2 +492,5 @@ return key;

var fieldKey = joinKeys(entityKey, keyOfField(fieldName, fieldArgs));
if ("production" !== process.env.NODE_ENV && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (isQuery) {

@@ -803,2 +816,5 @@ addDependency(fieldKey);

}
if ("production" !== process.env.NODE_ENV && schemaPredicates) {
schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
var dataFieldValue = void 0;

@@ -870,3 +886,3 @@ var resolvers = store.resolvers[typename];

}
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The resolver at `%s` returned a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nIf necessary, use Cache.resolve() to resolve a link or entity from the cache.", key);
"production" !== process.env.NODE_ENV && warning(!1, "Invalid resolver value: The resolver at `" + key + "` returned a scalar (number, boolean, etc), but the GraphQL query expects a selection set for this field.\nIf necessary, use Cache.resolve() to resolve a link or entity from the cache.");
return;

@@ -922,2 +938,6 @@ };

SchemaPredicates.prototype.isFieldAvailableOnType = function isFieldAvailableOnType(typename, fieldname) {
return !!getField(this.schema, typename, fieldname);
};
SchemaPredicates.prototype.isInterfaceOfType = function isInterfaceOfType(typeCondition, typename) {

@@ -942,3 +962,3 @@ if (!typename || !typeCondition) {

if (void 0 === object) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid type: The type `%s` is not a type in the defined schema, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", typename);
"production" !== process.env.NODE_ENV && warning(!1, "Invalid type: The type `" + typename + "` is not a type in the defined schema, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!");
return;

@@ -948,3 +968,3 @@ }

if (void 0 === field) {
"production" !== process.env.NODE_ENV && warning(!1, "Invalid field: The field `%s` does not exist on `%s`, but the GraphQL document expects it to exist.\nTraversal will continue, however this may lead to undefined behavior!", fieldName, typename);
"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!");
return;

@@ -951,0 +971,0 @@ }

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

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

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

"tiny-invariant": "^1.0.6",
"warning": "^4.0.3",
"wonka": "^3.2.1"

@@ -84,0 +83,0 @@ },

import invariant from 'invariant';
import warning from 'warning';
import { warning } from '../helpers/warning';
import {

@@ -36,2 +35,6 @@ buildClientSchema,

isFieldAvailableOnType(typename: string, fieldname: string): boolean {
return !!getField(this.schema, typename, fieldname);
}
isInterfaceOfType(

@@ -67,6 +70,7 @@ typeCondition: null | string,

false,
'Invalid type: The type `%s` is not a type in the defined schema, ' +
'Invalid type: The type `' +
typename +
'` is not a type in the defined schema, ' +
'but the GraphQL document expects it to exist.\n' +
'Traversal will continue, however this may lead to undefined behavior!',
typename
'Traversal will continue, however this may lead to undefined behavior!'
);

@@ -81,7 +85,9 @@

false,
'Invalid field: The field `%s` does not exist on `%s`, ' +
'Invalid field: The field `' +
fieldName +
'` does not exist on `' +
typename +
'`, ' +
'but the GraphQL document expects it to exist.\n' +
'Traversal will continue, however this may lead to undefined behavior!',
fieldName,
typename
'Traversal will continue, however this may lead to undefined behavior!'
);

@@ -88,0 +94,0 @@

@@ -77,2 +77,6 @@ import {

if (process.env.NODE_ENV !== 'production' && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (isQuery) addDependency(fieldKey);

@@ -79,0 +83,0 @@

@@ -26,2 +26,3 @@ import { Store } from '../store';

let schema, store;
const spy: { console?: any } = {};

@@ -32,2 +33,6 @@ beforeAll(() => {

afterEach(() => {
spy.console.mockRestore();
});
beforeEach(() => {

@@ -46,2 +51,3 @@ store = new Store(new SchemaPredicates(schema));

);
spy.console = jest.spyOn(console, 'warn');
});

@@ -72,2 +78,38 @@

});
it('should warn once for invalid fields on an entity', () => {
const INVALID_TODO_QUERY = gql`
query {
todos {
id
text
incomplete
}
}
`;
query(store, { query: INVALID_TODO_QUERY });
expect(console.warn).toHaveBeenCalledTimes(1);
query(store, { query: INVALID_TODO_QUERY });
expect(console.warn).toHaveBeenCalledTimes(1);
expect((console.warn as any).mock.calls[0][0]).toMatch(/incomplete/);
});
it('should warn once for invalid sub-entities on an entity', () => {
const INVALID_TODO_QUERY = gql`
query {
todos {
id
text
writer {
id
}
}
}
`;
query(store, { query: INVALID_TODO_QUERY });
expect(console.warn).toHaveBeenCalledTimes(1);
query(store, { query: INVALID_TODO_QUERY });
expect(console.warn).toHaveBeenCalledTimes(1);
expect((console.warn as any).mock.calls[0][0]).toMatch(/writer/);
});
});

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

import warning from 'warning';
import { warning } from '../helpers/warning';
import {

@@ -187,2 +186,6 @@ getFragments,

if (process.env.NODE_ENV !== 'production' && schemaPredicates) {
schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
// We temporarily store the data field in here, but undefined

@@ -330,6 +333,7 @@ // means that the value is missing from the cache

false,
'Invalid resolver value: The resolver at `%s` returned a scalar (number, boolean, etc)' +
'Invalid resolver value: The resolver at `' +
key +
'` returned a scalar (number, boolean, etc)' +
', but the GraphQL query expects a selection set for this field.\n' +
'If necessary, use Cache.resolve() to resolve a link or entity from the cache.',
key
'If necessary, use Cache.resolve() to resolve a link or entity from the cache.'
);

@@ -336,0 +340,0 @@

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

import warning from 'warning';
import { warning } from '../helpers/warning';
import { FieldNode, InlineFragmentNode, FragmentDefinitionNode } from 'graphql';

@@ -37,9 +37,12 @@ import { Fragments, Variables, SelectionSet, Scalar } from '../types';

false,
'Heuristic Fragment Matching: A fragment is trying to match against the `%s` type, ' +
'but the type condition is `%s`. Since GraphQL allows for interfaces `%s` may be an' +
'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 an' +
'interface.\nA schema needs to be defined for this match to be deterministic, ' +
'otherwise the fragment will be matched heuristically!',
typename,
typeCondition,
typeCondition
'otherwise the fragment will be matched heuristically!'
);

@@ -46,0 +49,0 @@

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

import warning from 'warning';
import { warning } from '../helpers/warning';
import { DocumentNode, FragmentDefinitionNode } from 'graphql';

@@ -166,4 +166,5 @@

"Can't generate a key for writeFragment(...) data.\n" +
'You have to pass an `id` or `_id` field or create a custom `keys` config for `%s`.',
typeName
'You have to pass an `id` or `_id` field or create a custom `keys` config for `' +
typeName +
'`.'
);

@@ -206,2 +207,7 @@ }

if (isQuery) addDependency(fieldKey);
if (process.env.NODE_ENV !== 'production' && ctx.schemaPredicates) {
ctx.schemaPredicates.isFieldAvailableOnType(typename, fieldName);
}
if (node.selectionSet === undefined) {

@@ -219,6 +225,7 @@ // This is a leaf node, so we're setting the field's value directly

false,
'Invalid value: The field at `%s` is a scalar (number, boolean, etc)' +
'Invalid value: The field at `' +
fieldKey +
'` is a scalar (number, boolean, etc)' +
', but the GraphQL query expects a selection set for this field.\n' +
'The value will still be cached, however this may lead to undefined behavior!',
fieldKey
'The value will still be cached, however this may lead to undefined behavior!'
);

@@ -258,16 +265,23 @@

warning(
if (
typeof data.__typename !== 'string' ||
ctx.store.keys[data.__typename] !== undefined ||
entityKey !== null,
'Invalid key: The GraphQL query at the field at `%s` has a selection set, ' +
'but no key could be generated for the data at this field.\n' +
'You have to request `id` or `_id` fields for all selection sets or create ' +
'a custom `keys` config for `%s`.\n' +
'Entities without keys will be embedded directly on the parent entity. ' +
'If this is intentional, create a `keys` config for `%s` that always returns null.',
parentFieldKey,
data.__typename,
data.__typename
);
ctx.store.keys[data.__typename] !== undefined ||
entityKey !== null
) {
warning(
false,
'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.\n' +
'You have to request `id` or `_id` fields for all selection sets or create ' +
'a custom `keys` config for `' +
data.__typename +
'`.\n' +
'Entities without keys will be embedded directly on the parent entity. ' +
'If this is intentional, create a `keys` config for `' +
data.__typename +
'` that always returns null.'
);
}

@@ -274,0 +288,0 @@ writeSelection(ctx, key, select, data);

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