apollo-cache
Advanced tools
Comparing version 1.1.7 to 1.1.8
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-utilities')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-utilities'], factory) : | ||
(factory((global.apollo = global.apollo || {}, global.apollo.cache = global.apollo.cache || {}, global.apollo.cache.core = {}),global.apollo.utilities)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-utilities')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-utilities'], factory) : | ||
(factory((global.apollo = global.apollo || {}, global.apollo.cache = global.apollo.cache || {}, global.apollo.cache.core = {}),global.apollo.utilities)); | ||
}(this, (function (exports,apolloUtilities) { 'use strict'; | ||
function queryFromPojo(obj) { | ||
var op = { | ||
kind: 'OperationDefinition', | ||
operation: 'query', | ||
name: { | ||
kind: 'Name', | ||
value: 'GeneratedClientQuery', | ||
}, | ||
selectionSet: selectionSetFromObj(obj), | ||
}; | ||
var out = { | ||
kind: 'Document', | ||
definitions: [op], | ||
}; | ||
return out; | ||
} | ||
function fragmentFromPojo(obj, typename) { | ||
var frag = { | ||
kind: 'FragmentDefinition', | ||
typeCondition: { | ||
kind: 'NamedType', | ||
function queryFromPojo(obj) { | ||
var op = { | ||
kind: 'OperationDefinition', | ||
operation: 'query', | ||
name: { | ||
kind: 'Name', | ||
value: typename || '__FakeType', | ||
value: 'GeneratedClientQuery', | ||
}, | ||
}, | ||
name: { | ||
kind: 'Name', | ||
value: 'GeneratedClientQuery', | ||
}, | ||
selectionSet: selectionSetFromObj(obj), | ||
}; | ||
var out = { | ||
kind: 'Document', | ||
definitions: [frag], | ||
}; | ||
return out; | ||
} | ||
function selectionSetFromObj(obj) { | ||
if (typeof obj === 'number' || | ||
typeof obj === 'boolean' || | ||
typeof obj === 'string' || | ||
typeof obj === 'undefined' || | ||
obj === null) { | ||
// No selection set here | ||
return null; | ||
selectionSet: selectionSetFromObj(obj), | ||
}; | ||
var out = { | ||
kind: 'Document', | ||
definitions: [op], | ||
}; | ||
return out; | ||
} | ||
if (Array.isArray(obj)) { | ||
// GraphQL queries don't include arrays | ||
return selectionSetFromObj(obj[0]); | ||
} | ||
// Now we know it's an object | ||
var selections = []; | ||
Object.keys(obj).forEach(function (key) { | ||
var field = { | ||
kind: 'Field', | ||
function fragmentFromPojo(obj, typename) { | ||
var frag = { | ||
kind: 'FragmentDefinition', | ||
typeCondition: { | ||
kind: 'NamedType', | ||
name: { | ||
kind: 'Name', | ||
value: typename || '__FakeType', | ||
}, | ||
}, | ||
name: { | ||
kind: 'Name', | ||
value: key, | ||
value: 'GeneratedClientQuery', | ||
}, | ||
selectionSet: selectionSetFromObj(obj), | ||
}; | ||
// Recurse | ||
var nestedSelSet = selectionSetFromObj(obj[key]); | ||
if (nestedSelSet) { | ||
field.selectionSet = nestedSelSet; | ||
var out = { | ||
kind: 'Document', | ||
definitions: [frag], | ||
}; | ||
return out; | ||
} | ||
function selectionSetFromObj(obj) { | ||
if (typeof obj === 'number' || | ||
typeof obj === 'boolean' || | ||
typeof obj === 'string' || | ||
typeof obj === 'undefined' || | ||
obj === null) { | ||
// No selection set here | ||
return null; | ||
} | ||
selections.push(field); | ||
}); | ||
var selectionSet = { | ||
kind: 'SelectionSet', | ||
selections: selections, | ||
}; | ||
return selectionSet; | ||
} | ||
var justTypenameQuery = { | ||
kind: 'Document', | ||
definitions: [ | ||
{ | ||
kind: 'OperationDefinition', | ||
operation: 'query', | ||
name: null, | ||
variableDefinitions: null, | ||
directives: [], | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: [ | ||
{ | ||
kind: 'Field', | ||
alias: null, | ||
name: { | ||
kind: 'Name', | ||
value: '__typename', | ||
if (Array.isArray(obj)) { | ||
// GraphQL queries don't include arrays | ||
return selectionSetFromObj(obj[0]); | ||
} | ||
// Now we know it's an object | ||
var selections = []; | ||
Object.keys(obj).forEach(function (key) { | ||
var field = { | ||
kind: 'Field', | ||
name: { | ||
kind: 'Name', | ||
value: key, | ||
}, | ||
}; | ||
// Recurse | ||
var nestedSelSet = selectionSetFromObj(obj[key]); | ||
if (nestedSelSet) { | ||
field.selectionSet = nestedSelSet; | ||
} | ||
selections.push(field); | ||
}); | ||
var selectionSet = { | ||
kind: 'SelectionSet', | ||
selections: selections, | ||
}; | ||
return selectionSet; | ||
} | ||
var justTypenameQuery = { | ||
kind: 'Document', | ||
definitions: [ | ||
{ | ||
kind: 'OperationDefinition', | ||
operation: 'query', | ||
name: null, | ||
variableDefinitions: null, | ||
directives: [], | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: [ | ||
{ | ||
kind: 'Field', | ||
alias: null, | ||
name: { | ||
kind: 'Name', | ||
value: '__typename', | ||
}, | ||
arguments: [], | ||
directives: [], | ||
selectionSet: null, | ||
}, | ||
arguments: [], | ||
directives: [], | ||
selectionSet: null, | ||
}, | ||
], | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
], | ||
}; | ||
var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var ApolloCache = /** @class */ (function () { | ||
function ApolloCache() { | ||
} | ||
// optional API | ||
ApolloCache.prototype.transformDocument = function (document) { | ||
return document; | ||
var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
// experimental | ||
ApolloCache.prototype.transformForLink = function (document) { | ||
return document; | ||
}; | ||
// DataProxy API | ||
/** | ||
* | ||
* @param options | ||
* @param optimistic | ||
*/ | ||
ApolloCache.prototype.readQuery = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
return this.read({ | ||
query: options.query, | ||
variables: options.variables, | ||
optimistic: optimistic, | ||
}); | ||
}; | ||
ApolloCache.prototype.readFragment = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
return this.read({ | ||
query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
variables: options.variables, | ||
rootId: options.id, | ||
optimistic: optimistic, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeQuery = function (options) { | ||
this.write({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
query: options.query, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeFragment = function (options) { | ||
this.write({ | ||
dataId: options.id, | ||
result: options.data, | ||
variables: options.variables, | ||
query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
}); | ||
}; | ||
ApolloCache.prototype.writeData = function (_a) { | ||
var id = _a.id, data = _a.data; | ||
if (typeof id !== 'undefined') { | ||
var typenameResult = null; | ||
// Since we can't use fragments without having a typename in the store, | ||
// we need to make sure we have one. | ||
// To avoid overwriting an existing typename, we need to read it out first | ||
// and generate a fake one if none exists. | ||
try { | ||
typenameResult = this.read({ | ||
rootId: id, | ||
optimistic: false, | ||
query: justTypenameQuery, | ||
var ApolloCache = /** @class */ (function () { | ||
function ApolloCache() { | ||
} | ||
// optional API | ||
ApolloCache.prototype.transformDocument = function (document) { | ||
return document; | ||
}; | ||
// experimental | ||
ApolloCache.prototype.transformForLink = function (document) { | ||
return document; | ||
}; | ||
// DataProxy API | ||
/** | ||
* | ||
* @param options | ||
* @param optimistic | ||
*/ | ||
ApolloCache.prototype.readQuery = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
return this.read({ | ||
query: options.query, | ||
variables: options.variables, | ||
optimistic: optimistic, | ||
}); | ||
}; | ||
ApolloCache.prototype.readFragment = function (options, optimistic) { | ||
if (optimistic === void 0) { optimistic = false; } | ||
return this.read({ | ||
query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
variables: options.variables, | ||
rootId: options.id, | ||
optimistic: optimistic, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeQuery = function (options) { | ||
this.write({ | ||
dataId: 'ROOT_QUERY', | ||
result: options.data, | ||
query: options.query, | ||
variables: options.variables, | ||
}); | ||
}; | ||
ApolloCache.prototype.writeFragment = function (options) { | ||
this.write({ | ||
dataId: options.id, | ||
result: options.data, | ||
variables: options.variables, | ||
query: apolloUtilities.getFragmentQueryDocument(options.fragment, options.fragmentName), | ||
}); | ||
}; | ||
ApolloCache.prototype.writeData = function (_a) { | ||
var id = _a.id, data = _a.data; | ||
if (typeof id !== 'undefined') { | ||
var typenameResult = null; | ||
// Since we can't use fragments without having a typename in the store, | ||
// we need to make sure we have one. | ||
// To avoid overwriting an existing typename, we need to read it out first | ||
// and generate a fake one if none exists. | ||
try { | ||
typenameResult = this.read({ | ||
rootId: id, | ||
optimistic: false, | ||
query: justTypenameQuery, | ||
}); | ||
} | ||
catch (e) { | ||
// Do nothing, since an error just means no typename exists | ||
} | ||
// tslint:disable-next-line | ||
var __typename = (typenameResult && typenameResult.__typename) || '__ClientData'; | ||
// Add a type here to satisfy the inmemory cache | ||
var dataToWrite = __assign({ __typename: __typename }, data); | ||
this.writeFragment({ | ||
id: id, | ||
fragment: fragmentFromPojo(dataToWrite, __typename), | ||
data: dataToWrite, | ||
}); | ||
} | ||
catch (e) { | ||
// Do nothing, since an error just means no typename exists | ||
else { | ||
this.writeQuery({ query: queryFromPojo(data), data: data }); | ||
} | ||
// tslint:disable-next-line | ||
var __typename = (typenameResult && typenameResult.__typename) || '__ClientData'; | ||
// Add a type here to satisfy the inmemory cache | ||
var dataToWrite = __assign({ __typename: __typename }, data); | ||
this.writeFragment({ | ||
id: id, | ||
fragment: fragmentFromPojo(dataToWrite, __typename), | ||
data: dataToWrite, | ||
}); | ||
} | ||
else { | ||
this.writeQuery({ query: queryFromPojo(data), data: data }); | ||
} | ||
}; | ||
return ApolloCache; | ||
}()); | ||
}; | ||
return ApolloCache; | ||
}()); | ||
(function (Cache) { | ||
})(exports.Cache || (exports.Cache = {})); | ||
(function (Cache) { | ||
})(exports.Cache || (exports.Cache = {})); | ||
exports.ApolloCache = ApolloCache; | ||
exports.ApolloCache = ApolloCache; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=bundle.umd.js.map |
{ | ||
"name": "apollo-cache", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -41,13 +41,13 @@ "author": "James Baxley <james@meteor.com>", | ||
"dependencies": { | ||
"apollo-utilities": "^1.0.11" | ||
"apollo-utilities": "^1.0.12" | ||
}, | ||
"devDependencies": { | ||
"@types/graphql": "0.12.5", | ||
"@types/graphql": "0.12.7", | ||
"@types/jest": "21.1.10", | ||
"browserify": "15.2.0", | ||
"graphql": "0.13.2", | ||
"graphql-tag": "2.8.0", | ||
"graphql-tag": "2.9.2", | ||
"jest": "20.0.4", | ||
"rimraf": "2.6.2", | ||
"rollup": "0.56.4", | ||
"rollup": "0.58.2", | ||
"rollup-plugin-node-resolve": "3.3.0", | ||
@@ -54,0 +54,0 @@ "ts-jest": "20.0.14", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60361
1
Updatedapollo-utilities@^1.0.12