Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@urql/exchange-graphcache

Package Overview
Dependencies
Maintainers
3
Versions
298
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.10 to 1.0.0-rc.11

src/ast/traversal.test.ts

10

CHANGELOG.md

@@ -11,2 +11,12 @@ # Changelog

## [v1.0.0-rc.11](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.0-rc.10...v1.0.0-rc.11)
- Fix `updates` not being called for `optimistic` results (see [#83](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/83))
- Add optional `variables` argument to `readFragment` and `writeFragment` (see [#84](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/84))
- ⚠ Fix field arguments not normalising optional `null` values (see [#85](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/85))
## [v1.0.0-rc.10](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.0-rc.9...v1.0.0-rc.10)
- ⚠ Fix removing cache entries by upgrading to Pessimism `1.1.4` (see [ae72d3](https://github.com/FormidableLabs/urql-exchange-graphcache/commit/ae72d3b1c8b3e5965e122d5509eb561f68579474))
## [v1.0.0-rc.9](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.0-rc.8...v1.0.0-rc.9)

@@ -13,0 +23,0 @@

4

dist/types/ast/variables.d.ts

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

import { FieldNode, ValueNode, OperationDefinitionNode } from 'graphql';
import { FieldNode, OperationDefinitionNode } from 'graphql';
import { Variables } from '../types';
/** Evaluates a given ValueNode to a JSON value taking vars into account */
export declare const evaluateValueNode: (node: ValueNode, vars: Variables) => any;
/** Evaluates a fields arguments taking vars into account */

@@ -6,0 +4,0 @@ export declare const getFieldArguments: (node: FieldNode, vars: Variables) => Variables | null;

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

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

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

export declare const read: (store: Store, request: OperationRequest, input?: Data | undefined) => QueryResult;
export declare const readFragment: (store: Store, query: DocumentNode, entity: string | Data) => Data | null;
export declare const readFragment: (store: Store, query: DocumentNode, entity: string | Data, variables?: Variables | undefined) => Data | null;
import { DocumentNode } from 'graphql';
import { Data, OperationRequest } from '../types';
import { Variables, Data, OperationRequest } from '../types';
import { Store } from '../store';

@@ -11,2 +11,2 @@ export interface WriteResult {

export declare const writeOptimistic: (store: Store, request: OperationRequest, optimisticKey: number) => WriteResult;
export declare const writeFragment: (store: Store, query: DocumentNode, data: Data) => void;
export declare const writeFragment: (store: Store, query: DocumentNode, data: Data, variables?: Variables | undefined) => void;

@@ -51,5 +51,5 @@ import { DocumentNode } from 'graphql';

readQuery(input: QueryInput): Data | null;
readFragment(dataFragment: DocumentNode, entity: string | Data): Data | null;
writeFragment(dataFragment: DocumentNode, data: Data): void;
readFragment(dataFragment: DocumentNode, entity: string | Data, variables?: Variables): Data | null;
writeFragment(dataFragment: DocumentNode, data: Data, variables?: Variables): void;
}
export {};

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

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

@@ -63,37 +63,2 @@ import { createRequest, formatDocument } from "urql";

var evaluateValueNode = function(node, vars) {
switch (node.kind) {
case Kind.NULL:
return null;
case Kind.INT:
return parseInt(node.value, 10);
case Kind.FLOAT:
return parseFloat(node.value);
case Kind.LIST:
var values = new Array(node.values.length);
for (var i = 0, l = node.values.length; i < l; i++) {
values[i] = evaluateValueNode(node.values[i], vars);
}
return values;
case Kind.OBJECT:
var fields = Object.create(null);
for (var i$1 = 0, l$1 = node.fields.length; i$1 < l$1; i$1++) {
var field = node.fields[i$1];
fields[getName(field)] = evaluateValueNode(field.value, vars);
}
return fields;
case Kind.VARIABLE:
var varValue = vars[getName(node)];
return void 0 !== varValue ? varValue : null;
default:
return node.value;
}
};
var getFieldArguments = function(node, vars) {

@@ -104,7 +69,12 @@ if (void 0 === node.arguments || 0 === node.arguments.length) {

var args = Object.create(null);
var argsSize = 0;
for (var i = 0, l = node.arguments.length; i < l; i++) {
var arg = node.arguments[i];
args[getName(arg)] = evaluateValueNode(arg.value, vars);
var value = valueFromASTUntyped(arg.value, vars);
if (null != value) {
args[getName(arg)] = value;
argsSize++;
}
}
return args;
return argsSize > 0 ? args : null;
};

@@ -122,3 +92,3 @@

if (void 0 !== def.defaultValue) {
value = evaluateValueNode(def.defaultValue, args);
value = valueFromASTUntyped(def.defaultValue, args);
} else {

@@ -194,3 +164,3 @@ return vars;

}
var value = evaluateValueNode(arg.value, vars);
var value = valueFromASTUntyped(arg.value, vars);
if ("boolean" != typeof value && null !== value) {

@@ -318,24 +288,28 @@ continue;

store: store,
schemaPredicates: store.schemaPredicates
schemaPredicates: store.schemaPredicates,
isOptimistic: !0
};
if ("development" === process.env.NODE_ENV) {
ctx.isOptimistic = !0;
}
var mutationRootKey = ctx.store.getRootKey("mutation");
var operationName = ctx.store.getRootKey(operation.operation);
if (operationName === ctx.store.getRootKey("mutation")) {
var select = getSelectionSet(operation);
var iter = new SelectionIterator(operationName, operationName, select, ctx);
var node;
while (void 0 !== (node = iter.next())) {
if (void 0 !== node.selectionSet) {
var fieldName = getName(node);
var resolver = ctx.store.optimisticMutations[fieldName];
if (void 0 !== resolver) {
var fieldArgs = getFieldArguments(node, ctx.variables);
var fieldSelect = getSelectionSet(node);
var resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
"production" !== process.env.NODE_ENV && browser(operationName === mutationRootKey, "writeOptimistic(...) was called with an operation that is not a mutation.\nThis case is unsupported and should never occur.");
var select = getSelectionSet(operation);
var data = Object.create(null);
var iter = new SelectionIterator(operationName, operationName, select, ctx);
var node;
while (void 0 !== (node = iter.next())) {
if (void 0 !== node.selectionSet) {
var fieldName = getName(node);
var resolver = ctx.store.optimisticMutations[fieldName];
if (void 0 !== resolver) {
var fieldArgs = getFieldArguments(node, ctx.variables);
var fieldSelect = getSelectionSet(node);
var resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
data[fieldName] = resolverValue;
var updater = ctx.store.updates[mutationRootKey][fieldName];
if (void 0 !== updater) {
updater(data, fieldArgs || {}, ctx.store, ctx);
}
}

@@ -348,3 +322,3 @@ }

var writeFragment = function(store, query, data) {
var writeFragment = function(store, query, data, variables) {
var fragments = getFragments(query);

@@ -365,3 +339,3 @@ var fragment = fragments[Object.keys(fragments)[0]];

var ctx = {
variables: {},
variables: variables || {},
fragments: fragments,

@@ -442,2 +416,3 @@ result: {

var writeRoot = function(ctx, typename, select, data) {
var isRootField = typename === ctx.store.getRootKey("mutation") || typename === ctx.store.getRootKey("subscription");
var iter = new SelectionIterator(typename, typename, select, ctx);

@@ -454,3 +429,3 @@ var node;

}
if (typename === ctx.store.getRootKey("mutation") || typename === ctx.store.getRootKey("subscription")) {
if (isRootField) {
var updater = ctx.store.updates[typename][fieldName];

@@ -734,8 +709,8 @@ if (void 0 !== updater) {

Store.prototype.readFragment = function readFragment$1(dataFragment, entity) {
return readFragment(this, dataFragment, entity);
Store.prototype.readFragment = function readFragment$1(dataFragment, entity, variables) {
return readFragment(this, dataFragment, entity, variables);
};
Store.prototype.writeFragment = function writeFragment$1(dataFragment, data) {
writeFragment(this, dataFragment, data);
Store.prototype.writeFragment = function writeFragment$1(dataFragment, data, variables) {
writeFragment(this, dataFragment, data, variables);
};

@@ -810,3 +785,3 @@

var readFragment = function(store, query, entity) {
var readFragment = function(store, query, entity, variables) {
var fragments = getFragments(query);

@@ -831,3 +806,3 @@ var fragment = fragments[Object.keys(fragments)[0]];

return readSelection({
variables: {},
variables: variables || {},
fragments: fragments,

@@ -834,0 +809,0 @@ partial: !1,

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

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

@@ -67,37 +67,2 @@ "use strict";

var evaluateValueNode = function(node, vars) {
switch (node.kind) {
case graphql.Kind.NULL:
return null;
case graphql.Kind.INT:
return parseInt(node.value, 10);
case graphql.Kind.FLOAT:
return parseFloat(node.value);
case graphql.Kind.LIST:
var values = new Array(node.values.length);
for (var i = 0, l = node.values.length; i < l; i++) {
values[i] = evaluateValueNode(node.values[i], vars);
}
return values;
case graphql.Kind.OBJECT:
var fields = Object.create(null);
for (var i$1 = 0, l$1 = node.fields.length; i$1 < l$1; i$1++) {
var field = node.fields[i$1];
fields[getName(field)] = evaluateValueNode(field.value, vars);
}
return fields;
case graphql.Kind.VARIABLE:
var varValue = vars[getName(node)];
return void 0 !== varValue ? varValue : null;
default:
return node.value;
}
};
var getFieldArguments = function(node, vars) {

@@ -108,7 +73,12 @@ if (void 0 === node.arguments || 0 === node.arguments.length) {

var args = Object.create(null);
var argsSize = 0;
for (var i = 0, l = node.arguments.length; i < l; i++) {
var arg = node.arguments[i];
args[getName(arg)] = evaluateValueNode(arg.value, vars);
var value = graphql.valueFromASTUntyped(arg.value, vars);
if (null != value) {
args[getName(arg)] = value;
argsSize++;
}
}
return args;
return argsSize > 0 ? args : null;
};

@@ -126,3 +96,3 @@

if (void 0 !== def.defaultValue) {
value = evaluateValueNode(def.defaultValue, args);
value = graphql.valueFromASTUntyped(def.defaultValue, args);
} else {

@@ -198,3 +168,3 @@ return vars;

}
var value = evaluateValueNode(arg.value, vars);
var value = graphql.valueFromASTUntyped(arg.value, vars);
if ("boolean" != typeof value && null !== value) {

@@ -322,24 +292,28 @@ continue;

store: store,
schemaPredicates: store.schemaPredicates
schemaPredicates: store.schemaPredicates,
isOptimistic: !0
};
if ("development" === process.env.NODE_ENV) {
ctx.isOptimistic = !0;
}
var mutationRootKey = ctx.store.getRootKey("mutation");
var operationName = ctx.store.getRootKey(operation.operation);
if (operationName === ctx.store.getRootKey("mutation")) {
var select = getSelectionSet(operation);
var iter = new SelectionIterator(operationName, operationName, select, ctx);
var node;
while (void 0 !== (node = iter.next())) {
if (void 0 !== node.selectionSet) {
var fieldName = getName(node);
var resolver = ctx.store.optimisticMutations[fieldName];
if (void 0 !== resolver) {
var fieldArgs = getFieldArguments(node, ctx.variables);
var fieldSelect = getSelectionSet(node);
var resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
"production" !== process.env.NODE_ENV && browser(operationName === mutationRootKey, "writeOptimistic(...) was called with an operation that is not a mutation.\nThis case is unsupported and should never occur.");
var select = getSelectionSet(operation);
var data = Object.create(null);
var iter = new SelectionIterator(operationName, operationName, select, ctx);
var node;
while (void 0 !== (node = iter.next())) {
if (void 0 !== node.selectionSet) {
var fieldName = getName(node);
var resolver = ctx.store.optimisticMutations[fieldName];
if (void 0 !== resolver) {
var fieldArgs = getFieldArguments(node, ctx.variables);
var fieldSelect = getSelectionSet(node);
var resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
data[fieldName] = resolverValue;
var updater = ctx.store.updates[mutationRootKey][fieldName];
if (void 0 !== updater) {
updater(data, fieldArgs || {}, ctx.store, ctx);
}
}

@@ -352,3 +326,3 @@ }

var writeFragment = function(store, query, data) {
var writeFragment = function(store, query, data, variables) {
var fragments = getFragments(query);

@@ -369,3 +343,3 @@ var fragment = fragments[Object.keys(fragments)[0]];

var ctx = {
variables: {},
variables: variables || {},
fragments: fragments,

@@ -446,2 +420,3 @@ result: {

var writeRoot = function(ctx, typename, select, data) {
var isRootField = typename === ctx.store.getRootKey("mutation") || typename === ctx.store.getRootKey("subscription");
var iter = new SelectionIterator(typename, typename, select, ctx);

@@ -458,3 +433,3 @@ var node;

}
if (typename === ctx.store.getRootKey("mutation") || typename === ctx.store.getRootKey("subscription")) {
if (isRootField) {
var updater = ctx.store.updates[typename][fieldName];

@@ -738,8 +713,8 @@ if (void 0 !== updater) {

Store.prototype.readFragment = function readFragment$1(dataFragment, entity) {
return readFragment(this, dataFragment, entity);
Store.prototype.readFragment = function readFragment$1(dataFragment, entity, variables) {
return readFragment(this, dataFragment, entity, variables);
};
Store.prototype.writeFragment = function writeFragment$1(dataFragment, data) {
writeFragment(this, dataFragment, data);
Store.prototype.writeFragment = function writeFragment$1(dataFragment, data, variables) {
writeFragment(this, dataFragment, data, variables);
};

@@ -814,3 +789,3 @@

var readFragment = function(store, query, entity) {
var readFragment = function(store, query, entity, variables) {
var fragments = getFragments(query);

@@ -835,3 +810,3 @@ var fragment = fragments[Object.keys(fragments)[0]];

return readSelection({
variables: {},
variables: variables || {},
fragments: fragments,

@@ -838,0 +813,0 @@ partial: !1,

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

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

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

@@ -9,2 +9,3 @@ import invariant from 'invariant';

OperationDefinitionNode,
valueFromASTUntyped,
Kind,

@@ -14,3 +15,2 @@ } from 'graphql';

import { getName } from './node';
import { evaluateValueNode } from './variables';
import { Fragments, Variables } from '../types';

@@ -70,3 +70,3 @@

const value = evaluateValueNode(arg.value, vars);
const value = valueFromASTUntyped(arg.value, vars);
if (typeof value !== 'boolean' && value !== null) continue;

@@ -73,0 +73,0 @@

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

import { FieldNode, ValueNode, OperationDefinitionNode, Kind } from 'graphql';
import {
FieldNode,
OperationDefinitionNode,
valueFromASTUntyped,
} from 'graphql';

@@ -6,32 +10,2 @@ import { getName } from './node';

/** Evaluates a given ValueNode to a JSON value taking vars into account */
export const evaluateValueNode = (node: ValueNode, vars: Variables) => {
switch (node.kind) {
case Kind.NULL:
return null;
case Kind.INT:
return parseInt(node.value, 10);
case Kind.FLOAT:
return parseFloat(node.value);
case Kind.LIST:
const values = new Array(node.values.length);
for (let i = 0, l = node.values.length; i < l; i++)
values[i] = evaluateValueNode(node.values[i], vars);
return values;
case Kind.OBJECT:
const fields = Object.create(null);
for (let i = 0, l = node.fields.length; i < l; i++) {
const field = node.fields[i];
fields[getName(field)] = evaluateValueNode(field.value, vars);
}
return fields;
case Kind.VARIABLE:
const varValue = vars[getName(node)];
return varValue !== undefined ? varValue : null;
default:
return node.value;
}
};
/** Evaluates a fields arguments taking vars into account */

@@ -47,8 +21,14 @@ export const getFieldArguments = (

const args = Object.create(null);
let argsSize = 0;
for (let i = 0, l = node.arguments.length; i < l; i++) {
const arg = node.arguments[i];
args[getName(arg)] = evaluateValueNode(arg.value, vars);
const value = valueFromASTUntyped(arg.value, vars);
if (value !== undefined && value !== null) {
args[getName(arg)] = value;
argsSize++;
}
}
return args;
return argsSize > 0 ? args : null;
};

@@ -72,3 +52,3 @@

if (def.defaultValue !== undefined) {
value = evaluateValueNode(def.defaultValue, args);
value = valueFromASTUntyped(def.defaultValue, args);
} else {

@@ -75,0 +55,0 @@ return vars;

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

@@ -157,3 +158,4 @@ getFragments,

query: DocumentNode,
entity: Data | string
entity: Data | string,
variables?: Variables
): Data | null => {

@@ -197,3 +199,3 @@ const fragments = getFragments(query);

const ctx: Context = {
variables: {},
variables: variables || {},
fragments,

@@ -200,0 +202,0 @@ partial: false,

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

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

@@ -106,31 +107,36 @@ import { DocumentNode, FragmentDefinitionNode } from 'graphql';

schemaPredicates: store.schemaPredicates,
isOptimistic: true,
};
if (process.env.NODE_ENV === 'development') {
ctx.isOptimistic = true;
}
const mutationRootKey = ctx.store.getRootKey('mutation');
const operationName = ctx.store.getRootKey(operation.operation);
if (operationName === ctx.store.getRootKey('mutation')) {
const select = getSelectionSet(operation);
const iter = new SelectionIterator(
operationName,
operationName,
select,
ctx
);
invariant(
operationName === mutationRootKey,
'writeOptimistic(...) was called with an operation that is not a mutation.\n' +
'This case is unsupported and should never occur.'
);
let node;
while ((node = iter.next()) !== undefined) {
if (node.selectionSet !== undefined) {
const fieldName = getName(node);
const resolver = ctx.store.optimisticMutations[fieldName];
if (resolver !== undefined) {
const fieldArgs = getFieldArguments(node, ctx.variables);
const fieldSelect = getSelectionSet(node);
const resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
const select = getSelectionSet(operation);
const data = Object.create(null);
const iter = new SelectionIterator(operationName, operationName, select, ctx);
let node;
while ((node = iter.next()) !== undefined) {
if (node.selectionSet !== undefined) {
const fieldName = getName(node);
const resolver = ctx.store.optimisticMutations[fieldName];
if (resolver !== undefined) {
const fieldArgs = getFieldArguments(node, ctx.variables);
const fieldSelect = getSelectionSet(node);
const resolverValue = resolver(fieldArgs || {}, ctx.store, ctx);
if (!isScalar(resolverValue)) {
writeRootField(ctx, resolverValue, fieldSelect);
}
data[fieldName] = resolverValue;
const updater = ctx.store.updates[mutationRootKey][fieldName];
if (updater !== undefined) {
updater(data, fieldArgs || {}, ctx.store, ctx);
}
}

@@ -147,3 +153,4 @@ }

query: DocumentNode,
data: Data
data: Data,
variables?: Variables
) => {

@@ -176,3 +183,3 @@ const fragments = getFragments(query);

const ctx: Context = {
variables: {},
variables: variables || {},
fragments,

@@ -323,2 +330,6 @@ result: { dependencies: getCurrentDependencies() },

) => {
const isRootField =
typename === ctx.store.getRootKey('mutation') ||
typename === ctx.store.getRootKey('subscription');
const iter = new SelectionIterator(typename, typename, select, ctx);

@@ -342,6 +353,3 @@

if (
typename === ctx.store.getRootKey('mutation') ||
typename === ctx.store.getRootKey('subscription')
) {
if (isRootField) {
// We run side-effect updates after the default, normalized updates

@@ -348,0 +356,0 @@ // so that the data is already available in-store if necessary

@@ -275,9 +275,17 @@ import invariant from 'invariant';

readFragment(dataFragment: DocumentNode, entity: string | Data): Data | null {
return readFragment(this, dataFragment, entity);
readFragment(
dataFragment: DocumentNode,
entity: string | Data,
variables?: Variables
): Data | null {
return readFragment(this, dataFragment, entity, variables);
}
writeFragment(dataFragment: DocumentNode, data: Data): void {
writeFragment(this, dataFragment, data);
writeFragment(
dataFragment: DocumentNode,
data: Data,
variables?: Variables
): void {
writeFragment(this, dataFragment, data, variables);
}
}

@@ -119,2 +119,36 @@ import gql from 'graphql-tag';

it('resolves missing, nullable arguments on fields', () => {
const store = new Store();
const GetWithVariables = gql`
query {
todo(first: null) {
__typename
id
}
}
`;
const GetWithoutVariables = gql`
query {
todo {
__typename
id
}
}
`;
const writeData = {
__typename: 'Query',
todo: {
__typename: 'Todo',
id: '123',
},
};
write(store, { query: GetWithVariables }, writeData);
const { data } = query(store, { query: GetWithoutVariables });
expect(data).toEqual(writeData);
});
it('respects property-level resolvers when given', () => {

@@ -121,0 +155,0 @@ const store = new Store(undefined, {

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