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.7 to 1.0.0-rc.8

7

CHANGELOG.md

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

## [v1.0.0-rc.8](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.0-rc.7...v1.0.0-rc.8)
- Fix warnings being shown for Relay `Connection` and `Edge` embedded types (see [#79](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/79))
- Implement `readFragment` method on `Store` (see [#73](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/73))
- Implement `readQuery` method on `Store` (see [#73](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/73))
- Improve `writeFragment` method on `Store` (see [#73](https://github.com/FormidableLabs/urql-exchange-graphcache/pull/73))
## [v1.0.0-rc.7](https://github.com/FormidableLabs/urql-exchange-graphcache/compare/v1.0.0-rc.6...v1.0.0-rc.7)

@@ -13,0 +20,0 @@

2

dist/types/operations/query.d.ts
import { Data, OperationRequest } from '../types';
import { Store } from '../store';
import { DocumentNode } from 'graphql';
export interface QueryResult {

@@ -10,1 +11,2 @@ dependencies: Set<string>;

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;

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

declare type RootField = 'query' | 'mutation' | 'subscription';
interface QueryInput {
query: string | DocumentNode;
variables?: Variables;
}
export declare class Store {

@@ -47,4 +51,6 @@ records: Pessimism.Map<EntityField>;

}, updater: (data: Data | null) => null | Data): void;
readQuery(input: QueryInput): Data | null;
readFragment(dataFragment: DocumentNode, entity: string | Data): Data | null;
writeFragment(dataFragment: DocumentNode, data: Data): void;
}
export {};

83

dist/urql-exchange-graphcache.es.js

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

function _extends() {
return (_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
}).apply(this, arguments);
}
var cache = {};

@@ -25,2 +39,6 @@

var getFragmentTypeName = function(node) {
return node.typeCondition.name.value;
};
var getFieldAlias = function(node) {

@@ -192,16 +210,2 @@ return void 0 !== node.alias ? node.alias.value : getName(node);

function _extends() {
return (_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
}).apply(this, arguments);
}
var isFragmentHeuristicallyMatching = function(node, typename, entityKey, ctx) {

@@ -349,9 +353,9 @@ if (!typename) {

var select = getSelectionSet(fragment);
var typeName = fragment.typeCondition.name.value;
var writeData = _extends({}, data, {
__typename: typeName
});
var typename = getFragmentTypeName(fragment);
var writeData = _extends({
__typename: typename
}, data);
var entityKey = store.keyOfEntity(writeData);
if (!entityKey) {
return "production" !== process.env.NODE_ENV ? warning(!1, "Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typeName + "`.") : 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;
}

@@ -427,3 +431,4 @@ var ctx = {

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.");
var typename = data.__typename;
"production" !== process.env.NODE_ENV && warning(typename.endsWith("Connection") || typename.endsWith("Edge"), "Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.");
}

@@ -715,3 +720,3 @@ writeSelection(ctx, key, select, data);

var request = createRequest(input.query, input.variables);
var output = updater(read(this, request).data);
var output = updater(this.readQuery(request));
if (null !== output) {

@@ -722,2 +727,10 @@ startWrite(this, request, output);

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

@@ -794,2 +807,30 @@ writeFragment(this, dataFragment, data);

var readFragment = function(store, query, entity) {
var fragments = getFragments(query);
var fragment = fragments[Object.keys(fragments)[0]];
if (void 0 === fragment) {
"production" !== process.env.NODE_ENV && warning(!1, "readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.");
return null;
}
var select = getSelectionSet(fragment);
var typename = getFragmentTypeName(fragment);
if ("string" != typeof entity && !entity.__typename) {
entity.__typename = typename;
}
var entityKey = "string" != typeof entity ? store.keyOfEntity(_extends({
__typename: typename
}, entity)) : entity;
if (!entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.");
return null;
}
return readSelection({
variables: {},
fragments: fragments,
partial: !1,
store: store,
schemaPredicates: store.schemaPredicates
}, entityKey, select, Object.create(null)) || null;
};
var readSelection = function(ctx, entityKey, select, data) {

@@ -796,0 +837,0 @@ var store = ctx.store;

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

@@ -15,2 +15,16 @@ "use strict";

function _extends() {
return (_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
}).apply(this, arguments);
}
var cache = {};

@@ -29,2 +43,6 @@

var getFragmentTypeName = function(node) {
return node.typeCondition.name.value;
};
var getFieldAlias = function(node) {

@@ -196,16 +214,2 @@ return void 0 !== node.alias ? node.alias.value : getName(node);

function _extends() {
return (_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
}).apply(this, arguments);
}
var isFragmentHeuristicallyMatching = function(node, typename, entityKey, ctx) {

@@ -353,9 +357,9 @@ if (!typename) {

var select = getSelectionSet(fragment);
var typeName = fragment.typeCondition.name.value;
var writeData = _extends({}, data, {
__typename: typeName
});
var typename = getFragmentTypeName(fragment);
var writeData = _extends({
__typename: typename
}, data);
var entityKey = store.keyOfEntity(writeData);
if (!entityKey) {
return "production" !== process.env.NODE_ENV ? warning(!1, "Can't generate a key for writeFragment(...) data.\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typeName + "`.") : 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;
}

@@ -431,3 +435,4 @@ var ctx = {

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.");
var typename = data.__typename;
"production" !== process.env.NODE_ENV && warning(typename.endsWith("Connection") || typename.endsWith("Edge"), "Invalid key: The GraphQL query at the field at `" + parentFieldKey + "` has a selection set, but no key could be generated for the data at this field.\nYou have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `" + typename + "`.\nEntities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `" + typename + "` that always returns null.");
}

@@ -719,3 +724,3 @@ writeSelection(ctx, key, select, data);

var request = urql.createRequest(input.query, input.variables);
var output = updater(read(this, request).data);
var output = updater(this.readQuery(request));
if (null !== output) {

@@ -726,2 +731,10 @@ startWrite(this, request, output);

Store.prototype.readQuery = function readQuery(input) {
return read(this, urql.createRequest(input.query, input.variables)).data;
};
Store.prototype.readFragment = function readFragment$1(dataFragment, entity) {
return readFragment(this, dataFragment, entity);
};
Store.prototype.writeFragment = function writeFragment$1(dataFragment, data) {

@@ -798,2 +811,30 @@ writeFragment(this, dataFragment, data);

var readFragment = function(store, query, entity) {
var fragments = getFragments(query);
var fragment = fragments[Object.keys(fragments)[0]];
if (void 0 === fragment) {
"production" !== process.env.NODE_ENV && warning(!1, "readFragment(...) was called with an empty fragment.\nYou have to call it with at least one fragment in your GraphQL document.");
return null;
}
var select = getSelectionSet(fragment);
var typename = getFragmentTypeName(fragment);
if ("string" != typeof entity && !entity.__typename) {
entity.__typename = typename;
}
var entityKey = "string" != typeof entity ? store.keyOfEntity(_extends({
__typename: typename
}, entity)) : entity;
if (!entityKey) {
"production" !== process.env.NODE_ENV && warning(!1, "Can't generate a key for readFragment(...).\nYou have to pass an `id` or `_id` field or create a custom `keys` config for `" + typename + "`.");
return null;
}
return readSelection({
variables: {},
fragments: fragments,
partial: !1,
store: store,
schemaPredicates: store.schemaPredicates
}, entityKey, select, Object.create(null)) || null;
};
var readSelection = function(ctx, entityKey, select, data) {

@@ -800,0 +841,0 @@ var store = ctx.store;

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

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

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

getFieldAlias,
getFragmentTypeName,
} from '../ast';

@@ -35,2 +36,3 @@

import { SchemaPredicates } from '../ast/schemaPredicates';
import { DocumentNode, FragmentDefinitionNode } from 'graphql';

@@ -154,2 +156,54 @@ export interface QueryResult {

export const readFragment = (
store: Store,
query: DocumentNode,
entity: Data | string
): Data | null => {
const fragments = getFragments(query);
const names = Object.keys(fragments);
const fragment = fragments[names[0]] as FragmentDefinitionNode;
if (fragment === undefined) {
warning(
false,
'readFragment(...) was called with an empty fragment.\n' +
'You have to call it with at least one fragment in your GraphQL document.'
);
return null;
}
const select = getSelectionSet(fragment);
const typename = getFragmentTypeName(fragment);
if (typeof entity !== 'string' && !entity.__typename) {
entity.__typename = typename;
}
const entityKey =
typeof entity !== 'string'
? store.keyOfEntity({ __typename: typename, ...entity } as Data)
: entity;
if (!entityKey) {
warning(
false,
"Can't generate a key for readFragment(...).\n" +
'You have to pass an `id` or `_id` field or create a custom `keys` config for `' +
typename +
'`.'
);
return null;
}
const ctx: Context = {
variables: {},
fragments,
partial: false,
store,
schemaPredicates: store.schemaPredicates,
};
return readSelection(ctx, entityKey, select, Object.create(null)) || null;
};
const readSelection = (

@@ -156,0 +210,0 @@ ctx: Context,

@@ -160,6 +160,5 @@ import { warning } from '../helpers/warning';

const select = getSelectionSet(fragment);
const typeName = getFragmentTypeName(fragment);
const writeData = { ...data, __typename: typeName } as Data;
const entityKey = store.keyOfEntity(writeData) as string;
const typename = getFragmentTypeName(fragment);
const writeData = { __typename: typename, ...data } as Data;
const entityKey = store.keyOfEntity(writeData);
if (!entityKey) {

@@ -170,3 +169,3 @@ return warning(

'You have to pass an `id` or `_id` field or create a custom `keys` config for `' +
typeName +
typename +
'`.'

@@ -177,3 +176,3 @@ );

const ctx: Context = {
variables: {}, // TODO: Should we support variables?
variables: {},
fragments,

@@ -294,4 +293,6 @@ result: { dependencies: getCurrentDependencies() },

) {
const typename = data.__typename;
warning(
false,
typename.endsWith('Connection') || typename.endsWith('Edge'),
'Invalid key: The GraphQL query at the field at `' +

@@ -303,7 +304,7 @@ parentFieldKey +

'a custom `keys` config for `' +
data.__typename +
typename +
'`.\n' +
'Entities without keys will be embedded directly on the parent entity. ' +
'If this is intentional, create a `keys` config for `' +
data.__typename +
typename +
'` that always returns null.'

@@ -310,0 +311,0 @@ );

@@ -184,4 +184,5 @@ import gql from 'graphql-tag';

it('should be able to update a fragment', () => {
it('should be able to write a fragment', () => {
initStoreState(0);
store.writeFragment(

@@ -222,2 +223,28 @@ gql`

it('should be able to read a fragment', () => {
initStoreState(0);
const result = store.readFragment(
gql`
fragment _ on Todo {
id
text
complete
}
`,
{ id: '0' }
);
const deps = getCurrentDependencies();
expect(deps).toEqual(new Set(['Todo:0']));
expect(result).toEqual({
id: '0',
text: 'Go to the shops',
complete: false,
__typename: 'Todo',
});
clearStoreState();
});
it('should be able to update a query', () => {

@@ -308,2 +335,25 @@ initStoreState(0);

it('should be able to read a query', () => {
initStoreState(0);
const result = store.readQuery({ query: Todos });
const deps = getCurrentDependencies();
expect(deps).toEqual(
new Set([
'Query.todos',
'Todo:0',
'Todo:1',
'Todo:2',
'Author:0',
'Author:1',
])
);
expect(result).toEqual({
__typename: 'Query',
todos: todosData.todos,
});
clearStoreState();
});
it('should be able to optimistically mutate', () => {

@@ -310,0 +360,0 @@ const { dependencies } = writeOptimistic(

@@ -19,3 +19,3 @@ import invariant from 'invariant';

import { joinKeys, keyOfField } from './helpers';
import { read } from './operations/query';
import { read, readFragment } from './operations/query';
import { writeFragment, startWrite } from './operations/write';

@@ -78,2 +78,7 @@ import { invalidate } from './operations/invalidate';

interface QueryInput {
query: string | DocumentNode;
variables?: Variables;
}
export class Store {

@@ -262,3 +267,3 @@ records: Pessimism.Map<EntityField>;

const request = createRequest(input.query, input.variables);
const output = updater(read(this, request).data);
const output = updater(this.readQuery(request as QueryInput));
if (output !== null) {

@@ -269,2 +274,10 @@ startWrite(this, request, output);

readQuery(input: QueryInput): Data | null {
return read(this, createRequest(input.query, input.variables)).data;
}
readFragment(dataFragment: DocumentNode, entity: string | Data): Data | null {
return readFragment(this, dataFragment, entity);
}
writeFragment(dataFragment: DocumentNode, data: Data): void {

@@ -271,0 +284,0 @@ writeFragment(this, dataFragment, 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