This commit is contained in:
2
node_modules/apollo-cache-inmemory/lib/__tests__/cache.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/cache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=cache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/cache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/cache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/__tests__/cache.ts"],"names":[],"mappings":""}
|
||||
627
node_modules/apollo-cache-inmemory/lib/__tests__/cache.js
generated
vendored
Normal file
627
node_modules/apollo-cache-inmemory/lib/__tests__/cache.js
generated
vendored
Normal file
@@ -0,0 +1,627 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var graphql_tag_1 = tslib_1.__importStar(require("graphql-tag"));
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var lodash_1 = require("lodash");
|
||||
var __1 = require("..");
|
||||
graphql_tag_1.disableFragmentWarnings();
|
||||
describe('Cache', function () {
|
||||
function itWithInitialData(message, initialDataForCaches, callback) {
|
||||
var cachesList = [
|
||||
initialDataForCaches.map(function (data) {
|
||||
return new __1.InMemoryCache({
|
||||
addTypename: false,
|
||||
}).restore(lodash_1.cloneDeep(data));
|
||||
}),
|
||||
initialDataForCaches.map(function (data) {
|
||||
return new __1.InMemoryCache({
|
||||
addTypename: false,
|
||||
resultCaching: false,
|
||||
}).restore(lodash_1.cloneDeep(data));
|
||||
}),
|
||||
initialDataForCaches.map(function (data) {
|
||||
return new __1.InMemoryCache({
|
||||
addTypename: false,
|
||||
freezeResults: true,
|
||||
}).restore(lodash_1.cloneDeep(data));
|
||||
}),
|
||||
];
|
||||
cachesList.forEach(function (caches, i) {
|
||||
it(message + (" (" + (i + 1) + "/" + cachesList.length + ")"), function () {
|
||||
return callback.apply(void 0, caches);
|
||||
});
|
||||
});
|
||||
}
|
||||
function itWithCacheConfig(message, config, callback) {
|
||||
var caches = [
|
||||
new __1.InMemoryCache(tslib_1.__assign(tslib_1.__assign({ addTypename: false }, config), { resultCaching: true })),
|
||||
new __1.InMemoryCache(tslib_1.__assign(tslib_1.__assign({ addTypename: false }, config), { resultCaching: false })),
|
||||
new __1.InMemoryCache(tslib_1.__assign(tslib_1.__assign({ addTypename: false }, config), { freezeResults: true })),
|
||||
];
|
||||
caches.forEach(function (cache, i) {
|
||||
it(message + (" (" + (i + 1) + "/" + caches.length + ")"), function () { return callback(cache); });
|
||||
});
|
||||
}
|
||||
describe('readQuery', function () {
|
||||
itWithInitialData('will read some data from the store', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n {\n a\n }\n "], ["\n {\n a\n }\n "]))),
|
||||
}))).toEqual({ a: 1 });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n {\n b\n c\n }\n "], ["\n {\n b\n c\n }\n "]))),
|
||||
}))).toEqual({ b: 2, c: 3 });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n }\n "], ["\n {\n a\n b\n c\n }\n "]))),
|
||||
}))).toEqual({ a: 1, b: 2, c: 3 });
|
||||
});
|
||||
itWithInitialData('will read some deeply nested data from the store', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: {
|
||||
type: 'id',
|
||||
id: 'foo',
|
||||
generated: false,
|
||||
},
|
||||
},
|
||||
foo: {
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
h: {
|
||||
type: 'id',
|
||||
id: 'bar',
|
||||
generated: false,
|
||||
},
|
||||
},
|
||||
bar: {
|
||||
i: 7,
|
||||
j: 8,
|
||||
k: 9,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n {\n a\n d {\n e\n }\n }\n "], ["\n {\n a\n d {\n e\n }\n }\n "]))),
|
||||
}))).toEqual({ a: 1, d: { e: 4 } });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n {\n a\n d {\n e\n h {\n i\n }\n }\n }\n "], ["\n {\n a\n d {\n e\n h {\n i\n }\n }\n }\n "]))),
|
||||
}))).toEqual({ a: 1, d: { e: 4, h: { i: 7 } } });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n d {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n }\n "], ["\n {\n a\n b\n c\n d {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n }\n "]))),
|
||||
}))).toEqual({
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: { e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } },
|
||||
});
|
||||
});
|
||||
itWithInitialData('will read some data from the store with variables', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":42})': 2,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: 42,
|
||||
},
|
||||
}))).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
itWithInitialData('will read some data from the store with null variables', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
'field({"literal":false,"value":null})': 1,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery({
|
||||
query: graphql_tag_1.default(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n query($literal: Boolean, $value: Int) {\n a: field(literal: $literal, value: $value)\n }\n "], ["\n query($literal: Boolean, $value: Int) {\n a: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: null,
|
||||
},
|
||||
}))).toEqual({ a: 1 });
|
||||
});
|
||||
itWithInitialData('should not mutate arguments passed in', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":42})': 2,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
var options = {
|
||||
query: graphql_tag_1.default(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: 42,
|
||||
},
|
||||
};
|
||||
var preQueryCopy = lodash_1.cloneDeep(options);
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readQuery(options))).toEqual({ a: 1, b: 2 });
|
||||
expect(preQueryCopy).toEqual(options);
|
||||
});
|
||||
});
|
||||
describe('readFragment', function () {
|
||||
itWithInitialData('will throw an error when there is no fragment', [
|
||||
{},
|
||||
], function (proxy) {
|
||||
expect(function () {
|
||||
proxy.readFragment({
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n query {\n a\n b\n c\n }\n "], ["\n query {\n a\n b\n c\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.');
|
||||
expect(function () {
|
||||
proxy.readFragment({
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_11 || (templateObject_11 = tslib_1.__makeTemplateObject(["\n schema {\n query: Query\n }\n "], ["\n schema {\n query: Query\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
});
|
||||
itWithInitialData('will throw an error when there is more than one fragment but no fragment name', [{}], function (proxy) {
|
||||
expect(function () {
|
||||
proxy.readFragment({
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_12 || (templateObject_12 = tslib_1.__makeTemplateObject(["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n "], ["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
expect(function () {
|
||||
proxy.readFragment({
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_13 || (templateObject_13 = tslib_1.__makeTemplateObject(["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n\n fragment c on C {\n c\n }\n "], ["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n\n fragment c on C {\n c\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
});
|
||||
itWithInitialData('will read some deeply nested data from the store at any id', [
|
||||
{
|
||||
ROOT_QUERY: {
|
||||
__typename: 'Type1',
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: {
|
||||
type: 'id',
|
||||
id: 'foo',
|
||||
generated: false,
|
||||
},
|
||||
},
|
||||
foo: {
|
||||
__typename: 'Foo',
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
h: {
|
||||
type: 'id',
|
||||
id: 'bar',
|
||||
generated: false,
|
||||
},
|
||||
},
|
||||
bar: {
|
||||
__typename: 'Bar',
|
||||
i: 7,
|
||||
j: 8,
|
||||
k: 9,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_14 || (templateObject_14 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n e\n h {\n i\n }\n }\n "], ["\n fragment fragmentFoo on Foo {\n e\n h {\n i\n }\n }\n "]))),
|
||||
}))).toEqual({ e: 4, h: { i: 7 } });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_15 || (templateObject_15 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n "], ["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n "]))),
|
||||
}))).toEqual({ e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_16 || (templateObject_16 = tslib_1.__makeTemplateObject(["\n fragment fragmentBar on Bar {\n i\n }\n "], ["\n fragment fragmentBar on Bar {\n i\n }\n "]))),
|
||||
}))).toEqual({ i: 7 });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_17 || (templateObject_17 = tslib_1.__makeTemplateObject(["\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "], ["\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "]))),
|
||||
}))).toEqual({ i: 7, j: 8, k: 9 });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_18 || (templateObject_18 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "], ["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "]))),
|
||||
fragmentName: 'fragmentFoo',
|
||||
}))).toEqual({ e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } });
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_19 || (templateObject_19 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "], ["\n fragment fragmentFoo on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment fragmentBar on Bar {\n i\n j\n k\n }\n "]))),
|
||||
fragmentName: 'fragmentBar',
|
||||
}))).toEqual({ i: 7, j: 8, k: 9 });
|
||||
});
|
||||
itWithInitialData('will read some data from the store with variables', [
|
||||
{
|
||||
foo: {
|
||||
__typename: 'Foo',
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":42})': 2,
|
||||
},
|
||||
},
|
||||
], function (proxy) {
|
||||
expect(apollo_utilities_1.stripSymbols(proxy.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_20 || (templateObject_20 = tslib_1.__makeTemplateObject(["\n fragment foo on Foo {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n fragment foo on Foo {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: 42,
|
||||
},
|
||||
}))).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
itWithInitialData('will return null when an id that can’t be found is provided', [
|
||||
{},
|
||||
{
|
||||
bar: { __typename: 'Bar', a: 1, b: 2, c: 3 },
|
||||
},
|
||||
{
|
||||
foo: { __typename: 'Foo', a: 1, b: 2, c: 3 },
|
||||
},
|
||||
], function (client1, client2, client3) {
|
||||
expect(apollo_utilities_1.stripSymbols(client1.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_21 || (templateObject_21 = tslib_1.__makeTemplateObject(["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "], ["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "]))),
|
||||
}))).toEqual(null);
|
||||
expect(apollo_utilities_1.stripSymbols(client2.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_22 || (templateObject_22 = tslib_1.__makeTemplateObject(["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "], ["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "]))),
|
||||
}))).toEqual(null);
|
||||
expect(apollo_utilities_1.stripSymbols(client3.readFragment({
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_23 || (templateObject_23 = tslib_1.__makeTemplateObject(["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "], ["\n fragment fooFragment on Foo {\n a\n b\n c\n }\n "]))),
|
||||
}))).toEqual({ a: 1, b: 2, c: 3 });
|
||||
});
|
||||
});
|
||||
describe('writeQuery', function () {
|
||||
itWithInitialData('will write some data to the store', [{}], function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: { a: 1 },
|
||||
query: graphql_tag_1.default(templateObject_24 || (templateObject_24 = tslib_1.__makeTemplateObject(["\n {\n a\n }\n "], ["\n {\n a\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
},
|
||||
});
|
||||
proxy.writeQuery({
|
||||
data: { b: 2, c: 3 },
|
||||
query: graphql_tag_1.default(templateObject_25 || (templateObject_25 = tslib_1.__makeTemplateObject(["\n {\n b\n c\n }\n "], ["\n {\n b\n c\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
},
|
||||
});
|
||||
proxy.writeQuery({
|
||||
data: { a: 4, b: 5, c: 6 },
|
||||
query: graphql_tag_1.default(templateObject_26 || (templateObject_26 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n }\n "], ["\n {\n a\n b\n c\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 4,
|
||||
b: 5,
|
||||
c: 6,
|
||||
},
|
||||
});
|
||||
});
|
||||
itWithInitialData('will write some deeply nested data to the store', [{}], function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: { a: 1, d: { e: 4 } },
|
||||
query: graphql_tag_1.default(templateObject_27 || (templateObject_27 = tslib_1.__makeTemplateObject(["\n {\n a\n d {\n e\n }\n }\n "], ["\n {\n a\n d {\n e\n }\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
d: {
|
||||
type: 'id',
|
||||
id: '$ROOT_QUERY.d',
|
||||
generated: true,
|
||||
},
|
||||
},
|
||||
'$ROOT_QUERY.d': {
|
||||
e: 4,
|
||||
},
|
||||
});
|
||||
proxy.writeQuery({
|
||||
data: { a: 1, d: { h: { i: 7 } } },
|
||||
query: graphql_tag_1.default(templateObject_28 || (templateObject_28 = tslib_1.__makeTemplateObject(["\n {\n a\n d {\n h {\n i\n }\n }\n }\n "], ["\n {\n a\n d {\n h {\n i\n }\n }\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
d: {
|
||||
type: 'id',
|
||||
id: '$ROOT_QUERY.d',
|
||||
generated: true,
|
||||
},
|
||||
},
|
||||
'$ROOT_QUERY.d': {
|
||||
e: 4,
|
||||
h: {
|
||||
type: 'id',
|
||||
id: '$ROOT_QUERY.d.h',
|
||||
generated: true,
|
||||
},
|
||||
},
|
||||
'$ROOT_QUERY.d.h': {
|
||||
i: 7,
|
||||
},
|
||||
});
|
||||
proxy.writeQuery({
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: { e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } },
|
||||
},
|
||||
query: graphql_tag_1.default(templateObject_29 || (templateObject_29 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n d {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n }\n "], ["\n {\n a\n b\n c\n d {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
d: {
|
||||
type: 'id',
|
||||
id: '$ROOT_QUERY.d',
|
||||
generated: true,
|
||||
},
|
||||
},
|
||||
'$ROOT_QUERY.d': {
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
h: {
|
||||
type: 'id',
|
||||
id: '$ROOT_QUERY.d.h',
|
||||
generated: true,
|
||||
},
|
||||
},
|
||||
'$ROOT_QUERY.d.h': {
|
||||
i: 7,
|
||||
j: 8,
|
||||
k: 9,
|
||||
},
|
||||
});
|
||||
});
|
||||
itWithInitialData('will write some data to the store with variables', [{}], function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
},
|
||||
query: graphql_tag_1.default(templateObject_30 || (templateObject_30 = tslib_1.__makeTemplateObject(["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: 42,
|
||||
},
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":42})': 2,
|
||||
},
|
||||
});
|
||||
});
|
||||
itWithInitialData('will write some data to the store with variables where some are null', [{}], function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
},
|
||||
query: graphql_tag_1.default(templateObject_31 || (templateObject_31 = tslib_1.__makeTemplateObject(["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n query($literal: Boolean, $value: Int) {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: null,
|
||||
},
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
ROOT_QUERY: {
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":null})': 2,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('writeFragment', function () {
|
||||
itWithInitialData('will throw an error when there is no fragment', [{}], function (proxy) {
|
||||
expect(function () {
|
||||
proxy.writeFragment({
|
||||
data: {},
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_32 || (templateObject_32 = tslib_1.__makeTemplateObject(["\n query {\n a\n b\n c\n }\n "], ["\n query {\n a\n b\n c\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.');
|
||||
expect(function () {
|
||||
proxy.writeFragment({
|
||||
data: {},
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_33 || (templateObject_33 = tslib_1.__makeTemplateObject(["\n schema {\n query: Query\n }\n "], ["\n schema {\n query: Query\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
});
|
||||
itWithInitialData('will throw an error when there is more than one fragment but no fragment name', [{}], function (proxy) {
|
||||
expect(function () {
|
||||
proxy.writeFragment({
|
||||
data: {},
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_34 || (templateObject_34 = tslib_1.__makeTemplateObject(["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n "], ["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
expect(function () {
|
||||
proxy.writeFragment({
|
||||
data: {},
|
||||
id: 'x',
|
||||
fragment: graphql_tag_1.default(templateObject_35 || (templateObject_35 = tslib_1.__makeTemplateObject(["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n\n fragment c on C {\n c\n }\n "], ["\n fragment a on A {\n a\n }\n\n fragment b on B {\n b\n }\n\n fragment c on C {\n c\n }\n "]))),
|
||||
});
|
||||
}).toThrowError('Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.');
|
||||
});
|
||||
itWithCacheConfig('will write some deeply nested data into the store at any id', {
|
||||
dataIdFromObject: function (o) { return o.id; },
|
||||
addTypename: false,
|
||||
}, function (proxy) {
|
||||
proxy.writeFragment({
|
||||
data: { __typename: 'Foo', e: 4, h: { id: 'bar', i: 7 } },
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_36 || (templateObject_36 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n e\n h {\n i\n }\n }\n "], ["\n fragment fragmentFoo on Foo {\n e\n h {\n i\n }\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
proxy.writeFragment({
|
||||
data: { __typename: 'Foo', f: 5, g: 6, h: { id: 'bar', j: 8, k: 9 } },
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_37 || (templateObject_37 = tslib_1.__makeTemplateObject(["\n fragment fragmentFoo on Foo {\n f\n g\n h {\n j\n k\n }\n }\n "], ["\n fragment fragmentFoo on Foo {\n f\n g\n h {\n j\n k\n }\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
proxy.writeFragment({
|
||||
data: { i: 10, __typename: 'Bar' },
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_38 || (templateObject_38 = tslib_1.__makeTemplateObject(["\n fragment fragmentBar on Bar {\n i\n }\n "], ["\n fragment fragmentBar on Bar {\n i\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
proxy.writeFragment({
|
||||
data: { j: 11, k: 12, __typename: 'Bar' },
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_39 || (templateObject_39 = tslib_1.__makeTemplateObject(["\n fragment fragmentBar on Bar {\n j\n k\n }\n "], ["\n fragment fragmentBar on Bar {\n j\n k\n }\n "]))),
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
proxy.writeFragment({
|
||||
data: {
|
||||
__typename: 'Foo',
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
h: { __typename: 'Bar', id: 'bar', i: 7, j: 8, k: 9 },
|
||||
},
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_40 || (templateObject_40 = tslib_1.__makeTemplateObject(["\n fragment fooFragment on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment barFragment on Bar {\n i\n j\n k\n }\n "], ["\n fragment fooFragment on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment barFragment on Bar {\n i\n j\n k\n }\n "]))),
|
||||
fragmentName: 'fooFragment',
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
proxy.writeFragment({
|
||||
data: { __typename: 'Bar', i: 10, j: 11, k: 12 },
|
||||
id: 'bar',
|
||||
fragment: graphql_tag_1.default(templateObject_41 || (templateObject_41 = tslib_1.__makeTemplateObject(["\n fragment fooFragment on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment barFragment on Bar {\n i\n j\n k\n }\n "], ["\n fragment fooFragment on Foo {\n e\n f\n g\n h {\n i\n j\n k\n }\n }\n\n fragment barFragment on Bar {\n i\n j\n k\n }\n "]))),
|
||||
fragmentName: 'barFragment',
|
||||
});
|
||||
expect(proxy.extract()).toMatchSnapshot();
|
||||
});
|
||||
itWithCacheConfig('writes data that can be read back', {
|
||||
addTypename: true,
|
||||
}, function (proxy) {
|
||||
var readWriteFragment = graphql_tag_1.default(templateObject_42 || (templateObject_42 = tslib_1.__makeTemplateObject(["\n fragment aFragment on query {\n getSomething {\n id\n }\n }\n "], ["\n fragment aFragment on query {\n getSomething {\n id\n }\n }\n "])));
|
||||
var data = {
|
||||
__typename: 'query',
|
||||
getSomething: { id: '123', __typename: 'Something' },
|
||||
};
|
||||
proxy.writeFragment({
|
||||
data: data,
|
||||
id: 'query',
|
||||
fragment: readWriteFragment,
|
||||
});
|
||||
var result = proxy.readFragment({
|
||||
fragment: readWriteFragment,
|
||||
id: 'query',
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(result)).toEqual(data);
|
||||
});
|
||||
itWithCacheConfig('will write some data to the store with variables', {
|
||||
addTypename: true,
|
||||
}, function (proxy) {
|
||||
proxy.writeFragment({
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
__typename: 'Foo',
|
||||
},
|
||||
id: 'foo',
|
||||
fragment: graphql_tag_1.default(templateObject_43 || (templateObject_43 = tslib_1.__makeTemplateObject(["\n fragment foo on Foo {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "], ["\n fragment foo on Foo {\n a: field(literal: true, value: 42)\n b: field(literal: $literal, value: $value)\n }\n "]))),
|
||||
variables: {
|
||||
literal: false,
|
||||
value: 42,
|
||||
},
|
||||
});
|
||||
expect(proxy.extract()).toEqual({
|
||||
foo: {
|
||||
__typename: 'Foo',
|
||||
'field({"literal":true,"value":42})': 1,
|
||||
'field({"literal":false,"value":42})': 2,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('performTransaction', function () {
|
||||
itWithInitialData('will not broadcast mid-transaction', [{}], function (cache) {
|
||||
var numBroadcasts = 0;
|
||||
var query = graphql_tag_1.default(templateObject_44 || (templateObject_44 = tslib_1.__makeTemplateObject(["\n {\n a\n }\n "], ["\n {\n a\n }\n "])));
|
||||
cache.watch({
|
||||
query: query,
|
||||
optimistic: false,
|
||||
callback: function () {
|
||||
numBroadcasts++;
|
||||
},
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
cache.performTransaction(function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: { a: 1 },
|
||||
query: query,
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
proxy.writeQuery({
|
||||
data: { a: 4, b: 5, c: 6 },
|
||||
query: graphql_tag_1.default(templateObject_45 || (templateObject_45 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n }\n "], ["\n {\n a\n b\n c\n }\n "]))),
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
});
|
||||
expect(numBroadcasts).toEqual(1);
|
||||
});
|
||||
});
|
||||
describe('performOptimisticTransaction', function () {
|
||||
itWithInitialData('will only broadcast once', [{}], function (cache) {
|
||||
var numBroadcasts = 0;
|
||||
var query = graphql_tag_1.default(templateObject_46 || (templateObject_46 = tslib_1.__makeTemplateObject(["\n {\n a\n }\n "], ["\n {\n a\n }\n "])));
|
||||
cache.watch({
|
||||
query: query,
|
||||
optimistic: true,
|
||||
callback: function () {
|
||||
numBroadcasts++;
|
||||
},
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
cache.recordOptimisticTransaction(function (proxy) {
|
||||
proxy.writeQuery({
|
||||
data: { a: 1 },
|
||||
query: query,
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
proxy.writeQuery({
|
||||
data: { a: 4, b: 5, c: 6 },
|
||||
query: graphql_tag_1.default(templateObject_47 || (templateObject_47 = tslib_1.__makeTemplateObject(["\n {\n a\n b\n c\n }\n "], ["\n {\n a\n b\n c\n }\n "]))),
|
||||
});
|
||||
expect(numBroadcasts).toEqual(0);
|
||||
}, 1);
|
||||
expect(numBroadcasts).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27, templateObject_28, templateObject_29, templateObject_30, templateObject_31, templateObject_32, templateObject_33, templateObject_34, templateObject_35, templateObject_36, templateObject_37, templateObject_38, templateObject_39, templateObject_40, templateObject_41, templateObject_42, templateObject_43, templateObject_44, templateObject_45, templateObject_46, templateObject_47;
|
||||
//# sourceMappingURL=cache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/cache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/cache.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function withError(func: Function, regex: RegExp): any;
|
||||
//# sourceMappingURL=diffAgainstStore.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"diffAgainstStore.d.ts","sourceRoot":"","sources":["../src/__tests__/diffAgainstStore.ts"],"names":[],"mappings":"AAaA,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OActD"}
|
||||
678
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.js
generated
vendored
Normal file
678
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.js
generated
vendored
Normal file
@@ -0,0 +1,678 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var graphql_tag_1 = tslib_1.__importStar(require("graphql-tag"));
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var objectCache_1 = require("../objectCache");
|
||||
var readFromStore_1 = require("../readFromStore");
|
||||
var writeToStore_1 = require("../writeToStore");
|
||||
var fragmentMatcher_1 = require("../fragmentMatcher");
|
||||
var inMemoryCache_1 = require("../inMemoryCache");
|
||||
var fragmentMatcherFunction = new fragmentMatcher_1.HeuristicFragmentMatcher().match;
|
||||
graphql_tag_1.disableFragmentWarnings();
|
||||
function withError(func, regex) {
|
||||
var message = null;
|
||||
var error = console.error;
|
||||
console.error = function (m) {
|
||||
message = m;
|
||||
};
|
||||
try {
|
||||
var result = func();
|
||||
expect(message).toMatch(regex);
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
console.error = error;
|
||||
}
|
||||
}
|
||||
exports.withError = withError;
|
||||
describe('diffing queries against the store', function () {
|
||||
var reader = new readFromStore_1.StoreReader();
|
||||
var writer = new writeToStore_1.StoreWriter();
|
||||
it('expects named fragments to return complete as true when diffd against ' +
|
||||
'the store', function () {
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({});
|
||||
var queryResult = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n query foo {\n ...root\n }\n\n fragment root on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n "], ["\n query foo {\n ...root\n }\n\n fragment root on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n "]))),
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
config: {
|
||||
dataIdFromObject: inMemoryCache_1.defaultDataIdFromObject,
|
||||
},
|
||||
});
|
||||
expect(queryResult.complete).toEqual(false);
|
||||
});
|
||||
it('expects inline fragments to return complete as true when diffd against ' +
|
||||
'the store', function () {
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory();
|
||||
var queryResult = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n {\n ... on DummyQuery {\n nestedObj {\n innerArray {\n id\n otherField\n }\n }\n }\n ... on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n ... on DummyQuery2 {\n nestedObj {\n innerArray {\n id\n otherField2\n }\n }\n }\n }\n "], ["\n {\n ... on DummyQuery {\n nestedObj {\n innerArray {\n id\n otherField\n }\n }\n }\n ... on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n ... on DummyQuery2 {\n nestedObj {\n innerArray {\n id\n otherField2\n }\n }\n }\n }\n "]))),
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
config: {
|
||||
dataIdFromObject: inMemoryCache_1.defaultDataIdFromObject,
|
||||
},
|
||||
});
|
||||
expect(queryResult.complete).toEqual(false);
|
||||
});
|
||||
it('returns nothing when the store is enough', function () {
|
||||
var query = graphql_tag_1.default(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n name\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n name\n }\n }\n "])));
|
||||
var result = {
|
||||
people_one: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: result,
|
||||
query: query,
|
||||
});
|
||||
expect(reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
}).complete).toBeTruthy();
|
||||
});
|
||||
it('caches root queries both under the ID of the node and the query name', function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "])));
|
||||
var result = {
|
||||
people_one: {
|
||||
__typename: 'Person',
|
||||
id: '1',
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
};
|
||||
var getIdField = function (_a) {
|
||||
var id = _a.id;
|
||||
return id;
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: result,
|
||||
query: firstQuery,
|
||||
dataIdFromObject: getIdField,
|
||||
});
|
||||
var secondQuery = graphql_tag_1.default(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "])));
|
||||
var complete = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: secondQuery,
|
||||
}).complete;
|
||||
expect(complete).toBeTruthy();
|
||||
expect(store.get('1')).toEqual(result.people_one);
|
||||
});
|
||||
it('does not swallow errors other than field errors', function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n query {\n person {\n powers\n }\n }\n "], ["\n query {\n person {\n powers\n }\n }\n "])));
|
||||
var firstResult = {
|
||||
person: {
|
||||
powers: 'the force',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: firstResult,
|
||||
query: firstQuery,
|
||||
});
|
||||
var unionQuery = graphql_tag_1.default(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n query {\n ...notARealFragment\n }\n "], ["\n query {\n ...notARealFragment\n }\n "])));
|
||||
return expect(function () {
|
||||
reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: unionQuery,
|
||||
});
|
||||
}).toThrowError(/No fragment/);
|
||||
});
|
||||
it('does not error on a correct query with union typed fragments', function () {
|
||||
return withError(function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "], ["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "])));
|
||||
var firstResult = {
|
||||
person: {
|
||||
__typename: 'Author',
|
||||
firstName: 'John',
|
||||
lastName: 'Smith',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: firstResult,
|
||||
query: firstQuery,
|
||||
});
|
||||
var unionQuery = graphql_tag_1.default(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n ... on Author {\n firstName\n lastName\n }\n ... on Jedi {\n powers\n }\n }\n }\n "], ["\n query {\n person {\n __typename\n ... on Author {\n firstName\n lastName\n }\n ... on Jedi {\n powers\n }\n }\n }\n "])));
|
||||
var complete = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: unionQuery,
|
||||
returnPartialData: false,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
}).complete;
|
||||
expect(complete).toBe(false);
|
||||
}, /IntrospectionFragmentMatcher/);
|
||||
});
|
||||
it('does not error on a query with fields missing from all but one named fragment', function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "], ["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "])));
|
||||
var firstResult = {
|
||||
person: {
|
||||
__typename: 'Author',
|
||||
firstName: 'John',
|
||||
lastName: 'Smith',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: firstResult,
|
||||
query: firstQuery,
|
||||
});
|
||||
var unionQuery = graphql_tag_1.default(templateObject_11 || (templateObject_11 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n ...authorInfo\n ...jediInfo\n }\n }\n\n fragment authorInfo on Author {\n firstName\n }\n\n fragment jediInfo on Jedi {\n powers\n }\n "], ["\n query {\n person {\n __typename\n ...authorInfo\n ...jediInfo\n }\n }\n\n fragment authorInfo on Author {\n firstName\n }\n\n fragment jediInfo on Jedi {\n powers\n }\n "])));
|
||||
var complete = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: unionQuery,
|
||||
}).complete;
|
||||
expect(complete).toBe(false);
|
||||
});
|
||||
it('throws an error on a query with fields missing from matching named fragments', function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_12 || (templateObject_12 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "], ["\n query {\n person {\n __typename\n firstName\n lastName\n }\n }\n "])));
|
||||
var firstResult = {
|
||||
person: {
|
||||
__typename: 'Author',
|
||||
firstName: 'John',
|
||||
lastName: 'Smith',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: firstResult,
|
||||
query: firstQuery,
|
||||
});
|
||||
var unionQuery = graphql_tag_1.default(templateObject_13 || (templateObject_13 = tslib_1.__makeTemplateObject(["\n query {\n person {\n __typename\n ...authorInfo2\n ...jediInfo2\n }\n }\n\n fragment authorInfo2 on Author {\n firstName\n address\n }\n\n fragment jediInfo2 on Jedi {\n jedi\n }\n "], ["\n query {\n person {\n __typename\n ...authorInfo2\n ...jediInfo2\n }\n }\n\n fragment authorInfo2 on Author {\n firstName\n address\n }\n\n fragment jediInfo2 on Jedi {\n jedi\n }\n "])));
|
||||
expect(function () {
|
||||
reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: unionQuery,
|
||||
returnPartialData: false,
|
||||
});
|
||||
}).toThrow();
|
||||
});
|
||||
it('returns available fields if returnPartialData is true', function () {
|
||||
var firstQuery = graphql_tag_1.default(templateObject_14 || (templateObject_14 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n __typename\n id\n name\n }\n }\n "])));
|
||||
var firstResult = {
|
||||
people_one: {
|
||||
__typename: 'Person',
|
||||
id: 'lukeId',
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
result: firstResult,
|
||||
query: firstQuery,
|
||||
});
|
||||
var simpleQuery = graphql_tag_1.default(templateObject_15 || (templateObject_15 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n name\n age\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n name\n age\n }\n }\n "])));
|
||||
var inlineFragmentQuery = graphql_tag_1.default(templateObject_16 || (templateObject_16 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n ... on Person {\n name\n age\n }\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n ... on Person {\n name\n age\n }\n }\n }\n "])));
|
||||
var namedFragmentQuery = graphql_tag_1.default(templateObject_17 || (templateObject_17 = tslib_1.__makeTemplateObject(["\n query {\n people_one(id: \"1\") {\n ...personInfo\n }\n }\n\n fragment personInfo on Person {\n name\n age\n }\n "], ["\n query {\n people_one(id: \"1\") {\n ...personInfo\n }\n }\n\n fragment personInfo on Person {\n name\n age\n }\n "])));
|
||||
var simpleDiff = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: simpleQuery,
|
||||
});
|
||||
expect(simpleDiff.result).toEqual({
|
||||
people_one: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
});
|
||||
var inlineDiff = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: inlineFragmentQuery,
|
||||
});
|
||||
expect(inlineDiff.result).toEqual({
|
||||
people_one: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
});
|
||||
var namedDiff = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: namedFragmentQuery,
|
||||
});
|
||||
expect(namedDiff.result).toEqual({
|
||||
people_one: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
});
|
||||
expect(function () {
|
||||
reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: simpleQuery,
|
||||
returnPartialData: false,
|
||||
});
|
||||
}).toThrow();
|
||||
});
|
||||
it('will add a private id property', function () {
|
||||
var query = graphql_tag_1.default(templateObject_18 || (templateObject_18 = tslib_1.__makeTemplateObject(["\n query {\n a {\n id\n b\n }\n c {\n d\n e {\n id\n f\n }\n g {\n h\n }\n }\n }\n "], ["\n query {\n a {\n id\n b\n }\n c {\n d\n e {\n id\n f\n }\n g {\n h\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [{ id: 'a:1', b: 1.1 }, { id: 'a:2', b: 1.2 }, { id: 'a:3', b: 1.3 }],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [
|
||||
{ id: 'e:1', f: 3.1 },
|
||||
{ id: 'e:2', f: 3.2 },
|
||||
{ id: 'e:3', f: 3.3 },
|
||||
{ id: 'e:4', f: 3.4 },
|
||||
{ id: 'e:5', f: 3.5 },
|
||||
],
|
||||
g: { h: 4 },
|
||||
},
|
||||
};
|
||||
function dataIdFromObject(_a) {
|
||||
var id = _a.id;
|
||||
return id;
|
||||
}
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
});
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(dataIdFromObject(result.a[0])).toBe('a:1');
|
||||
expect(dataIdFromObject(result.a[1])).toBe('a:2');
|
||||
expect(dataIdFromObject(result.a[2])).toBe('a:3');
|
||||
expect(dataIdFromObject(result.c.e[0])).toBe('e:1');
|
||||
expect(dataIdFromObject(result.c.e[1])).toBe('e:2');
|
||||
expect(dataIdFromObject(result.c.e[2])).toBe('e:3');
|
||||
expect(dataIdFromObject(result.c.e[3])).toBe('e:4');
|
||||
expect(dataIdFromObject(result.c.e[4])).toBe('e:5');
|
||||
});
|
||||
describe('referential equality preservation', function () {
|
||||
it('will return the previous result if there are no changes', function () {
|
||||
var query = graphql_tag_1.default(templateObject_19 || (templateObject_19 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "], ["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: { b: 1 },
|
||||
c: { d: 2, e: { f: 3 } },
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: { b: 1 },
|
||||
c: { d: 2, e: { f: 3 } },
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).toEqual(previousResult);
|
||||
});
|
||||
it('will return parts of the previous result that changed', function () {
|
||||
var query = graphql_tag_1.default(templateObject_20 || (templateObject_20 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "], ["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: { b: 1 },
|
||||
c: { d: 2, e: { f: 3 } },
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: { b: 1 },
|
||||
c: { d: 20, e: { f: 3 } },
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).not.toEqual(previousResult);
|
||||
expect(result.a).toEqual(previousResult.a);
|
||||
expect(result.c).not.toEqual(previousResult.c);
|
||||
expect(result.c.e).toEqual(previousResult.c.e);
|
||||
});
|
||||
it('will return the previous result if there are no changes in child arrays', function () {
|
||||
var query = graphql_tag_1.default(templateObject_21 || (templateObject_21 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "], ["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }],
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }],
|
||||
},
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).toEqual(previousResult);
|
||||
});
|
||||
it('will not add zombie items when previousResult starts with the same items', function () {
|
||||
var query = graphql_tag_1.default(templateObject_22 || (templateObject_22 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n }\n "], ["\n query {\n a {\n b\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [{ b: 1.1 }, { b: 1.2 }],
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }],
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result.a[0]).toEqual(previousResult.a[0]);
|
||||
expect(result.a[1]).toEqual(previousResult.a[1]);
|
||||
});
|
||||
it('will return the previous result if there are no changes in nested child arrays', function () {
|
||||
var query = graphql_tag_1.default(templateObject_23 || (templateObject_23 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "], ["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [[[[[{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }]]]]],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]],
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: [[[[[{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }]]]]],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [[{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }], [{ f: 3.4 }, { f: 3.5 }]],
|
||||
},
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).toEqual(previousResult);
|
||||
});
|
||||
it('will return parts of the previous result if there are changes in child arrays', function () {
|
||||
var query = graphql_tag_1.default(templateObject_24 || (templateObject_24 = tslib_1.__makeTemplateObject(["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "], ["\n query {\n a {\n b\n }\n c {\n d\n e {\n f\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }],
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: [{ b: 1.1 }, { b: -1.2 }, { b: 1.3 }],
|
||||
c: {
|
||||
d: 20,
|
||||
e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }],
|
||||
},
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).not.toEqual(previousResult);
|
||||
expect(result.a).not.toEqual(previousResult.a);
|
||||
expect(result.a[0]).toEqual(previousResult.a[0]);
|
||||
expect(result.a[1]).not.toEqual(previousResult.a[1]);
|
||||
expect(result.a[2]).toEqual(previousResult.a[2]);
|
||||
expect(result.c).not.toEqual(previousResult.c);
|
||||
expect(result.c.e).toEqual(previousResult.c.e);
|
||||
expect(result.c.e[0]).toEqual(previousResult.c.e[0]);
|
||||
expect(result.c.e[1]).toEqual(previousResult.c.e[1]);
|
||||
expect(result.c.e[2]).toEqual(previousResult.c.e[2]);
|
||||
expect(result.c.e[3]).toEqual(previousResult.c.e[3]);
|
||||
expect(result.c.e[4]).toEqual(previousResult.c.e[4]);
|
||||
});
|
||||
it('will return the same items in a different order with `dataIdFromObject`', function () {
|
||||
var query = graphql_tag_1.default(templateObject_25 || (templateObject_25 = tslib_1.__makeTemplateObject(["\n query {\n a {\n id\n b\n }\n c {\n d\n e {\n id\n f\n }\n g {\n h\n }\n }\n }\n "], ["\n query {\n a {\n id\n b\n }\n c {\n d\n e {\n id\n f\n }\n g {\n h\n }\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: [
|
||||
{ id: 'a:1', b: 1.1 },
|
||||
{ id: 'a:2', b: 1.2 },
|
||||
{ id: 'a:3', b: 1.3 },
|
||||
],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [
|
||||
{ id: 'e:1', f: 3.1 },
|
||||
{ id: 'e:2', f: 3.2 },
|
||||
{ id: 'e:3', f: 3.3 },
|
||||
{ id: 'e:4', f: 3.4 },
|
||||
{ id: 'e:5', f: 3.5 },
|
||||
],
|
||||
g: { h: 4 },
|
||||
},
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
dataIdFromObject: function (_a) {
|
||||
var id = _a.id;
|
||||
return id;
|
||||
},
|
||||
});
|
||||
var previousResult = {
|
||||
a: [
|
||||
{ id: 'a:3', b: 1.3 },
|
||||
{ id: 'a:2', b: 1.2 },
|
||||
{ id: 'a:1', b: 1.1 },
|
||||
],
|
||||
c: {
|
||||
d: 2,
|
||||
e: [
|
||||
{ id: 'e:4', f: 3.4 },
|
||||
{ id: 'e:2', f: 3.2 },
|
||||
{ id: 'e:5', f: 3.5 },
|
||||
{ id: 'e:3', f: 3.3 },
|
||||
{ id: 'e:1', f: 3.1 },
|
||||
],
|
||||
g: { h: 4 },
|
||||
},
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).not.toEqual(previousResult);
|
||||
expect(result.a).not.toEqual(previousResult.a);
|
||||
expect(result.a[0]).toEqual(previousResult.a[2]);
|
||||
expect(result.a[1]).toEqual(previousResult.a[1]);
|
||||
expect(result.a[2]).toEqual(previousResult.a[0]);
|
||||
expect(result.c).not.toEqual(previousResult.c);
|
||||
expect(result.c.e).not.toEqual(previousResult.c.e);
|
||||
expect(result.c.e[0]).toEqual(previousResult.c.e[4]);
|
||||
expect(result.c.e[1]).toEqual(previousResult.c.e[1]);
|
||||
expect(result.c.e[2]).toEqual(previousResult.c.e[3]);
|
||||
expect(result.c.e[3]).toEqual(previousResult.c.e[0]);
|
||||
expect(result.c.e[4]).toEqual(previousResult.c.e[2]);
|
||||
expect(result.c.g).toEqual(previousResult.c.g);
|
||||
});
|
||||
it('will return the same JSON scalar field object', function () {
|
||||
var query = graphql_tag_1.default(templateObject_26 || (templateObject_26 = tslib_1.__makeTemplateObject(["\n {\n a {\n b\n c\n }\n d {\n e\n f\n }\n }\n "], ["\n {\n a {\n b\n c\n }\n d {\n e\n f\n }\n }\n "])));
|
||||
var queryResult = {
|
||||
a: { b: 1, c: { x: 2, y: 3, z: 4 } },
|
||||
d: { e: 5, f: { x: 6, y: 7, z: 8 } },
|
||||
};
|
||||
var store = writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: queryResult,
|
||||
});
|
||||
var previousResult = {
|
||||
a: { b: 1, c: { x: 2, y: 3, z: 4 } },
|
||||
d: { e: 50, f: { x: 6, y: 7, z: 8 } },
|
||||
};
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: query,
|
||||
previousResult: previousResult,
|
||||
}).result;
|
||||
expect(result).toEqual(queryResult);
|
||||
expect(result).not.toEqual(previousResult);
|
||||
expect(result.a).toEqual(previousResult.a);
|
||||
expect(result.d).not.toEqual(previousResult.d);
|
||||
expect(result.d.f).toEqual(previousResult.d.f);
|
||||
});
|
||||
it('will preserve equality with custom resolvers', function () {
|
||||
var listQuery = graphql_tag_1.default(templateObject_27 || (templateObject_27 = tslib_1.__makeTemplateObject(["\n {\n people {\n id\n name\n __typename\n }\n }\n "], ["\n {\n people {\n id\n name\n __typename\n }\n }\n "])));
|
||||
var listResult = {
|
||||
people: [
|
||||
{
|
||||
id: '4',
|
||||
name: 'Luke Skywalker',
|
||||
__typename: 'Person',
|
||||
},
|
||||
],
|
||||
};
|
||||
var itemQuery = graphql_tag_1.default(templateObject_28 || (templateObject_28 = tslib_1.__makeTemplateObject(["\n {\n person(id: 4) {\n id\n name\n __typename\n }\n }\n "], ["\n {\n person(id: 4) {\n id\n name\n __typename\n }\n }\n "])));
|
||||
var dataIdFromObject = function (obj) { return obj.id; };
|
||||
var store = writer.writeQueryToStore({
|
||||
query: listQuery,
|
||||
result: listResult,
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
});
|
||||
var previousResult = {
|
||||
person: listResult.people[0],
|
||||
};
|
||||
var cacheRedirects = {
|
||||
Query: {
|
||||
person: function (_, args) {
|
||||
return apollo_utilities_1.toIdValue({ id: args['id'], typename: 'Person' });
|
||||
},
|
||||
},
|
||||
};
|
||||
var config = { dataIdFromObject: dataIdFromObject, cacheRedirects: cacheRedirects };
|
||||
var result = reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: itemQuery,
|
||||
previousResult: previousResult,
|
||||
config: config,
|
||||
}).result;
|
||||
expect(result).toEqual(previousResult);
|
||||
});
|
||||
});
|
||||
describe('malformed queries', function () {
|
||||
it('throws for non-scalar query fields without selection sets', function () {
|
||||
var validQuery = graphql_tag_1.default(templateObject_29 || (templateObject_29 = tslib_1.__makeTemplateObject(["\n query getMessageList {\n messageList {\n id\n __typename\n message\n }\n }\n "], ["\n query getMessageList {\n messageList {\n id\n __typename\n message\n }\n }\n "])));
|
||||
var invalidQuery = graphql_tag_1.default(templateObject_30 || (templateObject_30 = tslib_1.__makeTemplateObject(["\n query getMessageList {\n # This field needs a selection set because its value is an array\n # of non-scalar objects.\n messageList\n }\n "], ["\n query getMessageList {\n # This field needs a selection set because its value is an array\n # of non-scalar objects.\n messageList\n }\n "])));
|
||||
var store = writer.writeQueryToStore({
|
||||
query: validQuery,
|
||||
result: {
|
||||
messageList: [
|
||||
{
|
||||
id: 1,
|
||||
__typename: 'Message',
|
||||
message: 'hi',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
__typename: 'Message',
|
||||
message: 'hello',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
__typename: 'Message',
|
||||
message: 'hey',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
try {
|
||||
reader.diffQueryAgainstStore({
|
||||
store: store,
|
||||
query: invalidQuery,
|
||||
});
|
||||
throw new Error('should have thrown');
|
||||
}
|
||||
catch (e) {
|
||||
expect(e.message).toEqual('Missing selection set for object of type Message returned for query field messageList');
|
||||
}
|
||||
});
|
||||
});
|
||||
describe('issue #4081', function () {
|
||||
it('should not return results containing cycles', function () {
|
||||
var company = {
|
||||
__typename: 'Company',
|
||||
id: 1,
|
||||
name: 'Apollo',
|
||||
users: [],
|
||||
};
|
||||
company.users.push({
|
||||
__typename: 'User',
|
||||
id: 1,
|
||||
name: 'Ben',
|
||||
company: company,
|
||||
}, {
|
||||
__typename: 'User',
|
||||
id: 2,
|
||||
name: 'James',
|
||||
company: company,
|
||||
});
|
||||
var query = graphql_tag_1.default(templateObject_31 || (templateObject_31 = tslib_1.__makeTemplateObject(["\n query Query {\n user {\n ...UserFragment\n company {\n users {\n ...UserFragment\n }\n }\n }\n }\n\n fragment UserFragment on User {\n id\n name\n company {\n id\n name\n }\n }\n "], ["\n query Query {\n user {\n ...UserFragment\n company {\n users {\n ...UserFragment\n }\n }\n }\n }\n\n fragment UserFragment on User {\n id\n name\n company {\n id\n name\n }\n }\n "])));
|
||||
function check(store) {
|
||||
var result = reader.diffQueryAgainstStore({ store: store, query: query }).result;
|
||||
var json = JSON.stringify(result);
|
||||
company.users.forEach(function (user) {
|
||||
expect(json).toContain(JSON.stringify(user.name));
|
||||
});
|
||||
expect(result).toEqual({
|
||||
user: {
|
||||
id: 1,
|
||||
name: 'Ben',
|
||||
company: {
|
||||
id: 1,
|
||||
name: 'Apollo',
|
||||
users: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Ben',
|
||||
company: {
|
||||
id: 1,
|
||||
name: 'Apollo',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'James',
|
||||
company: {
|
||||
id: 1,
|
||||
name: 'Apollo',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
check(writer.writeQueryToStore({
|
||||
query: query,
|
||||
result: {
|
||||
user: company.users[0],
|
||||
},
|
||||
}));
|
||||
check(writer.writeQueryToStore({
|
||||
dataIdFromObject: inMemoryCache_1.defaultDataIdFromObject,
|
||||
query: query,
|
||||
result: {
|
||||
user: company.users[0],
|
||||
},
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27, templateObject_28, templateObject_29, templateObject_30, templateObject_31;
|
||||
//# sourceMappingURL=diffAgainstStore.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/diffAgainstStore.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=fragmentMatcher.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcher.d.ts","sourceRoot":"","sources":["../src/__tests__/fragmentMatcher.ts"],"names":[],"mappings":""}
|
||||
79
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.js
generated
vendored
Normal file
79
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var fragmentMatcher_1 = require("../fragmentMatcher");
|
||||
var objectCache_1 = require("../objectCache");
|
||||
var inMemoryCache_1 = require("../inMemoryCache");
|
||||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
||||
describe('FragmentMatcher', function () {
|
||||
it('can match against the root Query', function () {
|
||||
var cache = new inMemoryCache_1.InMemoryCache({
|
||||
addTypename: true,
|
||||
});
|
||||
var query = graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n query AllPeople {\n people {\n id\n name\n }\n ...PeopleTypes\n }\n fragment PeopleTypes on Query {\n __type(name: \"Person\") {\n name\n kind\n }\n }\n "], ["\n query AllPeople {\n people {\n id\n name\n }\n ...PeopleTypes\n }\n fragment PeopleTypes on Query {\n __type(name: \"Person\") {\n name\n kind\n }\n }\n "])));
|
||||
var data = {
|
||||
people: [
|
||||
{
|
||||
__typename: 'Person',
|
||||
id: 123,
|
||||
name: 'Ben',
|
||||
},
|
||||
],
|
||||
__type: {
|
||||
__typename: '__Type',
|
||||
name: 'Person',
|
||||
kind: 'OBJECT',
|
||||
},
|
||||
};
|
||||
cache.writeQuery({ query: query, data: data });
|
||||
expect(cache.readQuery({ query: query })).toEqual(data);
|
||||
});
|
||||
});
|
||||
describe('IntrospectionFragmentMatcher', function () {
|
||||
it('will throw an error if match is called if it is not ready', function () {
|
||||
var ifm = new fragmentMatcher_1.IntrospectionFragmentMatcher();
|
||||
expect(function () { return ifm.match(); }).toThrowError(/called before/);
|
||||
});
|
||||
it('can be seeded with an introspection query result', function () {
|
||||
var ifm = new fragmentMatcher_1.IntrospectionFragmentMatcher({
|
||||
introspectionQueryResultData: {
|
||||
__schema: {
|
||||
types: [
|
||||
{
|
||||
kind: 'UNION',
|
||||
name: 'Item',
|
||||
possibleTypes: [
|
||||
{
|
||||
name: 'ItemA',
|
||||
},
|
||||
{
|
||||
name: 'ItemB',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
a: {
|
||||
__typename: 'ItemB',
|
||||
},
|
||||
});
|
||||
var idValue = {
|
||||
type: 'id',
|
||||
id: 'a',
|
||||
generated: false,
|
||||
};
|
||||
var readStoreContext = {
|
||||
store: store,
|
||||
returnPartialData: false,
|
||||
hasMissingField: false,
|
||||
cacheRedirects: {},
|
||||
};
|
||||
expect(ifm.match(idValue, 'Item', readStoreContext)).toBe(true);
|
||||
expect(ifm.match(idValue, 'NotAnItem', readStoreContext)).toBe(false);
|
||||
});
|
||||
});
|
||||
var templateObject_1;
|
||||
//# sourceMappingURL=fragmentMatcher.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/fragmentMatcher.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcher.js","sourceRoot":"","sources":["../../src/__tests__/fragmentMatcher.ts"],"names":[],"mappings":";;;AAAA,sDAAkE;AAClE,8CAA+D;AAE/D,kDAAiD;AACjD,oEAA8B;AAE9B,QAAQ,CAAC,iBAAiB,EAAE;IAC1B,EAAE,CAAC,kCAAkC,EAAE;QACrC,IAAM,KAAK,GAAG,IAAI,6BAAa,CAAC;YAC9B,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,IAAM,KAAK,GAAG,qBAAG,uUAAA,4PAchB,IAAA,CAAC;QAEF,IAAM,IAAI,GAAG;YACX,MAAM,EAAE;gBACN;oBACE,UAAU,EAAE,QAAQ;oBACpB,EAAE,EAAE,GAAG;oBACP,IAAI,EAAE,KAAK;iBACZ;aACF;YACD,MAAM,EAAE;gBACN,UAAU,EAAE,QAAQ;gBACpB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf;SACF,CAAC;QAEF,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,8BAA8B,EAAE;IACvC,EAAE,CAAC,2DAA2D,EAAE;QAC9D,IAAM,GAAG,GAAG,IAAI,8CAA4B,EAAE,CAAC;QAC/C,MAAM,CAAC,cAAM,OAAC,GAAG,CAAC,KAAa,EAAE,EAApB,CAAoB,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACrD,IAAM,GAAG,GAAG,IAAI,8CAA4B,CAAC;YAC3C,4BAA4B,EAAE;gBAC5B,QAAQ,EAAE;oBACR,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,MAAM;4BACZ,aAAa,EAAE;gCACb;oCACE,IAAI,EAAE,OAAO;iCACd;gCACD;oCACE,IAAI,EAAE,OAAO;iCACd;6BACF;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QAEH,IAAM,KAAK,GAAG,2CAA6B,CAAC;YAC1C,CAAC,EAAE;gBACD,UAAU,EAAE,OAAO;aACpB;SACF,CAAC,CAAC;QAEH,IAAM,OAAO,GAAG;YACd,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,GAAG;YACP,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,IAAM,gBAAgB,GAAG;YACvB,KAAK,OAAA;YACL,iBAAiB,EAAE,KAAK;YACxB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,EAAE;SACC,CAAC;QAEtB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAc,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAc,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,IAAI,CACnE,KAAK,CACN,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.d.ts
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
//# sourceMappingURL=mapCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mapCache.d.ts","sourceRoot":"","sources":["../src/__tests__/mapCache.ts"],"names":[],"mappings":""}
|
||||
18
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.js
generated
vendored
Normal file
18
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
jest.mock('../objectCache', function () {
|
||||
var _a = require('../mapCache'), MapCache = _a.MapCache, mapNormalizedCacheFactory = _a.mapNormalizedCacheFactory;
|
||||
return {
|
||||
ObjectCache: MapCache,
|
||||
defaultNormalizedCacheFactory: mapNormalizedCacheFactory,
|
||||
};
|
||||
});
|
||||
describe('MapCache', function () {
|
||||
require('./objectCache');
|
||||
require('./cache');
|
||||
require('./diffAgainstStore');
|
||||
require('./fragmentMatcher');
|
||||
require('./readFromStore');
|
||||
require('./diffAgainstStore');
|
||||
require('./roundtrip');
|
||||
require('./writeToStore');
|
||||
});
|
||||
//# sourceMappingURL=mapCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/mapCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mapCache.js","sourceRoot":"","sources":["../../src/__tests__/mapCache.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACpB,IAAA,2BAAgE,EAA9D,sBAAQ,EAAE,wDAAoD,CAAC;IACvE,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,6BAA6B,EAAE,yBAAyB;KACzD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,UAAU,EAAE;IAGnB,OAAO,CAAC,eAAe,CAAC,CAAC;IACzB,OAAO,CAAC,SAAS,CAAC,CAAC;IACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC9B,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC3B,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAC;IACvB,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
||||
2
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=objectCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"objectCache.d.ts","sourceRoot":"","sources":["../src/__tests__/objectCache.ts"],"names":[],"mappings":""}
|
||||
33
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.js
generated
vendored
Normal file
33
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var objectCache_1 = require("../objectCache");
|
||||
describe('ObjectCache', function () {
|
||||
it('should create an empty cache', function () {
|
||||
var cache = new objectCache_1.ObjectCache();
|
||||
expect(cache.toObject()).toEqual({});
|
||||
});
|
||||
it('should create a cache based on an Object', function () {
|
||||
var contents = { a: {} };
|
||||
var cache = new objectCache_1.ObjectCache(contents);
|
||||
expect(cache.toObject()).toEqual(contents);
|
||||
});
|
||||
it("should .get() an object from the store by dataId", function () {
|
||||
var contents = { a: {} };
|
||||
var cache = new objectCache_1.ObjectCache(contents);
|
||||
expect(cache.get('a')).toBe(contents.a);
|
||||
});
|
||||
it("should .set() an object from the store by dataId", function () {
|
||||
var obj = {};
|
||||
var cache = new objectCache_1.ObjectCache();
|
||||
cache.set('a', obj);
|
||||
expect(cache.get('a')).toBe(obj);
|
||||
});
|
||||
it("should .clear() the store", function () {
|
||||
var obj = {};
|
||||
var cache = new objectCache_1.ObjectCache();
|
||||
cache.set('a', obj);
|
||||
cache.clear();
|
||||
expect(cache.get('a')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=objectCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/objectCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"objectCache.js","sourceRoot":"","sources":["../../src/__tests__/objectCache.ts"],"names":[],"mappings":";;AAAA,8CAA6C;AAG7C,QAAQ,CAAC,aAAa,EAAE;IACtB,EAAE,CAAC,8BAA8B,EAAE;QACjC,IAAM,KAAK,GAAG,IAAI,yBAAW,EAAE,CAAC;QAChC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE;QAC7C,IAAM,QAAQ,GAA0B,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAClD,IAAM,KAAK,GAAG,IAAI,yBAAW,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACrD,IAAM,QAAQ,GAA0B,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAClD,IAAM,KAAK,GAAG,IAAI,yBAAW,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACrD,IAAM,GAAG,GAAG,EAAE,CAAC;QACf,IAAM,KAAK,GAAG,IAAI,yBAAW,EAAE,CAAC;QAChC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACpB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE;QAC9B,IAAM,GAAG,GAAG,EAAE,CAAC;QACf,IAAM,KAAK,GAAG,IAAI,yBAAW,EAAE,CAAC;QAChC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACpB,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
2
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=readFromStore.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"readFromStore.d.ts","sourceRoot":"","sources":["../src/__tests__/readFromStore.ts"],"names":[],"mappings":""}
|
||||
555
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.js
generated
vendored
Normal file
555
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.js
generated
vendored
Normal file
@@ -0,0 +1,555 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var lodash_1 = require("lodash");
|
||||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var __1 = require("../");
|
||||
var readFromStore_1 = require("../readFromStore");
|
||||
var objectCache_1 = require("../objectCache");
|
||||
var fragmentMatcherFunction = new __1.HeuristicFragmentMatcher().match;
|
||||
var diffAgainstStore_1 = require("./diffAgainstStore");
|
||||
describe('reading from the store', function () {
|
||||
var reader = new readFromStore_1.StoreReader();
|
||||
it('runs a nested query with proper fragment fields in arrays', function () {
|
||||
diffAgainstStore_1.withError(function () {
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: {
|
||||
__typename: 'Query',
|
||||
nestedObj: { type: 'id', id: 'abcde', generated: false },
|
||||
},
|
||||
abcde: {
|
||||
id: 'abcde',
|
||||
innerArray: [
|
||||
{ type: 'id', generated: true, id: 'abcde.innerArray.0' },
|
||||
],
|
||||
},
|
||||
'abcde.innerArray.0': {
|
||||
id: 'abcdef',
|
||||
someField: 3,
|
||||
},
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n {\n ... on DummyQuery {\n nestedObj {\n innerArray {\n id\n otherField\n }\n }\n }\n ... on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n ... on DummyQuery2 {\n nestedObj {\n innerArray {\n id\n otherField2\n }\n }\n }\n }\n "], ["\n {\n ... on DummyQuery {\n nestedObj {\n innerArray {\n id\n otherField\n }\n }\n }\n ... on Query {\n nestedObj {\n innerArray {\n id\n someField\n }\n }\n }\n ... on DummyQuery2 {\n nestedObj {\n innerArray {\n id\n otherField2\n }\n }\n }\n }\n "]))),
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
nestedObj: {
|
||||
innerArray: [{ id: 'abcdef', someField: 3 }],
|
||||
},
|
||||
});
|
||||
}, /queries contain union or interface types/);
|
||||
});
|
||||
it('rejects malformed queries', function () {
|
||||
expect(function () {
|
||||
reader.readQueryFromStore({
|
||||
store: objectCache_1.defaultNormalizedCacheFactory(),
|
||||
query: graphql_tag_1.default(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n query {\n name\n }\n\n query {\n address\n }\n "], ["\n query {\n name\n }\n\n query {\n address\n }\n "]))),
|
||||
});
|
||||
}).toThrowError(/2 operations/);
|
||||
expect(function () {
|
||||
reader.readQueryFromStore({
|
||||
store: objectCache_1.defaultNormalizedCacheFactory(),
|
||||
query: graphql_tag_1.default(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n fragment x on y {\n name\n }\n "], ["\n fragment x on y {\n name\n }\n "]))),
|
||||
});
|
||||
}).toThrowError(/contain a query/);
|
||||
});
|
||||
it('runs a basic query', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: result,
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n query {\n stringField\n numberField\n }\n "], ["\n query {\n stringField\n numberField\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: result['stringField'],
|
||||
numberField: result['numberField'],
|
||||
});
|
||||
});
|
||||
it('runs a basic query with arguments', function () {
|
||||
var query = graphql_tag_1.default(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n query {\n id\n stringField(arg: $stringArg)\n numberField(intArg: $intArg, floatArg: $floatArg)\n nullField\n }\n "], ["\n query {\n id\n stringField(arg: $stringArg)\n numberField(intArg: $intArg, floatArg: $floatArg)\n nullField\n }\n "])));
|
||||
var variables = {
|
||||
intArg: 5,
|
||||
floatArg: 3.14,
|
||||
stringArg: 'This is a string!',
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: {
|
||||
id: 'abcd',
|
||||
nullField: null,
|
||||
'numberField({"floatArg":3.14,"intArg":5})': 5,
|
||||
'stringField({"arg":"This is a string!"})': 'Heyo',
|
||||
},
|
||||
});
|
||||
var result = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: query,
|
||||
variables: variables,
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(result)).toEqual({
|
||||
id: 'abcd',
|
||||
nullField: null,
|
||||
numberField: 5,
|
||||
stringField: 'Heyo',
|
||||
});
|
||||
});
|
||||
it('runs a basic query with custom directives', function () {
|
||||
var query = graphql_tag_1.default(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n query {\n id\n firstName @include(if: true)\n lastName @upperCase\n birthDate @dateFormat(format: \"DD-MM-YYYY\")\n }\n "], ["\n query {\n id\n firstName @include(if: true)\n lastName @upperCase\n birthDate @dateFormat(format: \"DD-MM-YYYY\")\n }\n "])));
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: {
|
||||
id: 'abcd',
|
||||
firstName: 'James',
|
||||
'lastName@upperCase': 'BOND',
|
||||
'birthDate@dateFormat({"format":"DD-MM-YYYY"})': '20-05-1940',
|
||||
},
|
||||
});
|
||||
var result = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: query,
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(result)).toEqual({
|
||||
id: 'abcd',
|
||||
firstName: 'James',
|
||||
lastName: 'BOND',
|
||||
birthDate: '20-05-1940',
|
||||
});
|
||||
});
|
||||
it('runs a basic query with default values for arguments', function () {
|
||||
var query = graphql_tag_1.default(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n query someBigQuery(\n $stringArg: String = \"This is a default string!\"\n $intArg: Int = 0\n $floatArg: Float\n ) {\n id\n stringField(arg: $stringArg)\n numberField(intArg: $intArg, floatArg: $floatArg)\n nullField\n }\n "], ["\n query someBigQuery(\n $stringArg: String = \"This is a default string!\"\n $intArg: Int = 0\n $floatArg: Float\n ) {\n id\n stringField(arg: $stringArg)\n numberField(intArg: $intArg, floatArg: $floatArg)\n nullField\n }\n "])));
|
||||
var variables = {
|
||||
floatArg: 3.14,
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: {
|
||||
id: 'abcd',
|
||||
nullField: null,
|
||||
'numberField({"floatArg":3.14,"intArg":0})': 5,
|
||||
'stringField({"arg":"This is a default string!"})': 'Heyo',
|
||||
},
|
||||
});
|
||||
var result = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: query,
|
||||
variables: variables,
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(result)).toEqual({
|
||||
id: 'abcd',
|
||||
nullField: null,
|
||||
numberField: 5,
|
||||
stringField: 'Heyo',
|
||||
});
|
||||
});
|
||||
it('runs a nested query', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedObj: {
|
||||
id: 'abcde',
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
},
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedObj')), {
|
||||
nestedObj: {
|
||||
type: 'id',
|
||||
id: 'abcde',
|
||||
generated: false,
|
||||
},
|
||||
}),
|
||||
abcde: result.nestedObj,
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nestedObj {\n stringField\n numberField\n }\n }\n "], ["\n {\n stringField\n numberField\n nestedObj {\n stringField\n numberField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nestedObj: {
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
},
|
||||
});
|
||||
});
|
||||
it('runs a nested query with multiple fragments', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedObj: {
|
||||
id: 'abcde',
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
},
|
||||
deepNestedObj: {
|
||||
stringField: 'This is a deep string',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
nullObject: null,
|
||||
__typename: 'Item',
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedObj', 'deepNestedObj')), {
|
||||
__typename: 'Query',
|
||||
nestedObj: {
|
||||
type: 'id',
|
||||
id: 'abcde',
|
||||
generated: false,
|
||||
},
|
||||
}),
|
||||
abcde: lodash_1.assign({}, result.nestedObj, {
|
||||
deepNestedObj: {
|
||||
type: 'id',
|
||||
id: 'abcdef',
|
||||
generated: false,
|
||||
},
|
||||
}),
|
||||
abcdef: result.deepNestedObj,
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nullField\n ... on Query {\n nestedObj {\n stringField\n nullField\n deepNestedObj {\n stringField\n nullField\n }\n }\n }\n ... on Query {\n nestedObj {\n numberField\n nullField\n deepNestedObj {\n numberField\n nullField\n }\n }\n }\n ... on Query {\n nullObject\n }\n }\n "], ["\n {\n stringField\n numberField\n nullField\n ... on Query {\n nestedObj {\n stringField\n nullField\n deepNestedObj {\n stringField\n nullField\n }\n }\n }\n ... on Query {\n nestedObj {\n numberField\n nullField\n deepNestedObj {\n numberField\n nullField\n }\n }\n }\n ... on Query {\n nullObject\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedObj: {
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
deepNestedObj: {
|
||||
stringField: 'This is a deep string',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
},
|
||||
nullObject: null,
|
||||
});
|
||||
});
|
||||
it('runs a nested query with an array without IDs', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedArray: [
|
||||
{
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
},
|
||||
{
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedArray')), {
|
||||
nestedArray: [
|
||||
{ type: 'id', generated: true, id: 'abcd.nestedArray.0' },
|
||||
{ type: 'id', generated: true, id: 'abcd.nestedArray.1' },
|
||||
],
|
||||
}),
|
||||
'abcd.nestedArray.0': result.nestedArray[0],
|
||||
'abcd.nestedArray.1': result.nestedArray[1],
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nestedArray {\n stringField\n numberField\n }\n }\n "], ["\n {\n stringField\n numberField\n nestedArray {\n stringField\n numberField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nestedArray: [
|
||||
{
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
},
|
||||
{
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
it('runs a nested query with an array without IDs and a null', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedArray: [
|
||||
null,
|
||||
{
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedArray')), {
|
||||
nestedArray: [
|
||||
null,
|
||||
{ type: 'id', generated: true, id: 'abcd.nestedArray.1' },
|
||||
],
|
||||
}),
|
||||
'abcd.nestedArray.1': result.nestedArray[1],
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_11 || (templateObject_11 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nestedArray {\n stringField\n numberField\n }\n }\n "], ["\n {\n stringField\n numberField\n nestedArray {\n stringField\n numberField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nestedArray: [
|
||||
null,
|
||||
{
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
it('runs a nested query with an array with IDs and a null', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedArray: [
|
||||
null,
|
||||
{
|
||||
id: 'abcde',
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedArray')), {
|
||||
nestedArray: [null, { type: 'id', generated: false, id: 'abcde' }],
|
||||
}),
|
||||
abcde: result.nestedArray[1],
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_12 || (templateObject_12 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nestedArray {\n id\n stringField\n numberField\n }\n }\n "], ["\n {\n stringField\n numberField\n nestedArray {\n id\n stringField\n numberField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nestedArray: [
|
||||
null,
|
||||
{
|
||||
id: 'abcde',
|
||||
stringField: 'This is a string also!',
|
||||
numberField: 7,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
it('throws on a missing field', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({ ROOT_QUERY: result });
|
||||
expect(function () {
|
||||
reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_13 || (templateObject_13 = tslib_1.__makeTemplateObject(["\n {\n stringField\n missingField\n }\n "], ["\n {\n stringField\n missingField\n }\n "]))),
|
||||
});
|
||||
}).toThrowError(/field missingField on object/);
|
||||
});
|
||||
it('runs a nested query where the reference is null', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedObj: null,
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'nestedObj')), {
|
||||
nestedObj: null,
|
||||
}),
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_14 || (templateObject_14 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nestedObj {\n stringField\n numberField\n }\n }\n "], ["\n {\n stringField\n numberField\n nestedObj {\n stringField\n numberField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nestedObj: null,
|
||||
});
|
||||
});
|
||||
it('runs an array of non-objects', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
simpleArray: ['one', 'two', 'three'],
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'simpleArray')), {
|
||||
simpleArray: {
|
||||
type: 'json',
|
||||
json: result.simpleArray,
|
||||
},
|
||||
}),
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_15 || (templateObject_15 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n simpleArray\n }\n "], ["\n {\n stringField\n numberField\n simpleArray\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
simpleArray: ['one', 'two', 'three'],
|
||||
});
|
||||
});
|
||||
it('runs an array of non-objects with null', function () {
|
||||
var result = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
simpleArray: [null, 'two', 'three'],
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(result, 'simpleArray')), {
|
||||
simpleArray: {
|
||||
type: 'json',
|
||||
json: result.simpleArray,
|
||||
},
|
||||
}),
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_16 || (templateObject_16 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n simpleArray\n }\n "], ["\n {\n stringField\n numberField\n simpleArray\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
simpleArray: [null, 'two', 'three'],
|
||||
});
|
||||
});
|
||||
it('will read from an arbitrary root id', function () {
|
||||
var data = {
|
||||
id: 'abcd',
|
||||
stringField: 'This is a string!',
|
||||
numberField: 5,
|
||||
nullField: null,
|
||||
nestedObj: {
|
||||
id: 'abcde',
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
},
|
||||
deepNestedObj: {
|
||||
stringField: 'This is a deep string',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
nullObject: null,
|
||||
__typename: 'Item',
|
||||
};
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: lodash_1.assign({}, lodash_1.assign({}, lodash_1.omit(data, 'nestedObj', 'deepNestedObj')), {
|
||||
__typename: 'Query',
|
||||
nestedObj: {
|
||||
type: 'id',
|
||||
id: 'abcde',
|
||||
generated: false,
|
||||
},
|
||||
}),
|
||||
abcde: lodash_1.assign({}, data.nestedObj, {
|
||||
deepNestedObj: {
|
||||
type: 'id',
|
||||
id: 'abcdef',
|
||||
generated: false,
|
||||
},
|
||||
}),
|
||||
abcdef: data.deepNestedObj,
|
||||
});
|
||||
var queryResult1 = reader.readQueryFromStore({
|
||||
store: store,
|
||||
rootId: 'abcde',
|
||||
query: graphql_tag_1.default(templateObject_17 || (templateObject_17 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nullField\n deepNestedObj {\n stringField\n numberField\n nullField\n }\n }\n "], ["\n {\n stringField\n numberField\n nullField\n deepNestedObj {\n stringField\n numberField\n nullField\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult1)).toEqual({
|
||||
stringField: 'This is a string too!',
|
||||
numberField: 6,
|
||||
nullField: null,
|
||||
deepNestedObj: {
|
||||
stringField: 'This is a deep string',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
},
|
||||
});
|
||||
var queryResult2 = reader.readQueryFromStore({
|
||||
store: store,
|
||||
rootId: 'abcdef',
|
||||
query: graphql_tag_1.default(templateObject_18 || (templateObject_18 = tslib_1.__makeTemplateObject(["\n {\n stringField\n numberField\n nullField\n }\n "], ["\n {\n stringField\n numberField\n nullField\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult2)).toEqual({
|
||||
stringField: 'This is a deep string',
|
||||
numberField: 7,
|
||||
nullField: null,
|
||||
});
|
||||
});
|
||||
it('properly handles the connection directive', function () {
|
||||
var store = objectCache_1.defaultNormalizedCacheFactory({
|
||||
ROOT_QUERY: {
|
||||
abc: [
|
||||
{
|
||||
generated: true,
|
||||
id: 'ROOT_QUERY.abc.0',
|
||||
type: 'id',
|
||||
},
|
||||
],
|
||||
},
|
||||
'ROOT_QUERY.abc.0': {
|
||||
name: 'efgh',
|
||||
},
|
||||
});
|
||||
var queryResult = reader.readQueryFromStore({
|
||||
store: store,
|
||||
query: graphql_tag_1.default(templateObject_19 || (templateObject_19 = tslib_1.__makeTemplateObject(["\n {\n books(skip: 0, limit: 2) @connection(key: \"abc\") {\n name\n }\n }\n "], ["\n {\n books(skip: 0, limit: 2) @connection(key: \"abc\") {\n name\n }\n }\n "]))),
|
||||
});
|
||||
expect(apollo_utilities_1.stripSymbols(queryResult)).toEqual({
|
||||
books: [
|
||||
{
|
||||
name: 'efgh',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19;
|
||||
//# sourceMappingURL=readFromStore.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/readFromStore.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=recordingCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"recordingCache.d.ts","sourceRoot":"","sources":["../src/__tests__/recordingCache.ts"],"names":[],"mappings":""}
|
||||
70
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.js
generated
vendored
Normal file
70
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var inMemoryCache_1 = require("../inMemoryCache");
|
||||
var objectCache_1 = require("../objectCache");
|
||||
describe('OptimisticCacheLayer', function () {
|
||||
function makeLayer(root) {
|
||||
return new inMemoryCache_1.OptimisticCacheLayer('whatever', root, function () { });
|
||||
}
|
||||
describe('returns correct values during recording', function () {
|
||||
var data = {
|
||||
Human: { __typename: 'Human', name: 'Mark' },
|
||||
Animal: { __typename: 'Mouse', name: '🐭' },
|
||||
};
|
||||
var dataToRecord = {
|
||||
Human: { __typename: 'Human', name: 'John' },
|
||||
};
|
||||
var underlyingCache = new objectCache_1.ObjectCache(data);
|
||||
var cache = makeLayer(underlyingCache);
|
||||
beforeEach(function () {
|
||||
cache = makeLayer(underlyingCache);
|
||||
});
|
||||
it('should passthrough values if not defined in recording', function () {
|
||||
expect(cache.get('Human')).toBe(data.Human);
|
||||
expect(cache.get('Animal')).toBe(data.Animal);
|
||||
});
|
||||
it('should return values defined during recording', function () {
|
||||
cache.set('Human', dataToRecord.Human);
|
||||
expect(cache.get('Human')).toBe(dataToRecord.Human);
|
||||
expect(underlyingCache.get('Human')).toBe(data.Human);
|
||||
});
|
||||
it('should return undefined for values deleted during recording', function () {
|
||||
expect(cache.get('Animal')).toBe(data.Animal);
|
||||
cache.delete('Animal');
|
||||
expect(cache.get('Animal')).toBeUndefined();
|
||||
expect(cache.toObject()).toHaveProperty('Animal');
|
||||
expect(underlyingCache.get('Animal')).toBe(data.Animal);
|
||||
});
|
||||
});
|
||||
describe('returns correct result of a recorded transaction', function () {
|
||||
var data = {
|
||||
Human: { __typename: 'Human', name: 'Mark' },
|
||||
Animal: { __typename: 'Mouse', name: '🐭' },
|
||||
};
|
||||
var dataToRecord = {
|
||||
Human: { __typename: 'Human', name: 'John' },
|
||||
};
|
||||
var underlyingCache = new objectCache_1.ObjectCache(data);
|
||||
var cache = makeLayer(underlyingCache);
|
||||
var recording;
|
||||
beforeEach(function () {
|
||||
cache = makeLayer(underlyingCache);
|
||||
cache.set('Human', dataToRecord.Human);
|
||||
cache.delete('Animal');
|
||||
recording = cache.toObject();
|
||||
});
|
||||
it('should contain the property indicating deletion', function () {
|
||||
expect(recording).toHaveProperty('Animal');
|
||||
});
|
||||
it('should have recorded the changes made during recording', function () {
|
||||
expect(recording).toEqual({
|
||||
Human: dataToRecord.Human,
|
||||
Animal: undefined,
|
||||
});
|
||||
});
|
||||
it('should keep the original data unaffected', function () {
|
||||
expect(underlyingCache.toObject()).toEqual(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=recordingCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/recordingCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"recordingCache.js","sourceRoot":"","sources":["../../src/__tests__/recordingCache.ts"],"names":[],"mappings":";;AAAA,kDAAwD;AACxD,8CAA6C;AAG7C,QAAQ,CAAC,sBAAsB,EAAE;IAC/B,SAAS,SAAS,CAAC,IAAiB;QAClC,OAAO,IAAI,oCAAoB,CAAC,UAAU,EAAE,IAAI,EAAE,cAAO,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,QAAQ,CAAC,yCAAyC,EAAE;QAClD,IAAM,IAAI,GAAG;YACX,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;YAC5C,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE;SAC5C,CAAC;QAEF,IAAM,YAAY,GAAG;YACnB,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;SAC7C,CAAC;QAEF,IAAM,eAAe,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAC;QAE9C,IAAI,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;QACvC,UAAU,CAAC;YACT,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uDAAuD,EAAE;YAC1D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+CAA+C,EAAE;YAClD,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACpD,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6DAA6D,EAAE;YAChE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE9C,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACvB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;YAC5C,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAClD,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,kDAAkD,EAAE;QAC3D,IAAM,IAAI,GAAG;YACX,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;YAC5C,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE;SAC5C,CAAC;QAEF,IAAM,YAAY,GAAG;YACnB,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;SAC7C,CAAC;QAEF,IAAM,eAAe,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;QACvC,IAAI,SAAgC,CAAC;QAErC,UAAU,CAAC;YACT,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;YACnC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YACvC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACvB,SAAS,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE;YACpD,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE;YAC3D,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC;gBACxB,KAAK,EAAE,YAAY,CAAC,KAAK;gBACzB,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE;YAC7C,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
2
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=roundtrip.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"roundtrip.d.ts","sourceRoot":"","sources":["../src/__tests__/roundtrip.ts"],"names":[],"mappings":""}
|
||||
275
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.js
generated
vendored
Normal file
275
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.js
generated
vendored
Normal file
@@ -0,0 +1,275 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
||||
var diffAgainstStore_1 = require("./diffAgainstStore");
|
||||
var writeToStore_1 = require("./writeToStore");
|
||||
var depTrackingCache_1 = require("../depTrackingCache");
|
||||
var __1 = require("../");
|
||||
var fragmentMatcherFunction = new __1.HeuristicFragmentMatcher().match;
|
||||
function assertDeeplyFrozen(value, stack) {
|
||||
if (stack === void 0) { stack = []; }
|
||||
if (value !== null && typeof value === 'object' && stack.indexOf(value) < 0) {
|
||||
expect(Object.isExtensible(value)).toBe(false);
|
||||
expect(Object.isFrozen(value)).toBe(true);
|
||||
stack.push(value);
|
||||
Object.keys(value).forEach(function (key) {
|
||||
assertDeeplyFrozen(value[key], stack);
|
||||
});
|
||||
expect(stack.pop()).toBe(value);
|
||||
}
|
||||
}
|
||||
function storeRoundtrip(query, result, variables) {
|
||||
if (variables === void 0) { variables = {}; }
|
||||
var reader = new __1.StoreReader();
|
||||
var immutableReader = new __1.StoreReader({ freezeResults: true });
|
||||
var writer = new __1.StoreWriter();
|
||||
var store = writer.writeQueryToStore({
|
||||
result: result,
|
||||
query: query,
|
||||
variables: variables,
|
||||
});
|
||||
var readOptions = {
|
||||
store: store,
|
||||
query: query,
|
||||
variables: variables,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
};
|
||||
var reconstructedResult = reader.readQueryFromStore(readOptions);
|
||||
expect(reconstructedResult).toEqual(result);
|
||||
expect(store).toBeInstanceOf(depTrackingCache_1.DepTrackingCache);
|
||||
expect(reader.readQueryFromStore(readOptions)).toBe(reconstructedResult);
|
||||
var immutableResult = immutableReader.readQueryFromStore(readOptions);
|
||||
expect(immutableResult).toEqual(reconstructedResult);
|
||||
expect(immutableReader.readQueryFromStore(readOptions)).toBe(immutableResult);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
try {
|
||||
immutableResult.illegal = 'this should not work';
|
||||
throw new Error('unreached');
|
||||
}
|
||||
catch (e) {
|
||||
expect(e.message).not.toMatch(/unreached/);
|
||||
expect(e).toBeInstanceOf(TypeError);
|
||||
}
|
||||
assertDeeplyFrozen(immutableResult);
|
||||
}
|
||||
writer.writeQueryToStore({
|
||||
store: store,
|
||||
result: { oyez: 1234 },
|
||||
query: graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n {\n oyez\n }\n "], ["\n {\n oyez\n }\n "]))),
|
||||
});
|
||||
var deletedRootResult = reader.readQueryFromStore(readOptions);
|
||||
expect(deletedRootResult).toEqual(result);
|
||||
if (deletedRootResult === reconstructedResult) {
|
||||
return;
|
||||
}
|
||||
Object.keys(result).forEach(function (key) {
|
||||
expect(deletedRootResult[key]).toBe(reconstructedResult[key]);
|
||||
});
|
||||
}
|
||||
describe('roundtrip', function () {
|
||||
it('real graphql result', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n {\n people_one(id: \"1\") {\n name\n }\n }\n "], ["\n {\n people_one(id: \"1\") {\n name\n }\n }\n "]))), {
|
||||
people_one: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('multidimensional array (#776)', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n {\n rows {\n value\n }\n }\n "], ["\n {\n rows {\n value\n }\n }\n "]))), {
|
||||
rows: [[{ value: 1 }, { value: 2 }], [{ value: 3 }, { value: 4 }]],
|
||||
});
|
||||
});
|
||||
it('array with null values (#1551)', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n {\n list {\n value\n }\n }\n "], ["\n {\n list {\n value\n }\n }\n "]))), {
|
||||
list: [null, { value: 1 }],
|
||||
});
|
||||
});
|
||||
it('enum arguments', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n {\n hero(episode: JEDI) {\n name\n }\n }\n "], ["\n {\n hero(episode: JEDI) {\n name\n }\n }\n "]))), {
|
||||
hero: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('with an alias', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n {\n luke: people_one(id: \"1\") {\n name\n }\n vader: people_one(id: \"4\") {\n name\n }\n }\n "], ["\n {\n luke: people_one(id: \"1\") {\n name\n }\n vader: people_one(id: \"4\") {\n name\n }\n }\n "]))), {
|
||||
luke: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
vader: {
|
||||
name: 'Darth Vader',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('with variables', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n {\n luke: people_one(id: $lukeId) {\n name\n }\n vader: people_one(id: $vaderId) {\n name\n }\n }\n "], ["\n {\n luke: people_one(id: $lukeId) {\n name\n }\n vader: people_one(id: $vaderId) {\n name\n }\n }\n "]))), {
|
||||
luke: {
|
||||
name: 'Luke Skywalker',
|
||||
},
|
||||
vader: {
|
||||
name: 'Darth Vader',
|
||||
},
|
||||
}, {
|
||||
lukeId: '1',
|
||||
vaderId: '4',
|
||||
});
|
||||
});
|
||||
it('with GraphQLJSON scalar type', function () {
|
||||
var updateClub = {
|
||||
uid: '1d7f836018fc11e68d809dfee940f657',
|
||||
name: 'Eple',
|
||||
settings: {
|
||||
name: 'eple',
|
||||
currency: 'AFN',
|
||||
calendarStretch: 2,
|
||||
defaultPreAllocationPeriod: 1,
|
||||
confirmationEmailCopy: null,
|
||||
emailDomains: null,
|
||||
},
|
||||
};
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n {\n updateClub {\n uid\n name\n settings\n }\n }\n "], ["\n {\n updateClub {\n uid\n name\n settings\n }\n }\n "]))), {
|
||||
updateClub: updateClub,
|
||||
});
|
||||
expect(Object.isExtensible(updateClub)).toBe(true);
|
||||
expect(Object.isFrozen(updateClub)).toBe(false);
|
||||
});
|
||||
describe('directives', function () {
|
||||
it('should be able to query with skip directive true', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n query {\n fortuneCookie @skip(if: true)\n }\n "], ["\n query {\n fortuneCookie @skip(if: true)\n }\n "]))), {});
|
||||
});
|
||||
it('should be able to query with skip directive false', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n query {\n fortuneCookie @skip(if: false)\n }\n "], ["\n query {\n fortuneCookie @skip(if: false)\n }\n "]))), { fortuneCookie: 'live long and prosper' });
|
||||
});
|
||||
});
|
||||
describe('fragments', function () {
|
||||
it('should work on null fields', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_11 || (templateObject_11 = tslib_1.__makeTemplateObject(["\n query {\n field {\n ... on Obj {\n stuff\n }\n }\n }\n "], ["\n query {\n field {\n ... on Obj {\n stuff\n }\n }\n }\n "]))), {
|
||||
field: null,
|
||||
});
|
||||
});
|
||||
it('should work on basic inline fragments', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_12 || (templateObject_12 = tslib_1.__makeTemplateObject(["\n query {\n field {\n __typename\n ... on Obj {\n stuff\n }\n }\n }\n "], ["\n query {\n field {\n __typename\n ... on Obj {\n stuff\n }\n }\n }\n "]))), {
|
||||
field: {
|
||||
__typename: 'Obj',
|
||||
stuff: 'Result',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('should resolve on union types with inline fragments without typenames with warning', function () {
|
||||
return writeToStore_1.withWarning(function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_13 || (templateObject_13 = tslib_1.__makeTemplateObject(["\n query {\n all_people {\n name\n ... on Jedi {\n side\n }\n ... on Droid {\n model\n }\n }\n }\n "], ["\n query {\n all_people {\n name\n ... on Jedi {\n side\n }\n ... on Droid {\n model\n }\n }\n }\n "]))), {
|
||||
all_people: [
|
||||
{
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
{
|
||||
name: 'R2D2',
|
||||
model: 'astromech',
|
||||
},
|
||||
],
|
||||
});
|
||||
}, /using fragments/);
|
||||
});
|
||||
it('should throw an error on two of the same inline fragment types', function () {
|
||||
return expect(function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_14 || (templateObject_14 = tslib_1.__makeTemplateObject(["\n query {\n all_people {\n __typename\n name\n ... on Jedi {\n side\n }\n ... on Jedi {\n rank\n }\n }\n }\n "], ["\n query {\n all_people {\n __typename\n name\n ... on Jedi {\n side\n }\n ... on Jedi {\n rank\n }\n }\n }\n "]))), {
|
||||
all_people: [
|
||||
{
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
],
|
||||
});
|
||||
}).toThrowError(/Can\'t find field rank on object/);
|
||||
});
|
||||
it('should resolve fields it can on interface with non matching inline fragments', function () {
|
||||
return diffAgainstStore_1.withError(function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_15 || (templateObject_15 = tslib_1.__makeTemplateObject(["\n query {\n dark_forces {\n __typename\n name\n ... on Droid {\n model\n }\n }\n }\n "], ["\n query {\n dark_forces {\n __typename\n name\n ... on Droid {\n model\n }\n }\n }\n "]))), {
|
||||
dark_forces: [
|
||||
{
|
||||
__typename: 'Droid',
|
||||
name: '8t88',
|
||||
model: '88',
|
||||
},
|
||||
{
|
||||
__typename: 'Darth',
|
||||
name: 'Anakin Skywalker',
|
||||
},
|
||||
],
|
||||
});
|
||||
}, /IntrospectionFragmentMatcher/);
|
||||
});
|
||||
it('should resolve on union types with spread fragments', function () {
|
||||
return diffAgainstStore_1.withError(function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_16 || (templateObject_16 = tslib_1.__makeTemplateObject(["\n fragment jediFragment on Jedi {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n all_people {\n __typename\n name\n ...jediFragment\n ...droidFragment\n }\n }\n "], ["\n fragment jediFragment on Jedi {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n all_people {\n __typename\n name\n ...jediFragment\n ...droidFragment\n }\n }\n "]))), {
|
||||
all_people: [
|
||||
{
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
{
|
||||
__typename: 'Droid',
|
||||
name: 'R2D2',
|
||||
model: 'astromech',
|
||||
},
|
||||
],
|
||||
});
|
||||
}, /IntrospectionFragmentMatcher/);
|
||||
});
|
||||
it('should work with a fragment on the actual interface or union', function () {
|
||||
return diffAgainstStore_1.withError(function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_17 || (templateObject_17 = tslib_1.__makeTemplateObject(["\n fragment jediFragment on Character {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n all_people {\n name\n __typename\n ...jediFragment\n ...droidFragment\n }\n }\n "], ["\n fragment jediFragment on Character {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n all_people {\n name\n __typename\n ...jediFragment\n ...droidFragment\n }\n }\n "]))), {
|
||||
all_people: [
|
||||
{
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
{
|
||||
__typename: 'Droid',
|
||||
name: 'R2D2',
|
||||
model: 'astromech',
|
||||
},
|
||||
],
|
||||
});
|
||||
}, /IntrospectionFragmentMatcher/);
|
||||
});
|
||||
it('should throw on error on two of the same spread fragment types', function () {
|
||||
expect(function () {
|
||||
return storeRoundtrip(graphql_tag_1.default(templateObject_18 || (templateObject_18 = tslib_1.__makeTemplateObject(["\n fragment jediSide on Jedi {\n side\n }\n\n fragment jediRank on Jedi {\n rank\n }\n\n query {\n all_people {\n __typename\n name\n ...jediSide\n ...jediRank\n }\n }\n "], ["\n fragment jediSide on Jedi {\n side\n }\n\n fragment jediRank on Jedi {\n rank\n }\n\n query {\n all_people {\n __typename\n name\n ...jediSide\n ...jediRank\n }\n }\n "]))), {
|
||||
all_people: [
|
||||
{
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
],
|
||||
});
|
||||
}).toThrowError(/Can\'t find field rank on object/);
|
||||
});
|
||||
it('should resolve on @include and @skip with inline fragments', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_19 || (templateObject_19 = tslib_1.__makeTemplateObject(["\n query {\n person {\n name\n __typename\n ... on Jedi @include(if: true) {\n side\n }\n ... on Droid @skip(if: true) {\n model\n }\n }\n }\n "], ["\n query {\n person {\n name\n __typename\n ... on Jedi @include(if: true) {\n side\n }\n ... on Droid @skip(if: true) {\n model\n }\n }\n }\n "]))), {
|
||||
person: {
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
});
|
||||
});
|
||||
it('should resolve on @include and @skip with spread fragments', function () {
|
||||
storeRoundtrip(graphql_tag_1.default(templateObject_20 || (templateObject_20 = tslib_1.__makeTemplateObject(["\n fragment jediFragment on Jedi {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n person {\n name\n __typename\n ...jediFragment @include(if: true)\n ...droidFragment @skip(if: true)\n }\n }\n "], ["\n fragment jediFragment on Jedi {\n side\n }\n\n fragment droidFragment on Droid {\n model\n }\n\n query {\n person {\n name\n __typename\n ...jediFragment @include(if: true)\n ...droidFragment @skip(if: true)\n }\n }\n "]))), {
|
||||
person: {
|
||||
__typename: 'Jedi',
|
||||
name: 'Luke Skywalker',
|
||||
side: 'bright',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20;
|
||||
//# sourceMappingURL=roundtrip.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/roundtrip.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function withWarning(func: Function, regex: RegExp): Promise<any>;
|
||||
//# sourceMappingURL=writeToStore.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"writeToStore.d.ts","sourceRoot":"","sources":["../src/__tests__/writeToStore.ts"],"names":[],"mappings":"AA2BA,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAWxD"}
|
||||
1523
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.js
generated
vendored
Normal file
1523
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/__tests__/writeToStore.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1280
node_modules/apollo-cache-inmemory/lib/bundle.cjs.js
generated
vendored
Normal file
1280
node_modules/apollo-cache-inmemory/lib/bundle.cjs.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/apollo-cache-inmemory/lib/bundle.cjs.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/bundle.cjs.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/apollo-cache-inmemory/lib/bundle.cjs.min.js
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/bundle.cjs.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
984
node_modules/apollo-cache-inmemory/lib/bundle.esm.js
generated
vendored
Normal file
984
node_modules/apollo-cache-inmemory/lib/bundle.esm.js
generated
vendored
Normal file
@@ -0,0 +1,984 @@
|
||||
import { __assign, __extends } from 'tslib';
|
||||
import { ApolloCache } from 'apollo-cache';
|
||||
import { isTest, getQueryDefinition, assign, getDefaultValues, isEqual, getMainDefinition, getFragmentDefinitions, createFragmentMap, shouldInclude, isField, resultKeyNameFromField, isInlineFragment, mergeDeepArray, argumentsObjectFromField, getDirectiveInfoFromField, maybeDeepFreeze, isIdValue, getStoreKeyName, toIdValue, isJsonValue, canUseWeakMap, getOperationDefinition, isProduction, storeKeyNameFromField, addTypenameToDocument } from 'apollo-utilities';
|
||||
import { wrap, KeyTrie } from 'optimism';
|
||||
import { invariant, InvariantError } from 'ts-invariant';
|
||||
|
||||
var haveWarned = false;
|
||||
function shouldWarn() {
|
||||
var answer = !haveWarned;
|
||||
if (!isTest()) {
|
||||
haveWarned = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
var HeuristicFragmentMatcher = (function () {
|
||||
function HeuristicFragmentMatcher() {
|
||||
}
|
||||
HeuristicFragmentMatcher.prototype.ensureReady = function () {
|
||||
return Promise.resolve();
|
||||
};
|
||||
HeuristicFragmentMatcher.prototype.canBypassInit = function () {
|
||||
return true;
|
||||
};
|
||||
HeuristicFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
||||
var obj = context.store.get(idValue.id);
|
||||
var isRootQuery = idValue.id === 'ROOT_QUERY';
|
||||
if (!obj) {
|
||||
return isRootQuery;
|
||||
}
|
||||
var _a = obj.__typename, __typename = _a === void 0 ? isRootQuery && 'Query' : _a;
|
||||
if (!__typename) {
|
||||
if (shouldWarn()) {
|
||||
process.env.NODE_ENV === "production" || invariant.warn("You're using fragments in your queries, but either don't have the addTypename:\n true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.\n Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client\n can accurately match fragments.");
|
||||
process.env.NODE_ENV === "production" || invariant.warn('Could not find __typename on Fragment ', typeCondition, obj);
|
||||
process.env.NODE_ENV === "production" || invariant.warn("DEPRECATION WARNING: using fragments without __typename is unsupported behavior " +
|
||||
"and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.");
|
||||
}
|
||||
return 'heuristic';
|
||||
}
|
||||
if (__typename === typeCondition) {
|
||||
return true;
|
||||
}
|
||||
if (shouldWarn()) {
|
||||
process.env.NODE_ENV === "production" || invariant.error('You are using the simple (heuristic) fragment matcher, but your ' +
|
||||
'queries contain union or interface types. Apollo Client will not be ' +
|
||||
'able to accurately map fragments. To make this error go away, use ' +
|
||||
'the `IntrospectionFragmentMatcher` as described in the docs: ' +
|
||||
'https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher');
|
||||
}
|
||||
return 'heuristic';
|
||||
};
|
||||
return HeuristicFragmentMatcher;
|
||||
}());
|
||||
var IntrospectionFragmentMatcher = (function () {
|
||||
function IntrospectionFragmentMatcher(options) {
|
||||
if (options && options.introspectionQueryResultData) {
|
||||
this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData);
|
||||
this.isReady = true;
|
||||
}
|
||||
else {
|
||||
this.isReady = false;
|
||||
}
|
||||
this.match = this.match.bind(this);
|
||||
}
|
||||
IntrospectionFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
||||
process.env.NODE_ENV === "production" ? invariant(this.isReady, 1) : invariant(this.isReady, 'FragmentMatcher.match() was called before FragmentMatcher.init()');
|
||||
var obj = context.store.get(idValue.id);
|
||||
var isRootQuery = idValue.id === 'ROOT_QUERY';
|
||||
if (!obj) {
|
||||
return isRootQuery;
|
||||
}
|
||||
var _a = obj.__typename, __typename = _a === void 0 ? isRootQuery && 'Query' : _a;
|
||||
process.env.NODE_ENV === "production" ? invariant(__typename, 2) : invariant(__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));
|
||||
if (__typename === typeCondition) {
|
||||
return true;
|
||||
}
|
||||
var implementingTypes = this.possibleTypesMap[typeCondition];
|
||||
if (__typename &&
|
||||
implementingTypes &&
|
||||
implementingTypes.indexOf(__typename) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
IntrospectionFragmentMatcher.prototype.parseIntrospectionResult = function (introspectionResultData) {
|
||||
var typeMap = {};
|
||||
introspectionResultData.__schema.types.forEach(function (type) {
|
||||
if (type.kind === 'UNION' || type.kind === 'INTERFACE') {
|
||||
typeMap[type.name] = type.possibleTypes.map(function (implementingType) { return implementingType.name; });
|
||||
}
|
||||
});
|
||||
return typeMap;
|
||||
};
|
||||
return IntrospectionFragmentMatcher;
|
||||
}());
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var DepTrackingCache = (function () {
|
||||
function DepTrackingCache(data) {
|
||||
var _this = this;
|
||||
if (data === void 0) { data = Object.create(null); }
|
||||
this.data = data;
|
||||
this.depend = wrap(function (dataId) { return _this.data[dataId]; }, {
|
||||
disposable: true,
|
||||
makeCacheKey: function (dataId) {
|
||||
return dataId;
|
||||
},
|
||||
});
|
||||
}
|
||||
DepTrackingCache.prototype.toObject = function () {
|
||||
return this.data;
|
||||
};
|
||||
DepTrackingCache.prototype.get = function (dataId) {
|
||||
this.depend(dataId);
|
||||
return this.data[dataId];
|
||||
};
|
||||
DepTrackingCache.prototype.set = function (dataId, value) {
|
||||
var oldValue = this.data[dataId];
|
||||
if (value !== oldValue) {
|
||||
this.data[dataId] = value;
|
||||
this.depend.dirty(dataId);
|
||||
}
|
||||
};
|
||||
DepTrackingCache.prototype.delete = function (dataId) {
|
||||
if (hasOwn.call(this.data, dataId)) {
|
||||
delete this.data[dataId];
|
||||
this.depend.dirty(dataId);
|
||||
}
|
||||
};
|
||||
DepTrackingCache.prototype.clear = function () {
|
||||
this.replace(null);
|
||||
};
|
||||
DepTrackingCache.prototype.replace = function (newData) {
|
||||
var _this = this;
|
||||
if (newData) {
|
||||
Object.keys(newData).forEach(function (dataId) {
|
||||
_this.set(dataId, newData[dataId]);
|
||||
});
|
||||
Object.keys(this.data).forEach(function (dataId) {
|
||||
if (!hasOwn.call(newData, dataId)) {
|
||||
_this.delete(dataId);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Object.keys(this.data).forEach(function (dataId) {
|
||||
_this.delete(dataId);
|
||||
});
|
||||
}
|
||||
};
|
||||
return DepTrackingCache;
|
||||
}());
|
||||
function defaultNormalizedCacheFactory(seed) {
|
||||
return new DepTrackingCache(seed);
|
||||
}
|
||||
|
||||
var StoreReader = (function () {
|
||||
function StoreReader(_a) {
|
||||
var _this = this;
|
||||
var _b = _a === void 0 ? {} : _a, _c = _b.cacheKeyRoot, cacheKeyRoot = _c === void 0 ? new KeyTrie(canUseWeakMap) : _c, _d = _b.freezeResults, freezeResults = _d === void 0 ? false : _d;
|
||||
var _e = this, executeStoreQuery = _e.executeStoreQuery, executeSelectionSet = _e.executeSelectionSet, executeSubSelectedArray = _e.executeSubSelectedArray;
|
||||
this.freezeResults = freezeResults;
|
||||
this.executeStoreQuery = wrap(function (options) {
|
||||
return executeStoreQuery.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, fragmentMatcher = _a.fragmentMatcher;
|
||||
if (contextValue.store instanceof DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(contextValue.store, query, fragmentMatcher, JSON.stringify(variableValues), rootValue.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.executeSelectionSet = wrap(function (options) {
|
||||
return executeSelectionSet.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
||||
if (execContext.contextValue.store instanceof DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(execContext.contextValue.store, selectionSet, execContext.fragmentMatcher, JSON.stringify(execContext.variableValues), rootValue.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.executeSubSelectedArray = wrap(function (options) {
|
||||
return executeSubSelectedArray.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var field = _a.field, array = _a.array, execContext = _a.execContext;
|
||||
if (execContext.contextValue.store instanceof DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(execContext.contextValue.store, field, array, JSON.stringify(execContext.variableValues));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
StoreReader.prototype.readQueryFromStore = function (options) {
|
||||
return this.diffQueryAgainstStore(__assign(__assign({}, options), { returnPartialData: false })).result;
|
||||
};
|
||||
StoreReader.prototype.diffQueryAgainstStore = function (_a) {
|
||||
var store = _a.store, query = _a.query, variables = _a.variables, previousResult = _a.previousResult, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, fragmentMatcherFunction = _a.fragmentMatcherFunction, config = _a.config;
|
||||
var queryDefinition = getQueryDefinition(query);
|
||||
variables = assign({}, getDefaultValues(queryDefinition), variables);
|
||||
var context = {
|
||||
store: store,
|
||||
dataIdFromObject: config && config.dataIdFromObject,
|
||||
cacheRedirects: (config && config.cacheRedirects) || {},
|
||||
};
|
||||
var execResult = this.executeStoreQuery({
|
||||
query: query,
|
||||
rootValue: {
|
||||
type: 'id',
|
||||
id: rootId,
|
||||
generated: true,
|
||||
typename: 'Query',
|
||||
},
|
||||
contextValue: context,
|
||||
variableValues: variables,
|
||||
fragmentMatcher: fragmentMatcherFunction,
|
||||
});
|
||||
var hasMissingFields = execResult.missing && execResult.missing.length > 0;
|
||||
if (hasMissingFields && !returnPartialData) {
|
||||
execResult.missing.forEach(function (info) {
|
||||
if (info.tolerable)
|
||||
return;
|
||||
throw process.env.NODE_ENV === "production" ? new InvariantError(8) : new InvariantError("Can't find field " + info.fieldName + " on object " + JSON.stringify(info.object, null, 2) + ".");
|
||||
});
|
||||
}
|
||||
if (previousResult) {
|
||||
if (isEqual(previousResult, execResult.result)) {
|
||||
execResult.result = previousResult;
|
||||
}
|
||||
}
|
||||
return {
|
||||
result: execResult.result,
|
||||
complete: !hasMissingFields,
|
||||
};
|
||||
};
|
||||
StoreReader.prototype.executeStoreQuery = function (_a) {
|
||||
var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, _b = _a.fragmentMatcher, fragmentMatcher = _b === void 0 ? defaultFragmentMatcher : _b;
|
||||
var mainDefinition = getMainDefinition(query);
|
||||
var fragments = getFragmentDefinitions(query);
|
||||
var fragmentMap = createFragmentMap(fragments);
|
||||
var execContext = {
|
||||
query: query,
|
||||
fragmentMap: fragmentMap,
|
||||
contextValue: contextValue,
|
||||
variableValues: variableValues,
|
||||
fragmentMatcher: fragmentMatcher,
|
||||
};
|
||||
return this.executeSelectionSet({
|
||||
selectionSet: mainDefinition.selectionSet,
|
||||
rootValue: rootValue,
|
||||
execContext: execContext,
|
||||
});
|
||||
};
|
||||
StoreReader.prototype.executeSelectionSet = function (_a) {
|
||||
var _this = this;
|
||||
var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
||||
var fragmentMap = execContext.fragmentMap, contextValue = execContext.contextValue, variables = execContext.variableValues;
|
||||
var finalResult = { result: null };
|
||||
var objectsToMerge = [];
|
||||
var object = contextValue.store.get(rootValue.id);
|
||||
var typename = (object && object.__typename) ||
|
||||
(rootValue.id === 'ROOT_QUERY' && 'Query') ||
|
||||
void 0;
|
||||
function handleMissing(result) {
|
||||
var _a;
|
||||
if (result.missing) {
|
||||
finalResult.missing = finalResult.missing || [];
|
||||
(_a = finalResult.missing).push.apply(_a, result.missing);
|
||||
}
|
||||
return result.result;
|
||||
}
|
||||
selectionSet.selections.forEach(function (selection) {
|
||||
var _a;
|
||||
if (!shouldInclude(selection, variables)) {
|
||||
return;
|
||||
}
|
||||
if (isField(selection)) {
|
||||
var fieldResult = handleMissing(_this.executeField(object, typename, selection, execContext));
|
||||
if (typeof fieldResult !== 'undefined') {
|
||||
objectsToMerge.push((_a = {},
|
||||
_a[resultKeyNameFromField(selection)] = fieldResult,
|
||||
_a));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var fragment = void 0;
|
||||
if (isInlineFragment(selection)) {
|
||||
fragment = selection;
|
||||
}
|
||||
else {
|
||||
fragment = fragmentMap[selection.name.value];
|
||||
if (!fragment) {
|
||||
throw process.env.NODE_ENV === "production" ? new InvariantError(9) : new InvariantError("No fragment named " + selection.name.value);
|
||||
}
|
||||
}
|
||||
var typeCondition = fragment.typeCondition && fragment.typeCondition.name.value;
|
||||
var match = !typeCondition ||
|
||||
execContext.fragmentMatcher(rootValue, typeCondition, contextValue);
|
||||
if (match) {
|
||||
var fragmentExecResult = _this.executeSelectionSet({
|
||||
selectionSet: fragment.selectionSet,
|
||||
rootValue: rootValue,
|
||||
execContext: execContext,
|
||||
});
|
||||
if (match === 'heuristic' && fragmentExecResult.missing) {
|
||||
fragmentExecResult = __assign(__assign({}, fragmentExecResult), { missing: fragmentExecResult.missing.map(function (info) {
|
||||
return __assign(__assign({}, info), { tolerable: true });
|
||||
}) });
|
||||
}
|
||||
objectsToMerge.push(handleMissing(fragmentExecResult));
|
||||
}
|
||||
}
|
||||
});
|
||||
finalResult.result = mergeDeepArray(objectsToMerge);
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(finalResult.result);
|
||||
}
|
||||
return finalResult;
|
||||
};
|
||||
StoreReader.prototype.executeField = function (object, typename, field, execContext) {
|
||||
var variables = execContext.variableValues, contextValue = execContext.contextValue;
|
||||
var fieldName = field.name.value;
|
||||
var args = argumentsObjectFromField(field, variables);
|
||||
var info = {
|
||||
resultKey: resultKeyNameFromField(field),
|
||||
directives: getDirectiveInfoFromField(field, variables),
|
||||
};
|
||||
var readStoreResult = readStoreResolver(object, typename, fieldName, args, contextValue, info);
|
||||
if (Array.isArray(readStoreResult.result)) {
|
||||
return this.combineExecResults(readStoreResult, this.executeSubSelectedArray({
|
||||
field: field,
|
||||
array: readStoreResult.result,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
if (!field.selectionSet) {
|
||||
assertSelectionSetForIdValue(field, readStoreResult.result);
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
maybeDeepFreeze(readStoreResult);
|
||||
}
|
||||
return readStoreResult;
|
||||
}
|
||||
if (readStoreResult.result == null) {
|
||||
return readStoreResult;
|
||||
}
|
||||
return this.combineExecResults(readStoreResult, this.executeSelectionSet({
|
||||
selectionSet: field.selectionSet,
|
||||
rootValue: readStoreResult.result,
|
||||
execContext: execContext,
|
||||
}));
|
||||
};
|
||||
StoreReader.prototype.combineExecResults = function () {
|
||||
var execResults = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
execResults[_i] = arguments[_i];
|
||||
}
|
||||
var missing;
|
||||
execResults.forEach(function (execResult) {
|
||||
if (execResult.missing) {
|
||||
missing = missing || [];
|
||||
missing.push.apply(missing, execResult.missing);
|
||||
}
|
||||
});
|
||||
return {
|
||||
result: execResults.pop().result,
|
||||
missing: missing,
|
||||
};
|
||||
};
|
||||
StoreReader.prototype.executeSubSelectedArray = function (_a) {
|
||||
var _this = this;
|
||||
var field = _a.field, array = _a.array, execContext = _a.execContext;
|
||||
var missing;
|
||||
function handleMissing(childResult) {
|
||||
if (childResult.missing) {
|
||||
missing = missing || [];
|
||||
missing.push.apply(missing, childResult.missing);
|
||||
}
|
||||
return childResult.result;
|
||||
}
|
||||
array = array.map(function (item) {
|
||||
if (item === null) {
|
||||
return null;
|
||||
}
|
||||
if (Array.isArray(item)) {
|
||||
return handleMissing(_this.executeSubSelectedArray({
|
||||
field: field,
|
||||
array: item,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
if (field.selectionSet) {
|
||||
return handleMissing(_this.executeSelectionSet({
|
||||
selectionSet: field.selectionSet,
|
||||
rootValue: item,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
assertSelectionSetForIdValue(field, item);
|
||||
return item;
|
||||
});
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(array);
|
||||
}
|
||||
return { result: array, missing: missing };
|
||||
};
|
||||
return StoreReader;
|
||||
}());
|
||||
function assertSelectionSetForIdValue(field, value) {
|
||||
if (!field.selectionSet && isIdValue(value)) {
|
||||
throw process.env.NODE_ENV === "production" ? new InvariantError(10) : new InvariantError("Missing selection set for object of type " + value.typename + " returned for query field " + field.name.value);
|
||||
}
|
||||
}
|
||||
function defaultFragmentMatcher() {
|
||||
return true;
|
||||
}
|
||||
function assertIdValue(idValue) {
|
||||
process.env.NODE_ENV === "production" ? invariant(isIdValue(idValue), 11) : invariant(isIdValue(idValue), "Encountered a sub-selection on the query, but the store doesn't have an object reference. This should never happen during normal use unless you have custom code that is directly manipulating the store; please file an issue.");
|
||||
}
|
||||
function readStoreResolver(object, typename, fieldName, args, context, _a) {
|
||||
var resultKey = _a.resultKey, directives = _a.directives;
|
||||
var storeKeyName = fieldName;
|
||||
if (args || directives) {
|
||||
storeKeyName = getStoreKeyName(storeKeyName, args, directives);
|
||||
}
|
||||
var fieldValue = void 0;
|
||||
if (object) {
|
||||
fieldValue = object[storeKeyName];
|
||||
if (typeof fieldValue === 'undefined' &&
|
||||
context.cacheRedirects &&
|
||||
typeof typename === 'string') {
|
||||
var type = context.cacheRedirects[typename];
|
||||
if (type) {
|
||||
var resolver = type[fieldName];
|
||||
if (resolver) {
|
||||
fieldValue = resolver(object, args, {
|
||||
getCacheKey: function (storeObj) {
|
||||
var id = context.dataIdFromObject(storeObj);
|
||||
return id && toIdValue({
|
||||
id: id,
|
||||
typename: storeObj.__typename,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof fieldValue === 'undefined') {
|
||||
return {
|
||||
result: fieldValue,
|
||||
missing: [{
|
||||
object: object,
|
||||
fieldName: storeKeyName,
|
||||
tolerable: false,
|
||||
}],
|
||||
};
|
||||
}
|
||||
if (isJsonValue(fieldValue)) {
|
||||
fieldValue = fieldValue.json;
|
||||
}
|
||||
return {
|
||||
result: fieldValue,
|
||||
};
|
||||
}
|
||||
|
||||
var ObjectCache = (function () {
|
||||
function ObjectCache(data) {
|
||||
if (data === void 0) { data = Object.create(null); }
|
||||
this.data = data;
|
||||
}
|
||||
ObjectCache.prototype.toObject = function () {
|
||||
return this.data;
|
||||
};
|
||||
ObjectCache.prototype.get = function (dataId) {
|
||||
return this.data[dataId];
|
||||
};
|
||||
ObjectCache.prototype.set = function (dataId, value) {
|
||||
this.data[dataId] = value;
|
||||
};
|
||||
ObjectCache.prototype.delete = function (dataId) {
|
||||
this.data[dataId] = void 0;
|
||||
};
|
||||
ObjectCache.prototype.clear = function () {
|
||||
this.data = Object.create(null);
|
||||
};
|
||||
ObjectCache.prototype.replace = function (newData) {
|
||||
this.data = newData || Object.create(null);
|
||||
};
|
||||
return ObjectCache;
|
||||
}());
|
||||
function defaultNormalizedCacheFactory$1(seed) {
|
||||
return new ObjectCache(seed);
|
||||
}
|
||||
|
||||
var WriteError = (function (_super) {
|
||||
__extends(WriteError, _super);
|
||||
function WriteError() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = 'WriteError';
|
||||
return _this;
|
||||
}
|
||||
return WriteError;
|
||||
}(Error));
|
||||
function enhanceErrorWithDocument(error, document) {
|
||||
var enhancedError = new WriteError("Error writing result to store for query:\n " + JSON.stringify(document));
|
||||
enhancedError.message += '\n' + error.message;
|
||||
enhancedError.stack = error.stack;
|
||||
return enhancedError;
|
||||
}
|
||||
var StoreWriter = (function () {
|
||||
function StoreWriter() {
|
||||
}
|
||||
StoreWriter.prototype.writeQueryToStore = function (_a) {
|
||||
var query = _a.query, result = _a.result, _b = _a.store, store = _b === void 0 ? defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
||||
return this.writeResultToStore({
|
||||
dataId: 'ROOT_QUERY',
|
||||
result: result,
|
||||
document: query,
|
||||
store: store,
|
||||
variables: variables,
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
});
|
||||
};
|
||||
StoreWriter.prototype.writeResultToStore = function (_a) {
|
||||
var dataId = _a.dataId, result = _a.result, document = _a.document, _b = _a.store, store = _b === void 0 ? defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
||||
var operationDefinition = getOperationDefinition(document);
|
||||
try {
|
||||
return this.writeSelectionSetToStore({
|
||||
result: result,
|
||||
dataId: dataId,
|
||||
selectionSet: operationDefinition.selectionSet,
|
||||
context: {
|
||||
store: store,
|
||||
processedData: {},
|
||||
variables: assign({}, getDefaultValues(operationDefinition), variables),
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
fragmentMap: createFragmentMap(getFragmentDefinitions(document)),
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
throw enhanceErrorWithDocument(e, document);
|
||||
}
|
||||
};
|
||||
StoreWriter.prototype.writeSelectionSetToStore = function (_a) {
|
||||
var _this = this;
|
||||
var result = _a.result, dataId = _a.dataId, selectionSet = _a.selectionSet, context = _a.context;
|
||||
var variables = context.variables, store = context.store, fragmentMap = context.fragmentMap;
|
||||
selectionSet.selections.forEach(function (selection) {
|
||||
var _a;
|
||||
if (!shouldInclude(selection, variables)) {
|
||||
return;
|
||||
}
|
||||
if (isField(selection)) {
|
||||
var resultFieldKey = resultKeyNameFromField(selection);
|
||||
var value = result[resultFieldKey];
|
||||
if (typeof value !== 'undefined') {
|
||||
_this.writeFieldToStore({
|
||||
dataId: dataId,
|
||||
value: value,
|
||||
field: selection,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
else {
|
||||
var isDefered = false;
|
||||
var isClient = false;
|
||||
if (selection.directives && selection.directives.length) {
|
||||
isDefered = selection.directives.some(function (directive) { return directive.name && directive.name.value === 'defer'; });
|
||||
isClient = selection.directives.some(function (directive) { return directive.name && directive.name.value === 'client'; });
|
||||
}
|
||||
if (!isDefered && !isClient && context.fragmentMatcherFunction) {
|
||||
process.env.NODE_ENV === "production" || invariant.warn("Missing field " + resultFieldKey + " in " + JSON.stringify(result, null, 2).substring(0, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var fragment = void 0;
|
||||
if (isInlineFragment(selection)) {
|
||||
fragment = selection;
|
||||
}
|
||||
else {
|
||||
fragment = (fragmentMap || {})[selection.name.value];
|
||||
process.env.NODE_ENV === "production" ? invariant(fragment, 3) : invariant(fragment, "No fragment named " + selection.name.value + ".");
|
||||
}
|
||||
var matches = true;
|
||||
if (context.fragmentMatcherFunction && fragment.typeCondition) {
|
||||
var id = dataId || 'self';
|
||||
var idValue = toIdValue({ id: id, typename: undefined });
|
||||
var fakeContext = {
|
||||
store: new ObjectCache((_a = {}, _a[id] = result, _a)),
|
||||
cacheRedirects: {},
|
||||
};
|
||||
var match = context.fragmentMatcherFunction(idValue, fragment.typeCondition.name.value, fakeContext);
|
||||
if (!isProduction() && match === 'heuristic') {
|
||||
process.env.NODE_ENV === "production" || invariant.error('WARNING: heuristic fragment matching going on!');
|
||||
}
|
||||
matches = !!match;
|
||||
}
|
||||
if (matches) {
|
||||
_this.writeSelectionSetToStore({
|
||||
result: result,
|
||||
selectionSet: fragment.selectionSet,
|
||||
dataId: dataId,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return store;
|
||||
};
|
||||
StoreWriter.prototype.writeFieldToStore = function (_a) {
|
||||
var _b;
|
||||
var field = _a.field, value = _a.value, dataId = _a.dataId, context = _a.context;
|
||||
var variables = context.variables, dataIdFromObject = context.dataIdFromObject, store = context.store;
|
||||
var storeValue;
|
||||
var storeObject;
|
||||
var storeFieldName = storeKeyNameFromField(field, variables);
|
||||
if (!field.selectionSet || value === null) {
|
||||
storeValue =
|
||||
value != null && typeof value === 'object'
|
||||
?
|
||||
{ type: 'json', json: value }
|
||||
:
|
||||
value;
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
var generatedId = dataId + "." + storeFieldName;
|
||||
storeValue = this.processArrayValue(value, generatedId, field.selectionSet, context);
|
||||
}
|
||||
else {
|
||||
var valueDataId = dataId + "." + storeFieldName;
|
||||
var generated = true;
|
||||
if (!isGeneratedId(valueDataId)) {
|
||||
valueDataId = '$' + valueDataId;
|
||||
}
|
||||
if (dataIdFromObject) {
|
||||
var semanticId = dataIdFromObject(value);
|
||||
process.env.NODE_ENV === "production" ? invariant(!semanticId || !isGeneratedId(semanticId), 4) : invariant(!semanticId || !isGeneratedId(semanticId), 'IDs returned by dataIdFromObject cannot begin with the "$" character.');
|
||||
if (semanticId ||
|
||||
(typeof semanticId === 'number' && semanticId === 0)) {
|
||||
valueDataId = semanticId;
|
||||
generated = false;
|
||||
}
|
||||
}
|
||||
if (!isDataProcessed(valueDataId, field, context.processedData)) {
|
||||
this.writeSelectionSetToStore({
|
||||
dataId: valueDataId,
|
||||
result: value,
|
||||
selectionSet: field.selectionSet,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
var typename = value.__typename;
|
||||
storeValue = toIdValue({ id: valueDataId, typename: typename }, generated);
|
||||
storeObject = store.get(dataId);
|
||||
var escapedId = storeObject && storeObject[storeFieldName];
|
||||
if (escapedId !== storeValue && isIdValue(escapedId)) {
|
||||
var hadTypename = escapedId.typename !== undefined;
|
||||
var hasTypename = typename !== undefined;
|
||||
var typenameChanged = hadTypename && hasTypename && escapedId.typename !== typename;
|
||||
process.env.NODE_ENV === "production" ? invariant(!generated || escapedId.generated || typenameChanged, 5) : invariant(!generated || escapedId.generated || typenameChanged, "Store error: the application attempted to write an object with no provided id but the store already contains an id of " + escapedId.id + " for this object. The selectionSet that was trying to be written is:\n" + JSON.stringify(field));
|
||||
process.env.NODE_ENV === "production" ? invariant(!hadTypename || hasTypename, 6) : invariant(!hadTypename || hasTypename, "Store error: the application attempted to write an object with no provided typename but the store already contains an object with typename of " + escapedId.typename + " for the object of id " + escapedId.id + ". The selectionSet that was trying to be written is:\n" + JSON.stringify(field));
|
||||
if (escapedId.generated) {
|
||||
if (typenameChanged) {
|
||||
if (!generated) {
|
||||
store.delete(escapedId.id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mergeWithGenerated(escapedId.id, storeValue.id, store);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
storeObject = store.get(dataId);
|
||||
if (!storeObject || !isEqual(storeValue, storeObject[storeFieldName])) {
|
||||
store.set(dataId, __assign(__assign({}, storeObject), (_b = {}, _b[storeFieldName] = storeValue, _b)));
|
||||
}
|
||||
};
|
||||
StoreWriter.prototype.processArrayValue = function (value, generatedId, selectionSet, context) {
|
||||
var _this = this;
|
||||
return value.map(function (item, index) {
|
||||
if (item === null) {
|
||||
return null;
|
||||
}
|
||||
var itemDataId = generatedId + "." + index;
|
||||
if (Array.isArray(item)) {
|
||||
return _this.processArrayValue(item, itemDataId, selectionSet, context);
|
||||
}
|
||||
var generated = true;
|
||||
if (context.dataIdFromObject) {
|
||||
var semanticId = context.dataIdFromObject(item);
|
||||
if (semanticId) {
|
||||
itemDataId = semanticId;
|
||||
generated = false;
|
||||
}
|
||||
}
|
||||
if (!isDataProcessed(itemDataId, selectionSet, context.processedData)) {
|
||||
_this.writeSelectionSetToStore({
|
||||
dataId: itemDataId,
|
||||
result: item,
|
||||
selectionSet: selectionSet,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
return toIdValue({ id: itemDataId, typename: item.__typename }, generated);
|
||||
});
|
||||
};
|
||||
return StoreWriter;
|
||||
}());
|
||||
function isGeneratedId(id) {
|
||||
return id[0] === '$';
|
||||
}
|
||||
function mergeWithGenerated(generatedKey, realKey, cache) {
|
||||
if (generatedKey === realKey) {
|
||||
return false;
|
||||
}
|
||||
var generated = cache.get(generatedKey);
|
||||
var real = cache.get(realKey);
|
||||
var madeChanges = false;
|
||||
Object.keys(generated).forEach(function (key) {
|
||||
var value = generated[key];
|
||||
var realValue = real[key];
|
||||
if (isIdValue(value) &&
|
||||
isGeneratedId(value.id) &&
|
||||
isIdValue(realValue) &&
|
||||
!isEqual(value, realValue) &&
|
||||
mergeWithGenerated(value.id, realValue.id, cache)) {
|
||||
madeChanges = true;
|
||||
}
|
||||
});
|
||||
cache.delete(generatedKey);
|
||||
var newRealValue = __assign(__assign({}, generated), real);
|
||||
if (isEqual(newRealValue, real)) {
|
||||
return madeChanges;
|
||||
}
|
||||
cache.set(realKey, newRealValue);
|
||||
return true;
|
||||
}
|
||||
function isDataProcessed(dataId, field, processedData) {
|
||||
if (!processedData) {
|
||||
return false;
|
||||
}
|
||||
if (processedData[dataId]) {
|
||||
if (processedData[dataId].indexOf(field) >= 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
processedData[dataId].push(field);
|
||||
}
|
||||
}
|
||||
else {
|
||||
processedData[dataId] = [field];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var defaultConfig = {
|
||||
fragmentMatcher: new HeuristicFragmentMatcher(),
|
||||
dataIdFromObject: defaultDataIdFromObject,
|
||||
addTypename: true,
|
||||
resultCaching: true,
|
||||
freezeResults: false,
|
||||
};
|
||||
function defaultDataIdFromObject(result) {
|
||||
if (result.__typename) {
|
||||
if (result.id !== undefined) {
|
||||
return result.__typename + ":" + result.id;
|
||||
}
|
||||
if (result._id !== undefined) {
|
||||
return result.__typename + ":" + result._id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var hasOwn$1 = Object.prototype.hasOwnProperty;
|
||||
var OptimisticCacheLayer = (function (_super) {
|
||||
__extends(OptimisticCacheLayer, _super);
|
||||
function OptimisticCacheLayer(optimisticId, parent, transaction) {
|
||||
var _this = _super.call(this, Object.create(null)) || this;
|
||||
_this.optimisticId = optimisticId;
|
||||
_this.parent = parent;
|
||||
_this.transaction = transaction;
|
||||
return _this;
|
||||
}
|
||||
OptimisticCacheLayer.prototype.toObject = function () {
|
||||
return __assign(__assign({}, this.parent.toObject()), this.data);
|
||||
};
|
||||
OptimisticCacheLayer.prototype.get = function (dataId) {
|
||||
return hasOwn$1.call(this.data, dataId)
|
||||
? this.data[dataId]
|
||||
: this.parent.get(dataId);
|
||||
};
|
||||
return OptimisticCacheLayer;
|
||||
}(ObjectCache));
|
||||
var InMemoryCache = (function (_super) {
|
||||
__extends(InMemoryCache, _super);
|
||||
function InMemoryCache(config) {
|
||||
if (config === void 0) { config = {}; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.watches = new Set();
|
||||
_this.typenameDocumentCache = new Map();
|
||||
_this.cacheKeyRoot = new KeyTrie(canUseWeakMap);
|
||||
_this.silenceBroadcast = false;
|
||||
_this.config = __assign(__assign({}, defaultConfig), config);
|
||||
if (_this.config.customResolvers) {
|
||||
process.env.NODE_ENV === "production" || invariant.warn('customResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating customResolvers in the next major version.');
|
||||
_this.config.cacheRedirects = _this.config.customResolvers;
|
||||
}
|
||||
if (_this.config.cacheResolvers) {
|
||||
process.env.NODE_ENV === "production" || invariant.warn('cacheResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating cacheResolvers in the next major version.');
|
||||
_this.config.cacheRedirects = _this.config.cacheResolvers;
|
||||
}
|
||||
_this.addTypename = !!_this.config.addTypename;
|
||||
_this.data = _this.config.resultCaching
|
||||
? new DepTrackingCache()
|
||||
: new ObjectCache();
|
||||
_this.optimisticData = _this.data;
|
||||
_this.storeWriter = new StoreWriter();
|
||||
_this.storeReader = new StoreReader({
|
||||
cacheKeyRoot: _this.cacheKeyRoot,
|
||||
freezeResults: config.freezeResults,
|
||||
});
|
||||
var cache = _this;
|
||||
var maybeBroadcastWatch = cache.maybeBroadcastWatch;
|
||||
_this.maybeBroadcastWatch = wrap(function (c) {
|
||||
return maybeBroadcastWatch.call(_this, c);
|
||||
}, {
|
||||
makeCacheKey: function (c) {
|
||||
if (c.optimistic) {
|
||||
return;
|
||||
}
|
||||
if (c.previousResult) {
|
||||
return;
|
||||
}
|
||||
if (cache.data instanceof DepTrackingCache) {
|
||||
return cache.cacheKeyRoot.lookup(c.query, JSON.stringify(c.variables));
|
||||
}
|
||||
}
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
InMemoryCache.prototype.restore = function (data) {
|
||||
if (data)
|
||||
this.data.replace(data);
|
||||
return this;
|
||||
};
|
||||
InMemoryCache.prototype.extract = function (optimistic) {
|
||||
if (optimistic === void 0) { optimistic = false; }
|
||||
return (optimistic ? this.optimisticData : this.data).toObject();
|
||||
};
|
||||
InMemoryCache.prototype.read = function (options) {
|
||||
if (typeof options.rootId === 'string' &&
|
||||
typeof this.data.get(options.rootId) === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
return this.storeReader.readQueryFromStore({
|
||||
store: options.optimistic ? this.optimisticData : this.data,
|
||||
query: this.transformDocument(options.query),
|
||||
variables: options.variables,
|
||||
rootId: options.rootId,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
previousResult: options.previousResult,
|
||||
config: this.config,
|
||||
}) || null;
|
||||
};
|
||||
InMemoryCache.prototype.write = function (write) {
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
this.storeWriter.writeResultToStore({
|
||||
dataId: write.dataId,
|
||||
result: write.result,
|
||||
variables: write.variables,
|
||||
document: this.transformDocument(write.query),
|
||||
store: this.data,
|
||||
dataIdFromObject: this.config.dataIdFromObject,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
});
|
||||
this.broadcastWatches();
|
||||
};
|
||||
InMemoryCache.prototype.diff = function (query) {
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
return this.storeReader.diffQueryAgainstStore({
|
||||
store: query.optimistic ? this.optimisticData : this.data,
|
||||
query: this.transformDocument(query.query),
|
||||
variables: query.variables,
|
||||
returnPartialData: query.returnPartialData,
|
||||
previousResult: query.previousResult,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
config: this.config,
|
||||
});
|
||||
};
|
||||
InMemoryCache.prototype.watch = function (watch) {
|
||||
var _this = this;
|
||||
this.watches.add(watch);
|
||||
return function () {
|
||||
_this.watches.delete(watch);
|
||||
};
|
||||
};
|
||||
InMemoryCache.prototype.evict = function (query) {
|
||||
throw process.env.NODE_ENV === "production" ? new InvariantError(7) : new InvariantError("eviction is not implemented on InMemory Cache");
|
||||
};
|
||||
InMemoryCache.prototype.reset = function () {
|
||||
this.data.clear();
|
||||
this.broadcastWatches();
|
||||
return Promise.resolve();
|
||||
};
|
||||
InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
|
||||
var toReapply = [];
|
||||
var removedCount = 0;
|
||||
var layer = this.optimisticData;
|
||||
while (layer instanceof OptimisticCacheLayer) {
|
||||
if (layer.optimisticId === idToRemove) {
|
||||
++removedCount;
|
||||
}
|
||||
else {
|
||||
toReapply.push(layer);
|
||||
}
|
||||
layer = layer.parent;
|
||||
}
|
||||
if (removedCount > 0) {
|
||||
this.optimisticData = layer;
|
||||
while (toReapply.length > 0) {
|
||||
var layer_1 = toReapply.pop();
|
||||
this.performTransaction(layer_1.transaction, layer_1.optimisticId);
|
||||
}
|
||||
this.broadcastWatches();
|
||||
}
|
||||
};
|
||||
InMemoryCache.prototype.performTransaction = function (transaction, optimisticId) {
|
||||
var _a = this, data = _a.data, silenceBroadcast = _a.silenceBroadcast;
|
||||
this.silenceBroadcast = true;
|
||||
if (typeof optimisticId === 'string') {
|
||||
this.data = this.optimisticData = new OptimisticCacheLayer(optimisticId, this.optimisticData, transaction);
|
||||
}
|
||||
try {
|
||||
transaction(this);
|
||||
}
|
||||
finally {
|
||||
this.silenceBroadcast = silenceBroadcast;
|
||||
this.data = data;
|
||||
}
|
||||
this.broadcastWatches();
|
||||
};
|
||||
InMemoryCache.prototype.recordOptimisticTransaction = function (transaction, id) {
|
||||
return this.performTransaction(transaction, id);
|
||||
};
|
||||
InMemoryCache.prototype.transformDocument = function (document) {
|
||||
if (this.addTypename) {
|
||||
var result = this.typenameDocumentCache.get(document);
|
||||
if (!result) {
|
||||
result = addTypenameToDocument(document);
|
||||
this.typenameDocumentCache.set(document, result);
|
||||
this.typenameDocumentCache.set(result, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return document;
|
||||
};
|
||||
InMemoryCache.prototype.broadcastWatches = function () {
|
||||
var _this = this;
|
||||
if (!this.silenceBroadcast) {
|
||||
this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c); });
|
||||
}
|
||||
};
|
||||
InMemoryCache.prototype.maybeBroadcastWatch = function (c) {
|
||||
c.callback(this.diff({
|
||||
query: c.query,
|
||||
variables: c.variables,
|
||||
previousResult: c.previousResult && c.previousResult(),
|
||||
optimistic: c.optimistic,
|
||||
}));
|
||||
};
|
||||
return InMemoryCache;
|
||||
}(ApolloCache));
|
||||
|
||||
export { HeuristicFragmentMatcher, InMemoryCache, IntrospectionFragmentMatcher, ObjectCache, StoreReader, StoreWriter, WriteError, assertIdValue, defaultDataIdFromObject, defaultNormalizedCacheFactory$1 as defaultNormalizedCacheFactory, enhanceErrorWithDocument };
|
||||
//# sourceMappingURL=bundle.esm.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/bundle.esm.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/bundle.esm.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1284
node_modules/apollo-cache-inmemory/lib/bundle.umd.js
generated
vendored
Normal file
1284
node_modules/apollo-cache-inmemory/lib/bundle.umd.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/apollo-cache-inmemory/lib/bundle.umd.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/bundle.umd.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
14
node_modules/apollo-cache-inmemory/lib/depTrackingCache.d.ts
generated
vendored
Normal file
14
node_modules/apollo-cache-inmemory/lib/depTrackingCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
|
||||
export declare class DepTrackingCache implements NormalizedCache {
|
||||
private data;
|
||||
private depend;
|
||||
constructor(data?: NormalizedCacheObject);
|
||||
toObject(): NormalizedCacheObject;
|
||||
get(dataId: string): StoreObject;
|
||||
set(dataId: string, value?: StoreObject): void;
|
||||
delete(dataId: string): void;
|
||||
clear(): void;
|
||||
replace(newData: NormalizedCacheObject | null): void;
|
||||
}
|
||||
export declare function defaultNormalizedCacheFactory(seed?: NormalizedCacheObject): NormalizedCache;
|
||||
//# sourceMappingURL=depTrackingCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/depTrackingCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/depTrackingCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"depTrackingCache.d.ts","sourceRoot":"","sources":["src/depTrackingCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK9E,qBAAa,gBAAiB,YAAW,eAAe;IAK1C,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,MAAM,CAA+D;gBAEzD,IAAI,GAAE,qBAA2C;IAS9D,QAAQ,IAAI,qBAAqB;IAIjC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;IAKhC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW;IAQvC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,GAAG,IAAI;CAgB5D;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,CAAC,EAAE,qBAAqB,GAC3B,eAAe,CAEjB"}
|
||||
65
node_modules/apollo-cache-inmemory/lib/depTrackingCache.js
generated
vendored
Normal file
65
node_modules/apollo-cache-inmemory/lib/depTrackingCache.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var optimism_1 = require("optimism");
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var DepTrackingCache = (function () {
|
||||
function DepTrackingCache(data) {
|
||||
var _this = this;
|
||||
if (data === void 0) { data = Object.create(null); }
|
||||
this.data = data;
|
||||
this.depend = optimism_1.wrap(function (dataId) { return _this.data[dataId]; }, {
|
||||
disposable: true,
|
||||
makeCacheKey: function (dataId) {
|
||||
return dataId;
|
||||
},
|
||||
});
|
||||
}
|
||||
DepTrackingCache.prototype.toObject = function () {
|
||||
return this.data;
|
||||
};
|
||||
DepTrackingCache.prototype.get = function (dataId) {
|
||||
this.depend(dataId);
|
||||
return this.data[dataId];
|
||||
};
|
||||
DepTrackingCache.prototype.set = function (dataId, value) {
|
||||
var oldValue = this.data[dataId];
|
||||
if (value !== oldValue) {
|
||||
this.data[dataId] = value;
|
||||
this.depend.dirty(dataId);
|
||||
}
|
||||
};
|
||||
DepTrackingCache.prototype.delete = function (dataId) {
|
||||
if (hasOwn.call(this.data, dataId)) {
|
||||
delete this.data[dataId];
|
||||
this.depend.dirty(dataId);
|
||||
}
|
||||
};
|
||||
DepTrackingCache.prototype.clear = function () {
|
||||
this.replace(null);
|
||||
};
|
||||
DepTrackingCache.prototype.replace = function (newData) {
|
||||
var _this = this;
|
||||
if (newData) {
|
||||
Object.keys(newData).forEach(function (dataId) {
|
||||
_this.set(dataId, newData[dataId]);
|
||||
});
|
||||
Object.keys(this.data).forEach(function (dataId) {
|
||||
if (!hasOwn.call(newData, dataId)) {
|
||||
_this.delete(dataId);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Object.keys(this.data).forEach(function (dataId) {
|
||||
_this.delete(dataId);
|
||||
});
|
||||
}
|
||||
};
|
||||
return DepTrackingCache;
|
||||
}());
|
||||
exports.DepTrackingCache = DepTrackingCache;
|
||||
function defaultNormalizedCacheFactory(seed) {
|
||||
return new DepTrackingCache(seed);
|
||||
}
|
||||
exports.defaultNormalizedCacheFactory = defaultNormalizedCacheFactory;
|
||||
//# sourceMappingURL=depTrackingCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/depTrackingCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/depTrackingCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"depTrackingCache.js","sourceRoot":"","sources":["../src/depTrackingCache.ts"],"names":[],"mappings":";;AACA,qCAA2D;AAE3D,IAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AAE/C;IAKE,0BAAoB,IAAiD;QAArE,iBAOC;QAPmB,qBAAA,EAAA,OAA8B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAAjD,SAAI,GAAJ,IAAI,CAA6C;QACnE,IAAI,CAAC,MAAM,GAAG,eAAI,CAAC,UAAC,MAAc,IAAK,OAAA,KAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAjB,CAAiB,EAAE;YACxD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAZ,UAAa,MAAc;gBACzB,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,mCAAQ,GAAf;QACE,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEM,8BAAG,GAAV,UAAW,MAAc;QACvB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC;IAC5B,CAAC;IAEM,8BAAG,GAAV,UAAW,MAAc,EAAE,KAAmB;QAC5C,IAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,KAAK,KAAK,QAAQ,EAAE;YACtB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAC3B;IACH,CAAC;IAEM,iCAAM,GAAb,UAAc,MAAc;QAC1B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;YAClC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAC3B;IACH,CAAC;IAEM,gCAAK,GAAZ;QACE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,kCAAO,GAAd,UAAe,OAAqC;QAApD,iBAeC;QAdC,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAA,MAAM;gBACjC,KAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAA,MAAM;gBACnC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;oBACjC,KAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBACrB;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAA,MAAM;gBACnC,KAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AA1DD,IA0DC;AA1DY,4CAAgB;AA4D7B,SAAgB,6BAA6B,CAC3C,IAA4B;IAE5B,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAJD,sEAIC"}
|
||||
2
node_modules/apollo-cache-inmemory/lib/fixPolyfills.d.ts
generated
vendored
Normal file
2
node_modules/apollo-cache-inmemory/lib/fixPolyfills.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=fixPolyfills.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fixPolyfills.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fixPolyfills.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixPolyfills.d.ts","sourceRoot":"","sources":["src/fixPolyfills.ts"],"names":[],"mappings":"AAoDA,OAAO,EAAE,CAAA"}
|
||||
49
node_modules/apollo-cache-inmemory/lib/fixPolyfills.js
generated
vendored
Normal file
49
node_modules/apollo-cache-inmemory/lib/fixPolyfills.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var testMap = new Map();
|
||||
if (testMap.set(1, 2) !== testMap) {
|
||||
var set_1 = testMap.set;
|
||||
Map.prototype.set = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
set_1.apply(this, args);
|
||||
return this;
|
||||
};
|
||||
}
|
||||
var testSet = new Set();
|
||||
if (testSet.add(3) !== testSet) {
|
||||
var add_1 = testSet.add;
|
||||
Set.prototype.add = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
add_1.apply(this, args);
|
||||
return this;
|
||||
};
|
||||
}
|
||||
var frozen = {};
|
||||
if (typeof Object.freeze === 'function') {
|
||||
Object.freeze(frozen);
|
||||
}
|
||||
try {
|
||||
testMap.set(frozen, frozen).delete(frozen);
|
||||
}
|
||||
catch (_a) {
|
||||
var wrap = function (method) {
|
||||
return method && (function (obj) {
|
||||
try {
|
||||
testMap.set(obj, obj).delete(obj);
|
||||
}
|
||||
finally {
|
||||
return method.call(Object, obj);
|
||||
}
|
||||
});
|
||||
};
|
||||
Object.freeze = wrap(Object.freeze);
|
||||
Object.seal = wrap(Object.seal);
|
||||
Object.preventExtensions = wrap(Object.preventExtensions);
|
||||
}
|
||||
//# sourceMappingURL=fixPolyfills.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fixPolyfills.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fixPolyfills.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixPolyfills.js","sourceRoot":"","sources":["../src/fixPolyfills.ts"],"names":[],"mappings":";;AAEA,IAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,EAAE;IACzB,IAAA,mBAAG,CAAa;IACxB,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG;QAAU,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,yBAAO;;QACnC,KAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;CACH;AAGD,IAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,IAAA,mBAAG,CAAa;IACxB,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG;QAAU,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,yBAAO;;QACnC,KAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;CACH;AAED,IAAM,MAAM,GAAG,EAAE,CAAC;AAClB,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE;IACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,IAAI;IAOF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CAC5C;AAAC,WAAM;IACN,IAAM,IAAI,GAAG,UAAC,MAAwB;QACpC,OAAO,MAAM,IAAI,CAAC,UAAA,GAAG;YACnB,IAAI;gBAEF,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aACnC;oBAAS;gBAGR,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;CAC3D"}
|
||||
18
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.d.ts
generated
vendored
Normal file
18
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IdValue } from 'apollo-utilities';
|
||||
import { ReadStoreContext, FragmentMatcherInterface, IntrospectionResultData } from './types';
|
||||
export declare class HeuristicFragmentMatcher implements FragmentMatcherInterface {
|
||||
constructor();
|
||||
ensureReady(): Promise<void>;
|
||||
canBypassInit(): boolean;
|
||||
match(idValue: IdValue, typeCondition: string, context: ReadStoreContext): boolean | 'heuristic';
|
||||
}
|
||||
export declare class IntrospectionFragmentMatcher implements FragmentMatcherInterface {
|
||||
private isReady;
|
||||
private possibleTypesMap;
|
||||
constructor(options?: {
|
||||
introspectionQueryResultData?: IntrospectionResultData;
|
||||
});
|
||||
match(idValue: IdValue, typeCondition: string, context: ReadStoreContext): boolean;
|
||||
private parseIntrospectionResult;
|
||||
}
|
||||
//# sourceMappingURL=fragmentMatcher.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcher.d.ts","sourceRoot":"","sources":["src/fragmentMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EAExB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAgBjB,qBAAa,wBAAyB,YAAW,wBAAwB;;IAKhE,WAAW;IAIX,aAAa;IAIb,KAAK,CACV,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,GAAG,WAAW;CA6DzB;AAED,qBAAa,4BAA6B,YAAW,wBAAwB;IAC3E,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,OAAO,CAAC,EAAE;QACpB,4BAA4B,CAAC,EAAE,uBAAuB,CAAC;KACxD;IAaM,KAAK,CACV,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB;IAwC3B,OAAO,CAAC,wBAAwB;CAajC"}
|
||||
96
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.js
generated
vendored
Normal file
96
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var ts_invariant_1 = require("ts-invariant");
|
||||
var haveWarned = false;
|
||||
function shouldWarn() {
|
||||
var answer = !haveWarned;
|
||||
if (!apollo_utilities_1.isTest()) {
|
||||
haveWarned = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
var HeuristicFragmentMatcher = (function () {
|
||||
function HeuristicFragmentMatcher() {
|
||||
}
|
||||
HeuristicFragmentMatcher.prototype.ensureReady = function () {
|
||||
return Promise.resolve();
|
||||
};
|
||||
HeuristicFragmentMatcher.prototype.canBypassInit = function () {
|
||||
return true;
|
||||
};
|
||||
HeuristicFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
||||
var obj = context.store.get(idValue.id);
|
||||
var isRootQuery = idValue.id === 'ROOT_QUERY';
|
||||
if (!obj) {
|
||||
return isRootQuery;
|
||||
}
|
||||
var _a = obj.__typename, __typename = _a === void 0 ? isRootQuery && 'Query' : _a;
|
||||
if (!__typename) {
|
||||
if (shouldWarn()) {
|
||||
ts_invariant_1.invariant.warn("You're using fragments in your queries, but either don't have the addTypename:\n true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.\n Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client\n can accurately match fragments.");
|
||||
ts_invariant_1.invariant.warn('Could not find __typename on Fragment ', typeCondition, obj);
|
||||
ts_invariant_1.invariant.warn("DEPRECATION WARNING: using fragments without __typename is unsupported behavior " +
|
||||
"and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.");
|
||||
}
|
||||
return 'heuristic';
|
||||
}
|
||||
if (__typename === typeCondition) {
|
||||
return true;
|
||||
}
|
||||
if (shouldWarn()) {
|
||||
ts_invariant_1.invariant.error('You are using the simple (heuristic) fragment matcher, but your ' +
|
||||
'queries contain union or interface types. Apollo Client will not be ' +
|
||||
'able to accurately map fragments. To make this error go away, use ' +
|
||||
'the `IntrospectionFragmentMatcher` as described in the docs: ' +
|
||||
'https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher');
|
||||
}
|
||||
return 'heuristic';
|
||||
};
|
||||
return HeuristicFragmentMatcher;
|
||||
}());
|
||||
exports.HeuristicFragmentMatcher = HeuristicFragmentMatcher;
|
||||
var IntrospectionFragmentMatcher = (function () {
|
||||
function IntrospectionFragmentMatcher(options) {
|
||||
if (options && options.introspectionQueryResultData) {
|
||||
this.possibleTypesMap = this.parseIntrospectionResult(options.introspectionQueryResultData);
|
||||
this.isReady = true;
|
||||
}
|
||||
else {
|
||||
this.isReady = false;
|
||||
}
|
||||
this.match = this.match.bind(this);
|
||||
}
|
||||
IntrospectionFragmentMatcher.prototype.match = function (idValue, typeCondition, context) {
|
||||
ts_invariant_1.invariant(this.isReady, 'FragmentMatcher.match() was called before FragmentMatcher.init()');
|
||||
var obj = context.store.get(idValue.id);
|
||||
var isRootQuery = idValue.id === 'ROOT_QUERY';
|
||||
if (!obj) {
|
||||
return isRootQuery;
|
||||
}
|
||||
var _a = obj.__typename, __typename = _a === void 0 ? isRootQuery && 'Query' : _a;
|
||||
ts_invariant_1.invariant(__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));
|
||||
if (__typename === typeCondition) {
|
||||
return true;
|
||||
}
|
||||
var implementingTypes = this.possibleTypesMap[typeCondition];
|
||||
if (__typename &&
|
||||
implementingTypes &&
|
||||
implementingTypes.indexOf(__typename) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
IntrospectionFragmentMatcher.prototype.parseIntrospectionResult = function (introspectionResultData) {
|
||||
var typeMap = {};
|
||||
introspectionResultData.__schema.types.forEach(function (type) {
|
||||
if (type.kind === 'UNION' || type.kind === 'INTERFACE') {
|
||||
typeMap[type.name] = type.possibleTypes.map(function (implementingType) { return implementingType.name; });
|
||||
}
|
||||
});
|
||||
return typeMap;
|
||||
};
|
||||
return IntrospectionFragmentMatcher;
|
||||
}());
|
||||
exports.IntrospectionFragmentMatcher = IntrospectionFragmentMatcher;
|
||||
//# sourceMappingURL=fragmentMatcher.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcher.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcher.js","sourceRoot":"","sources":["../src/fragmentMatcher.ts"],"names":[],"mappings":";;AAAA,qDAAmD;AACnD,6CAAyC;AASzC,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,SAAS,UAAU;IACjB,IAAM,MAAM,GAAG,CAAC,UAAU,CAAC;IAE3B,IAAI,CAAC,yBAAM,EAAE,EAAE;QACb,UAAU,GAAG,IAAI,CAAC;KACnB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAKD;IACE;IAEA,CAAC;IAEM,8CAAW,GAAlB;QACE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAEM,gDAAa,GAApB;QACE,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,wCAAK,GAAZ,UACE,OAAgB,EAChB,aAAqB,EACrB,OAAyB;QAEzB,IAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC1C,IAAM,WAAW,GAAG,OAAO,CAAC,EAAE,KAAK,YAAY,CAAC;QAEhD,IAAI,CAAC,GAAG,EAAE;YAER,OAAO,WAAW,CAAC;SACpB;QAEO,IAAA,mBAAmC,EAAnC,wDAAmC,CAAS;QAEpD,IAAI,CAAC,UAAU,EAAE;YACf,IAAI,UAAU,EAAE,EAAE;gBAChB,wBAAS,CAAC,IAAI,CAAC,kVAGY,CAAC,CAAC;gBAC7B,wBAAS,CAAC,IAAI,CACZ,wCAAwC,EACxC,aAAa,EACb,GAAG,CACJ,CAAC;gBACF,wBAAS,CAAC,IAAI,CACZ,kFAAkF;oBAChF,+GAA+G,CAClH,CAAC;aACH;YAED,OAAO,WAAW,CAAC;SACpB;QAED,IAAI,UAAU,KAAK,aAAa,EAAE;YAChC,OAAO,IAAI,CAAC;SACb;QAgBD,IAAI,UAAU,EAAE,EAAE;YAChB,wBAAS,CAAC,KAAK,CACb,kEAAkE;gBAChE,sEAAsE;gBACtE,oEAAoE;gBACpE,+DAA+D;gBAC/D,mFAAmF,CACtF,CAAC;SACH;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IACH,+BAAC;AAAD,CAAC,AA9ED,IA8EC;AA9EY,4DAAwB;AAgFrC;IAIE,sCAAY,OAEX;QACC,IAAI,OAAO,IAAI,OAAO,CAAC,4BAA4B,EAAE;YACnD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,wBAAwB,CACnD,OAAO,CAAC,4BAA4B,CACrC,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACtB;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEM,4CAAK,GAAZ,UACE,OAAgB,EAChB,aAAqB,EACrB,OAAyB;QAEzB,wBAAS,CACP,IAAI,CAAC,OAAO,EACZ,kEAAkE,CACnE,CAAC;QAEF,IAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC1C,IAAM,WAAW,GAAG,OAAO,CAAC,EAAE,KAAK,YAAY,CAAC;QAEhD,IAAI,CAAC,GAAG,EAAE;YAER,OAAO,WAAW,CAAC;SACpB;QAEO,IAAA,mBAAmC,EAAnC,wDAAmC,CAAS;QAEpD,wBAAS,CACP,UAAU,EACV,mEAAiE,IAAI,CAAC,SAAS,CAC7E,GAAG,CACF,CACJ,CAAC;QAEF,IAAI,UAAU,KAAK,aAAa,EAAE;YAChC,OAAO,IAAI,CAAC;SACb;QAED,IAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAC/D,IACE,UAAU;YACV,iBAAiB;YACjB,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAC1C;YACA,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,+DAAwB,GAAhC,UACE,uBAAgD;QAEhD,IAAM,OAAO,GAAqB,EAAE,CAAC;QACrC,uBAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;YACjD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE;gBACtD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CACzC,UAAA,gBAAgB,IAAI,OAAA,gBAAgB,CAAC,IAAI,EAArB,CAAqB,CAC1C,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;IACH,mCAAC;AAAD,CAAC,AA3ED,IA2EC;AA3EY,oEAA4B"}
|
||||
3
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.d.ts
generated
vendored
Normal file
3
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const query: any;
|
||||
export default query;
|
||||
//# sourceMappingURL=fragmentMatcherIntrospectionQuery.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcherIntrospectionQuery.d.ts","sourceRoot":"","sources":["src/fragmentMatcherIntrospectionQuery.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,KAAK,EAAE,GA8FZ,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
||||
99
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.js
generated
vendored
Normal file
99
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var query = {
|
||||
kind: 'Document',
|
||||
definitions: [
|
||||
{
|
||||
kind: 'OperationDefinition',
|
||||
operation: 'query',
|
||||
name: null,
|
||||
variableDefinitions: null,
|
||||
directives: [],
|
||||
selectionSet: {
|
||||
kind: 'SelectionSet',
|
||||
selections: [
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: '__schema',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: {
|
||||
kind: 'SelectionSet',
|
||||
selections: [
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: 'types',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: {
|
||||
kind: 'SelectionSet',
|
||||
selections: [
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: 'kind',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null,
|
||||
},
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: 'name',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null,
|
||||
},
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: 'possibleTypes',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: {
|
||||
kind: 'SelectionSet',
|
||||
selections: [
|
||||
{
|
||||
kind: 'Field',
|
||||
alias: null,
|
||||
name: {
|
||||
kind: 'Name',
|
||||
value: 'name',
|
||||
},
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
exports.default = query;
|
||||
//# sourceMappingURL=fragmentMatcherIntrospectionQuery.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/fragmentMatcherIntrospectionQuery.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fragmentMatcherIntrospectionQuery.js","sourceRoot":"","sources":["../src/fragmentMatcherIntrospectionQuery.ts"],"names":[],"mappings":";;AAAA,IAAM,KAAK,GAAQ;IACjB,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE;QACX;YACE,IAAI,EAAE,qBAAqB;YAC3B,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,IAAI;YACV,mBAAmB,EAAE,IAAI;YACzB,UAAU,EAAE,EAAE;YACd,YAAY,EAAE;gBACZ,IAAI,EAAE,cAAc;gBACpB,UAAU,EAAE;oBACV;wBACE,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,IAAI;wBACX,IAAI,EAAE;4BACJ,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,UAAU;yBAClB;wBACD,SAAS,EAAE,EAAE;wBACb,UAAU,EAAE,EAAE;wBACd,YAAY,EAAE;4BACZ,IAAI,EAAE,cAAc;4BACpB,UAAU,EAAE;gCACV;oCACE,IAAI,EAAE,OAAO;oCACb,KAAK,EAAE,IAAI;oCACX,IAAI,EAAE;wCACJ,IAAI,EAAE,MAAM;wCACZ,KAAK,EAAE,OAAO;qCACf;oCACD,SAAS,EAAE,EAAE;oCACb,UAAU,EAAE,EAAE;oCACd,YAAY,EAAE;wCACZ,IAAI,EAAE,cAAc;wCACpB,UAAU,EAAE;4CACV;gDACE,IAAI,EAAE,OAAO;gDACb,KAAK,EAAE,IAAI;gDACX,IAAI,EAAE;oDACJ,IAAI,EAAE,MAAM;oDACZ,KAAK,EAAE,MAAM;iDACd;gDACD,SAAS,EAAE,EAAE;gDACb,UAAU,EAAE,EAAE;gDACd,YAAY,EAAE,IAAI;6CACnB;4CACD;gDACE,IAAI,EAAE,OAAO;gDACb,KAAK,EAAE,IAAI;gDACX,IAAI,EAAE;oDACJ,IAAI,EAAE,MAAM;oDACZ,KAAK,EAAE,MAAM;iDACd;gDACD,SAAS,EAAE,EAAE;gDACb,UAAU,EAAE,EAAE;gDACd,YAAY,EAAE,IAAI;6CACnB;4CACD;gDACE,IAAI,EAAE,OAAO;gDACb,KAAK,EAAE,IAAI;gDACX,IAAI,EAAE;oDACJ,IAAI,EAAE,MAAM;oDACZ,KAAK,EAAE,eAAe;iDACvB;gDACD,SAAS,EAAE,EAAE;gDACb,UAAU,EAAE,EAAE;gDACd,YAAY,EAAE;oDACZ,IAAI,EAAE,cAAc;oDACpB,UAAU,EAAE;wDACV;4DACE,IAAI,EAAE,OAAO;4DACb,KAAK,EAAE,IAAI;4DACX,IAAI,EAAE;gEACJ,IAAI,EAAE,MAAM;gEACZ,KAAK,EAAE,MAAM;6DACd;4DACD,SAAS,EAAE,EAAE;4DACb,UAAU,EAAE,EAAE;4DACd,YAAY,EAAE,IAAI;yDACnB;qDACF;iDACF;6CACF;yCACF;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
||||
46
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts
generated
vendored
Normal file
46
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import './fixPolyfills';
|
||||
import { DocumentNode } from 'graphql';
|
||||
import { Cache, ApolloCache, Transaction } from 'apollo-cache';
|
||||
import { ApolloReducerConfig, NormalizedCache, NormalizedCacheObject } from './types';
|
||||
import { ObjectCache } from './objectCache';
|
||||
export interface InMemoryCacheConfig extends ApolloReducerConfig {
|
||||
resultCaching?: boolean;
|
||||
freezeResults?: boolean;
|
||||
}
|
||||
export declare function defaultDataIdFromObject(result: any): string | null;
|
||||
export declare class OptimisticCacheLayer extends ObjectCache {
|
||||
readonly optimisticId: string;
|
||||
readonly parent: NormalizedCache;
|
||||
readonly transaction: Transaction<NormalizedCacheObject>;
|
||||
constructor(optimisticId: string, parent: NormalizedCache, transaction: Transaction<NormalizedCacheObject>);
|
||||
toObject(): NormalizedCacheObject;
|
||||
get(dataId: string): import("./types").StoreObject;
|
||||
}
|
||||
export declare class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
|
||||
private data;
|
||||
private optimisticData;
|
||||
protected config: InMemoryCacheConfig;
|
||||
private watches;
|
||||
private addTypename;
|
||||
private typenameDocumentCache;
|
||||
private storeReader;
|
||||
private storeWriter;
|
||||
private cacheKeyRoot;
|
||||
private silenceBroadcast;
|
||||
constructor(config?: InMemoryCacheConfig);
|
||||
restore(data: NormalizedCacheObject): this;
|
||||
extract(optimistic?: boolean): NormalizedCacheObject;
|
||||
read<T>(options: Cache.ReadOptions): T | null;
|
||||
write(write: Cache.WriteOptions): void;
|
||||
diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;
|
||||
watch(watch: Cache.WatchOptions): () => void;
|
||||
evict(query: Cache.EvictOptions): Cache.EvictionResult;
|
||||
reset(): Promise<void>;
|
||||
removeOptimistic(idToRemove: string): void;
|
||||
performTransaction(transaction: Transaction<NormalizedCacheObject>, optimisticId?: string): void;
|
||||
recordOptimisticTransaction(transaction: Transaction<NormalizedCacheObject>, id: string): void;
|
||||
transformDocument(document: DocumentNode): DocumentNode;
|
||||
protected broadcastWatches(): void;
|
||||
private maybeBroadcastWatch;
|
||||
}
|
||||
//# sourceMappingURL=inMemoryCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"inMemoryCache.d.ts","sourceRoot":"","sources":["src/inMemoryCache.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAS/D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAUD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CAUlE;AAID,qBAAa,oBAAqB,SAAQ,WAAW;aAEjC,YAAY,EAAE,MAAM;aAGpB,MAAM,EAAE,eAAe;aACvB,WAAW,EAAE,WAAW,CAAC,qBAAqB,CAAC;gBAJ/C,YAAY,EAAE,MAAM,EAGpB,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,CAAC,qBAAqB,CAAC;IAK1D,QAAQ,IAAI,qBAAqB;IAUjC,GAAG,CAAC,MAAM,EAAE,MAAM;CAK1B;AAED,qBAAa,aAAc,SAAQ,WAAW,CAAC,qBAAqB,CAAC;IACnE,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,cAAc,CAAkB;IAExC,SAAS,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,qBAAqB,CAAyC;IACtE,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAsC;IAI1D,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,MAAM,GAAE,mBAAwB;IAyErC,OAAO,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAK1C,OAAO,CAAC,UAAU,GAAE,OAAe,GAAG,qBAAqB;IAI3D,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI;IAoB7C,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI;IAiBtC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAetD,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,MAAM,IAAI;IAQ5C,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,cAAc;IAItD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,gBAAgB,CAAC,UAAU,EAAE,MAAM;IA6BnC,kBAAkB,CACvB,WAAW,EAAE,WAAW,CAAC,qBAAqB,CAAC,EAI/C,YAAY,CAAC,EAAE,MAAM;IA6BhB,2BAA2B,CAChC,WAAW,EAAE,WAAW,CAAC,qBAAqB,CAAC,EAC/C,EAAE,EAAE,MAAM;IAKL,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY;IAgB9D,SAAS,CAAC,gBAAgB;IAQ1B,OAAO,CAAC,mBAAmB;CAU5B"}
|
||||
239
node_modules/apollo-cache-inmemory/lib/inMemoryCache.js
generated
vendored
Normal file
239
node_modules/apollo-cache-inmemory/lib/inMemoryCache.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
require("./fixPolyfills");
|
||||
var apollo_cache_1 = require("apollo-cache");
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var optimism_1 = require("optimism");
|
||||
var ts_invariant_1 = require("ts-invariant");
|
||||
var fragmentMatcher_1 = require("./fragmentMatcher");
|
||||
var readFromStore_1 = require("./readFromStore");
|
||||
var writeToStore_1 = require("./writeToStore");
|
||||
var depTrackingCache_1 = require("./depTrackingCache");
|
||||
var optimism_2 = require("optimism");
|
||||
var objectCache_1 = require("./objectCache");
|
||||
var defaultConfig = {
|
||||
fragmentMatcher: new fragmentMatcher_1.HeuristicFragmentMatcher(),
|
||||
dataIdFromObject: defaultDataIdFromObject,
|
||||
addTypename: true,
|
||||
resultCaching: true,
|
||||
freezeResults: false,
|
||||
};
|
||||
function defaultDataIdFromObject(result) {
|
||||
if (result.__typename) {
|
||||
if (result.id !== undefined) {
|
||||
return result.__typename + ":" + result.id;
|
||||
}
|
||||
if (result._id !== undefined) {
|
||||
return result.__typename + ":" + result._id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
exports.defaultDataIdFromObject = defaultDataIdFromObject;
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var OptimisticCacheLayer = (function (_super) {
|
||||
tslib_1.__extends(OptimisticCacheLayer, _super);
|
||||
function OptimisticCacheLayer(optimisticId, parent, transaction) {
|
||||
var _this = _super.call(this, Object.create(null)) || this;
|
||||
_this.optimisticId = optimisticId;
|
||||
_this.parent = parent;
|
||||
_this.transaction = transaction;
|
||||
return _this;
|
||||
}
|
||||
OptimisticCacheLayer.prototype.toObject = function () {
|
||||
return tslib_1.__assign(tslib_1.__assign({}, this.parent.toObject()), this.data);
|
||||
};
|
||||
OptimisticCacheLayer.prototype.get = function (dataId) {
|
||||
return hasOwn.call(this.data, dataId)
|
||||
? this.data[dataId]
|
||||
: this.parent.get(dataId);
|
||||
};
|
||||
return OptimisticCacheLayer;
|
||||
}(objectCache_1.ObjectCache));
|
||||
exports.OptimisticCacheLayer = OptimisticCacheLayer;
|
||||
var InMemoryCache = (function (_super) {
|
||||
tslib_1.__extends(InMemoryCache, _super);
|
||||
function InMemoryCache(config) {
|
||||
if (config === void 0) { config = {}; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.watches = new Set();
|
||||
_this.typenameDocumentCache = new Map();
|
||||
_this.cacheKeyRoot = new optimism_2.KeyTrie(apollo_utilities_1.canUseWeakMap);
|
||||
_this.silenceBroadcast = false;
|
||||
_this.config = tslib_1.__assign(tslib_1.__assign({}, defaultConfig), config);
|
||||
if (_this.config.customResolvers) {
|
||||
ts_invariant_1.invariant.warn('customResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating customResolvers in the next major version.');
|
||||
_this.config.cacheRedirects = _this.config.customResolvers;
|
||||
}
|
||||
if (_this.config.cacheResolvers) {
|
||||
ts_invariant_1.invariant.warn('cacheResolvers have been renamed to cacheRedirects. Please update your config as we will be deprecating cacheResolvers in the next major version.');
|
||||
_this.config.cacheRedirects = _this.config.cacheResolvers;
|
||||
}
|
||||
_this.addTypename = !!_this.config.addTypename;
|
||||
_this.data = _this.config.resultCaching
|
||||
? new depTrackingCache_1.DepTrackingCache()
|
||||
: new objectCache_1.ObjectCache();
|
||||
_this.optimisticData = _this.data;
|
||||
_this.storeWriter = new writeToStore_1.StoreWriter();
|
||||
_this.storeReader = new readFromStore_1.StoreReader({
|
||||
cacheKeyRoot: _this.cacheKeyRoot,
|
||||
freezeResults: config.freezeResults,
|
||||
});
|
||||
var cache = _this;
|
||||
var maybeBroadcastWatch = cache.maybeBroadcastWatch;
|
||||
_this.maybeBroadcastWatch = optimism_1.wrap(function (c) {
|
||||
return maybeBroadcastWatch.call(_this, c);
|
||||
}, {
|
||||
makeCacheKey: function (c) {
|
||||
if (c.optimistic) {
|
||||
return;
|
||||
}
|
||||
if (c.previousResult) {
|
||||
return;
|
||||
}
|
||||
if (cache.data instanceof depTrackingCache_1.DepTrackingCache) {
|
||||
return cache.cacheKeyRoot.lookup(c.query, JSON.stringify(c.variables));
|
||||
}
|
||||
}
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
InMemoryCache.prototype.restore = function (data) {
|
||||
if (data)
|
||||
this.data.replace(data);
|
||||
return this;
|
||||
};
|
||||
InMemoryCache.prototype.extract = function (optimistic) {
|
||||
if (optimistic === void 0) { optimistic = false; }
|
||||
return (optimistic ? this.optimisticData : this.data).toObject();
|
||||
};
|
||||
InMemoryCache.prototype.read = function (options) {
|
||||
if (typeof options.rootId === 'string' &&
|
||||
typeof this.data.get(options.rootId) === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
return this.storeReader.readQueryFromStore({
|
||||
store: options.optimistic ? this.optimisticData : this.data,
|
||||
query: this.transformDocument(options.query),
|
||||
variables: options.variables,
|
||||
rootId: options.rootId,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
previousResult: options.previousResult,
|
||||
config: this.config,
|
||||
}) || null;
|
||||
};
|
||||
InMemoryCache.prototype.write = function (write) {
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
this.storeWriter.writeResultToStore({
|
||||
dataId: write.dataId,
|
||||
result: write.result,
|
||||
variables: write.variables,
|
||||
document: this.transformDocument(write.query),
|
||||
store: this.data,
|
||||
dataIdFromObject: this.config.dataIdFromObject,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
});
|
||||
this.broadcastWatches();
|
||||
};
|
||||
InMemoryCache.prototype.diff = function (query) {
|
||||
var fragmentMatcher = this.config.fragmentMatcher;
|
||||
var fragmentMatcherFunction = fragmentMatcher && fragmentMatcher.match;
|
||||
return this.storeReader.diffQueryAgainstStore({
|
||||
store: query.optimistic ? this.optimisticData : this.data,
|
||||
query: this.transformDocument(query.query),
|
||||
variables: query.variables,
|
||||
returnPartialData: query.returnPartialData,
|
||||
previousResult: query.previousResult,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
config: this.config,
|
||||
});
|
||||
};
|
||||
InMemoryCache.prototype.watch = function (watch) {
|
||||
var _this = this;
|
||||
this.watches.add(watch);
|
||||
return function () {
|
||||
_this.watches.delete(watch);
|
||||
};
|
||||
};
|
||||
InMemoryCache.prototype.evict = function (query) {
|
||||
throw new ts_invariant_1.InvariantError("eviction is not implemented on InMemory Cache");
|
||||
};
|
||||
InMemoryCache.prototype.reset = function () {
|
||||
this.data.clear();
|
||||
this.broadcastWatches();
|
||||
return Promise.resolve();
|
||||
};
|
||||
InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
|
||||
var toReapply = [];
|
||||
var removedCount = 0;
|
||||
var layer = this.optimisticData;
|
||||
while (layer instanceof OptimisticCacheLayer) {
|
||||
if (layer.optimisticId === idToRemove) {
|
||||
++removedCount;
|
||||
}
|
||||
else {
|
||||
toReapply.push(layer);
|
||||
}
|
||||
layer = layer.parent;
|
||||
}
|
||||
if (removedCount > 0) {
|
||||
this.optimisticData = layer;
|
||||
while (toReapply.length > 0) {
|
||||
var layer_1 = toReapply.pop();
|
||||
this.performTransaction(layer_1.transaction, layer_1.optimisticId);
|
||||
}
|
||||
this.broadcastWatches();
|
||||
}
|
||||
};
|
||||
InMemoryCache.prototype.performTransaction = function (transaction, optimisticId) {
|
||||
var _a = this, data = _a.data, silenceBroadcast = _a.silenceBroadcast;
|
||||
this.silenceBroadcast = true;
|
||||
if (typeof optimisticId === 'string') {
|
||||
this.data = this.optimisticData = new OptimisticCacheLayer(optimisticId, this.optimisticData, transaction);
|
||||
}
|
||||
try {
|
||||
transaction(this);
|
||||
}
|
||||
finally {
|
||||
this.silenceBroadcast = silenceBroadcast;
|
||||
this.data = data;
|
||||
}
|
||||
this.broadcastWatches();
|
||||
};
|
||||
InMemoryCache.prototype.recordOptimisticTransaction = function (transaction, id) {
|
||||
return this.performTransaction(transaction, id);
|
||||
};
|
||||
InMemoryCache.prototype.transformDocument = function (document) {
|
||||
if (this.addTypename) {
|
||||
var result = this.typenameDocumentCache.get(document);
|
||||
if (!result) {
|
||||
result = apollo_utilities_1.addTypenameToDocument(document);
|
||||
this.typenameDocumentCache.set(document, result);
|
||||
this.typenameDocumentCache.set(result, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return document;
|
||||
};
|
||||
InMemoryCache.prototype.broadcastWatches = function () {
|
||||
var _this = this;
|
||||
if (!this.silenceBroadcast) {
|
||||
this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c); });
|
||||
}
|
||||
};
|
||||
InMemoryCache.prototype.maybeBroadcastWatch = function (c) {
|
||||
c.callback(this.diff({
|
||||
query: c.query,
|
||||
variables: c.variables,
|
||||
previousResult: c.previousResult && c.previousResult(),
|
||||
optimistic: c.optimistic,
|
||||
}));
|
||||
};
|
||||
return InMemoryCache;
|
||||
}(apollo_cache_1.ApolloCache));
|
||||
exports.InMemoryCache = InMemoryCache;
|
||||
//# sourceMappingURL=inMemoryCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/inMemoryCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/inMemoryCache.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
7
node_modules/apollo-cache-inmemory/lib/index.d.ts
generated
vendored
Normal file
7
node_modules/apollo-cache-inmemory/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export { InMemoryCache, InMemoryCacheConfig, defaultDataIdFromObject, } from './inMemoryCache';
|
||||
export * from './readFromStore';
|
||||
export * from './writeToStore';
|
||||
export * from './fragmentMatcher';
|
||||
export * from './objectCache';
|
||||
export * from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/index.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
||||
11
node_modules/apollo-cache-inmemory/lib/index.js
generated
vendored
Normal file
11
node_modules/apollo-cache-inmemory/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var inMemoryCache_1 = require("./inMemoryCache");
|
||||
exports.InMemoryCache = inMemoryCache_1.InMemoryCache;
|
||||
exports.defaultDataIdFromObject = inMemoryCache_1.defaultDataIdFromObject;
|
||||
tslib_1.__exportStar(require("./readFromStore"), exports);
|
||||
tslib_1.__exportStar(require("./writeToStore"), exports);
|
||||
tslib_1.__exportStar(require("./fragmentMatcher"), exports);
|
||||
tslib_1.__exportStar(require("./objectCache"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/index.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAIyB;AAHvB,wCAAA,aAAa,CAAA;AAEb,kDAAA,uBAAuB,CAAA;AAGzB,0DAAgC;AAChC,yDAA+B;AAC/B,4DAAkC;AAClC,wDAA8B"}
|
||||
13
node_modules/apollo-cache-inmemory/lib/mapCache.d.ts
generated
vendored
Normal file
13
node_modules/apollo-cache-inmemory/lib/mapCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
|
||||
export declare class MapCache implements NormalizedCache {
|
||||
private cache;
|
||||
constructor(data?: NormalizedCacheObject);
|
||||
get(dataId: string): StoreObject;
|
||||
set(dataId: string, value: StoreObject): void;
|
||||
delete(dataId: string): void;
|
||||
clear(): void;
|
||||
toObject(): NormalizedCacheObject;
|
||||
replace(newData: NormalizedCacheObject): void;
|
||||
}
|
||||
export declare function mapNormalizedCacheFactory(seed?: NormalizedCacheObject): NormalizedCache;
|
||||
//# sourceMappingURL=mapCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/mapCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/mapCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mapCache.d.ts","sourceRoot":"","sources":["src/mapCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM9E,qBAAa,QAAS,YAAW,eAAe;IAC9C,OAAO,CAAC,KAAK,CAAuC;gBAExC,IAAI,GAAE,qBAA0B;IAIrC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;IAIhC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI;IAI7C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI5B,KAAK,IAAI,IAAI;IAIb,QAAQ,IAAI,qBAAqB;IAQjC,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;CAMrD;AAED,wBAAgB,yBAAyB,CACvC,IAAI,CAAC,EAAE,qBAAqB,GAC3B,eAAe,CAEjB"}
|
||||
42
node_modules/apollo-cache-inmemory/lib/mapCache.js
generated
vendored
Normal file
42
node_modules/apollo-cache-inmemory/lib/mapCache.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var MapCache = (function () {
|
||||
function MapCache(data) {
|
||||
if (data === void 0) { data = {}; }
|
||||
this.cache = new Map(Object.entries(data));
|
||||
}
|
||||
MapCache.prototype.get = function (dataId) {
|
||||
return this.cache.get("" + dataId);
|
||||
};
|
||||
MapCache.prototype.set = function (dataId, value) {
|
||||
this.cache.set("" + dataId, value);
|
||||
};
|
||||
MapCache.prototype.delete = function (dataId) {
|
||||
this.cache.delete("" + dataId);
|
||||
};
|
||||
MapCache.prototype.clear = function () {
|
||||
return this.cache.clear();
|
||||
};
|
||||
MapCache.prototype.toObject = function () {
|
||||
var obj = {};
|
||||
this.cache.forEach(function (dataId, key) {
|
||||
obj[key] = dataId;
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
MapCache.prototype.replace = function (newData) {
|
||||
var _this = this;
|
||||
this.cache.clear();
|
||||
Object.entries(newData).forEach(function (_a) {
|
||||
var dataId = _a[0], value = _a[1];
|
||||
return _this.cache.set(dataId, value);
|
||||
});
|
||||
};
|
||||
return MapCache;
|
||||
}());
|
||||
exports.MapCache = MapCache;
|
||||
function mapNormalizedCacheFactory(seed) {
|
||||
return new MapCache(seed);
|
||||
}
|
||||
exports.mapNormalizedCacheFactory = mapNormalizedCacheFactory;
|
||||
//# sourceMappingURL=mapCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/mapCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/mapCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mapCache.js","sourceRoot":"","sources":["../src/mapCache.ts"],"names":[],"mappings":";;AAMA;IAGE,kBAAY,IAAgC;QAAhC,qBAAA,EAAA,SAAgC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAEM,sBAAG,GAAV,UAAW,MAAc;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAG,MAAQ,CAAE,CAAC;IACtC,CAAC;IAEM,sBAAG,GAAV,UAAW,MAAc,EAAE,KAAkB;QAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAG,MAAQ,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAEM,yBAAM,GAAb,UAAc,MAAc;QAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAG,MAAQ,CAAC,CAAC;IACjC,CAAC;IAEM,wBAAK,GAAZ;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAEM,2BAAQ,GAAf;QACE,IAAM,GAAG,GAA0B,EAAE,CAAC;QACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,MAAM,EAAE,GAAG;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACpB,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,0BAAO,GAAd,UAAe,OAA8B;QAA7C,iBAKC;QAJC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,EAAe;gBAAd,cAAM,EAAE,aAAK;YAC7C,OAAA,KAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;QAA7B,CAA6B,CAC9B,CAAC;IACJ,CAAC;IACH,eAAC;AAAD,CAAC,AArCD,IAqCC;AArCY,4BAAQ;AAuCrB,SAAgB,yBAAyB,CACvC,IAA4B;IAE5B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAJD,8DAIC"}
|
||||
13
node_modules/apollo-cache-inmemory/lib/objectCache.d.ts
generated
vendored
Normal file
13
node_modules/apollo-cache-inmemory/lib/objectCache.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
|
||||
export declare class ObjectCache implements NormalizedCache {
|
||||
protected data: NormalizedCacheObject;
|
||||
constructor(data?: NormalizedCacheObject);
|
||||
toObject(): NormalizedCacheObject;
|
||||
get(dataId: string): StoreObject;
|
||||
set(dataId: string, value: StoreObject): void;
|
||||
delete(dataId: string): void;
|
||||
clear(): void;
|
||||
replace(newData: NormalizedCacheObject): void;
|
||||
}
|
||||
export declare function defaultNormalizedCacheFactory(seed?: NormalizedCacheObject): NormalizedCache;
|
||||
//# sourceMappingURL=objectCache.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/objectCache.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/objectCache.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"objectCache.d.ts","sourceRoot":"","sources":["src/objectCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE9E,qBAAa,WAAY,YAAW,eAAe;IACrC,SAAS,CAAC,IAAI,EAAE,qBAAqB;gBAA3B,IAAI,GAAE,qBAA2C;IAEhE,QAAQ;IAIR,GAAG,CAAC,MAAM,EAAE,MAAM;IAIlB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAItC,MAAM,CAAC,MAAM,EAAE,MAAM;IAIrB,KAAK;IAIL,OAAO,CAAC,OAAO,EAAE,qBAAqB;CAG9C;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,CAAC,EAAE,qBAAqB,GAC3B,eAAe,CAEjB"}
|
||||
33
node_modules/apollo-cache-inmemory/lib/objectCache.js
generated
vendored
Normal file
33
node_modules/apollo-cache-inmemory/lib/objectCache.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ObjectCache = (function () {
|
||||
function ObjectCache(data) {
|
||||
if (data === void 0) { data = Object.create(null); }
|
||||
this.data = data;
|
||||
}
|
||||
ObjectCache.prototype.toObject = function () {
|
||||
return this.data;
|
||||
};
|
||||
ObjectCache.prototype.get = function (dataId) {
|
||||
return this.data[dataId];
|
||||
};
|
||||
ObjectCache.prototype.set = function (dataId, value) {
|
||||
this.data[dataId] = value;
|
||||
};
|
||||
ObjectCache.prototype.delete = function (dataId) {
|
||||
this.data[dataId] = void 0;
|
||||
};
|
||||
ObjectCache.prototype.clear = function () {
|
||||
this.data = Object.create(null);
|
||||
};
|
||||
ObjectCache.prototype.replace = function (newData) {
|
||||
this.data = newData || Object.create(null);
|
||||
};
|
||||
return ObjectCache;
|
||||
}());
|
||||
exports.ObjectCache = ObjectCache;
|
||||
function defaultNormalizedCacheFactory(seed) {
|
||||
return new ObjectCache(seed);
|
||||
}
|
||||
exports.defaultNormalizedCacheFactory = defaultNormalizedCacheFactory;
|
||||
//# sourceMappingURL=objectCache.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/objectCache.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/objectCache.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"objectCache.js","sourceRoot":"","sources":["../src/objectCache.ts"],"names":[],"mappings":";;AAEA;IACE,qBAAsB,IAAiD;QAAjD,qBAAA,EAAA,OAA8B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAAjD,SAAI,GAAJ,IAAI,CAA6C;IAAG,CAAC;IAEpE,8BAAQ,GAAf;QACE,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEM,yBAAG,GAAV,UAAW,MAAc;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC;IAC5B,CAAC;IAEM,yBAAG,GAAV,UAAW,MAAc,EAAE,KAAkB;QAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAEM,4BAAM,GAAb,UAAc,MAAc;QAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;IAC7B,CAAC;IAEM,2BAAK,GAAZ;QACE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,6BAAO,GAAd,UAAe,OAA8B;QAC3C,IAAI,CAAC,IAAI,GAAG,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IACH,kBAAC;AAAD,CAAC,AA1BD,IA0BC;AA1BY,kCAAW;AA4BxB,SAAgB,6BAA6B,CAC3C,IAA4B;IAE5B,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAJD,sEAIC"}
|
||||
34
node_modules/apollo-cache-inmemory/lib/readFromStore.d.ts
generated
vendored
Normal file
34
node_modules/apollo-cache-inmemory/lib/readFromStore.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { IdValue } from 'apollo-utilities';
|
||||
import { Cache } from 'apollo-cache';
|
||||
import { ReadStoreContext, DiffQueryAgainstStoreOptions, ReadQueryOptions, StoreObject } from './types';
|
||||
import { KeyTrie } from 'optimism';
|
||||
export declare type VariableMap = {
|
||||
[name: string]: any;
|
||||
};
|
||||
export declare type FragmentMatcher = (rootValue: any, typeCondition: string, context: ReadStoreContext) => boolean | 'heuristic';
|
||||
export declare type ExecResultMissingField = {
|
||||
object: StoreObject;
|
||||
fieldName: string;
|
||||
tolerable: boolean;
|
||||
};
|
||||
export declare type ExecResult<R = any> = {
|
||||
result: R;
|
||||
missing?: ExecResultMissingField[];
|
||||
};
|
||||
export interface StoreReaderConfig {
|
||||
cacheKeyRoot?: KeyTrie<object>;
|
||||
freezeResults?: boolean;
|
||||
}
|
||||
export declare class StoreReader {
|
||||
private freezeResults;
|
||||
constructor({ cacheKeyRoot, freezeResults, }?: StoreReaderConfig);
|
||||
readQueryFromStore<QueryType>(options: ReadQueryOptions): QueryType | undefined;
|
||||
diffQueryAgainstStore<T>({ store, query, variables, previousResult, returnPartialData, rootId, fragmentMatcherFunction, config, }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T>;
|
||||
private executeStoreQuery;
|
||||
private executeSelectionSet;
|
||||
private executeField;
|
||||
private combineExecResults;
|
||||
private executeSubSelectedArray;
|
||||
}
|
||||
export declare function assertIdValue(idValue: IdValue): void;
|
||||
//# sourceMappingURL=readFromStore.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/readFromStore.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/readFromStore.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"readFromStore.d.ts","sourceRoot":"","sources":["src/readFromStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAaL,OAAO,EAYR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;AAUjB,OAAO,EAAQ,OAAO,EAAE,MAAM,UAAU,CAAC;AAIzC,oBAAY,WAAW,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAElD,oBAAY,eAAe,GAAG,CAC5B,SAAS,EAAE,GAAG,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,KACtB,OAAO,GAAG,WAAW,CAAC;AAe3B,oBAAY,sBAAsB,GAAG;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,oBAAY,UAAU,CAAC,CAAC,GAAG,GAAG,IAAI;IAChC,MAAM,EAAE,CAAC,CAAC;IAEV,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACpC,CAAC;AAuBF,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,aAAa,CAAU;gBAEnB,EACV,YAAiD,EACjD,aAAqB,GACtB,GAAE,iBAAsB;IAqFlB,kBAAkB,CAAC,SAAS,EACjC,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS;IAejB,qBAAqB,CAAC,CAAC,EAAE,EAC9B,KAAK,EACL,KAAK,EACL,SAAS,EACT,cAAc,EACd,iBAAwB,EACxB,MAAqB,EACrB,uBAAuB,EACvB,MAAM,GACP,EAAE,4BAA4B,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAwErD,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,mBAAmB;IA+F3B,OAAO,CAAC,YAAY;IA8DpB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,uBAAuB;CAmDhC;AAmBD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QAK7C"}
|
||||
318
node_modules/apollo-cache-inmemory/lib/readFromStore.js
generated
vendored
Normal file
318
node_modules/apollo-cache-inmemory/lib/readFromStore.js
generated
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var optimism_1 = require("optimism");
|
||||
var depTrackingCache_1 = require("./depTrackingCache");
|
||||
var ts_invariant_1 = require("ts-invariant");
|
||||
var StoreReader = (function () {
|
||||
function StoreReader(_a) {
|
||||
var _this = this;
|
||||
var _b = _a === void 0 ? {} : _a, _c = _b.cacheKeyRoot, cacheKeyRoot = _c === void 0 ? new optimism_1.KeyTrie(apollo_utilities_1.canUseWeakMap) : _c, _d = _b.freezeResults, freezeResults = _d === void 0 ? false : _d;
|
||||
var _e = this, executeStoreQuery = _e.executeStoreQuery, executeSelectionSet = _e.executeSelectionSet, executeSubSelectedArray = _e.executeSubSelectedArray;
|
||||
this.freezeResults = freezeResults;
|
||||
this.executeStoreQuery = optimism_1.wrap(function (options) {
|
||||
return executeStoreQuery.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, fragmentMatcher = _a.fragmentMatcher;
|
||||
if (contextValue.store instanceof depTrackingCache_1.DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(contextValue.store, query, fragmentMatcher, JSON.stringify(variableValues), rootValue.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.executeSelectionSet = optimism_1.wrap(function (options) {
|
||||
return executeSelectionSet.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
||||
if (execContext.contextValue.store instanceof depTrackingCache_1.DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(execContext.contextValue.store, selectionSet, execContext.fragmentMatcher, JSON.stringify(execContext.variableValues), rootValue.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.executeSubSelectedArray = optimism_1.wrap(function (options) {
|
||||
return executeSubSelectedArray.call(_this, options);
|
||||
}, {
|
||||
makeCacheKey: function (_a) {
|
||||
var field = _a.field, array = _a.array, execContext = _a.execContext;
|
||||
if (execContext.contextValue.store instanceof depTrackingCache_1.DepTrackingCache) {
|
||||
return cacheKeyRoot.lookup(execContext.contextValue.store, field, array, JSON.stringify(execContext.variableValues));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
StoreReader.prototype.readQueryFromStore = function (options) {
|
||||
return this.diffQueryAgainstStore(tslib_1.__assign(tslib_1.__assign({}, options), { returnPartialData: false })).result;
|
||||
};
|
||||
StoreReader.prototype.diffQueryAgainstStore = function (_a) {
|
||||
var store = _a.store, query = _a.query, variables = _a.variables, previousResult = _a.previousResult, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, fragmentMatcherFunction = _a.fragmentMatcherFunction, config = _a.config;
|
||||
var queryDefinition = apollo_utilities_1.getQueryDefinition(query);
|
||||
variables = apollo_utilities_1.assign({}, apollo_utilities_1.getDefaultValues(queryDefinition), variables);
|
||||
var context = {
|
||||
store: store,
|
||||
dataIdFromObject: config && config.dataIdFromObject,
|
||||
cacheRedirects: (config && config.cacheRedirects) || {},
|
||||
};
|
||||
var execResult = this.executeStoreQuery({
|
||||
query: query,
|
||||
rootValue: {
|
||||
type: 'id',
|
||||
id: rootId,
|
||||
generated: true,
|
||||
typename: 'Query',
|
||||
},
|
||||
contextValue: context,
|
||||
variableValues: variables,
|
||||
fragmentMatcher: fragmentMatcherFunction,
|
||||
});
|
||||
var hasMissingFields = execResult.missing && execResult.missing.length > 0;
|
||||
if (hasMissingFields && !returnPartialData) {
|
||||
execResult.missing.forEach(function (info) {
|
||||
if (info.tolerable)
|
||||
return;
|
||||
throw new ts_invariant_1.InvariantError("Can't find field " + info.fieldName + " on object " + JSON.stringify(info.object, null, 2) + ".");
|
||||
});
|
||||
}
|
||||
if (previousResult) {
|
||||
if (apollo_utilities_1.isEqual(previousResult, execResult.result)) {
|
||||
execResult.result = previousResult;
|
||||
}
|
||||
}
|
||||
return {
|
||||
result: execResult.result,
|
||||
complete: !hasMissingFields,
|
||||
};
|
||||
};
|
||||
StoreReader.prototype.executeStoreQuery = function (_a) {
|
||||
var query = _a.query, rootValue = _a.rootValue, contextValue = _a.contextValue, variableValues = _a.variableValues, _b = _a.fragmentMatcher, fragmentMatcher = _b === void 0 ? defaultFragmentMatcher : _b;
|
||||
var mainDefinition = apollo_utilities_1.getMainDefinition(query);
|
||||
var fragments = apollo_utilities_1.getFragmentDefinitions(query);
|
||||
var fragmentMap = apollo_utilities_1.createFragmentMap(fragments);
|
||||
var execContext = {
|
||||
query: query,
|
||||
fragmentMap: fragmentMap,
|
||||
contextValue: contextValue,
|
||||
variableValues: variableValues,
|
||||
fragmentMatcher: fragmentMatcher,
|
||||
};
|
||||
return this.executeSelectionSet({
|
||||
selectionSet: mainDefinition.selectionSet,
|
||||
rootValue: rootValue,
|
||||
execContext: execContext,
|
||||
});
|
||||
};
|
||||
StoreReader.prototype.executeSelectionSet = function (_a) {
|
||||
var _this = this;
|
||||
var selectionSet = _a.selectionSet, rootValue = _a.rootValue, execContext = _a.execContext;
|
||||
var fragmentMap = execContext.fragmentMap, contextValue = execContext.contextValue, variables = execContext.variableValues;
|
||||
var finalResult = { result: null };
|
||||
var objectsToMerge = [];
|
||||
var object = contextValue.store.get(rootValue.id);
|
||||
var typename = (object && object.__typename) ||
|
||||
(rootValue.id === 'ROOT_QUERY' && 'Query') ||
|
||||
void 0;
|
||||
function handleMissing(result) {
|
||||
var _a;
|
||||
if (result.missing) {
|
||||
finalResult.missing = finalResult.missing || [];
|
||||
(_a = finalResult.missing).push.apply(_a, result.missing);
|
||||
}
|
||||
return result.result;
|
||||
}
|
||||
selectionSet.selections.forEach(function (selection) {
|
||||
var _a;
|
||||
if (!apollo_utilities_1.shouldInclude(selection, variables)) {
|
||||
return;
|
||||
}
|
||||
if (apollo_utilities_1.isField(selection)) {
|
||||
var fieldResult = handleMissing(_this.executeField(object, typename, selection, execContext));
|
||||
if (typeof fieldResult !== 'undefined') {
|
||||
objectsToMerge.push((_a = {},
|
||||
_a[apollo_utilities_1.resultKeyNameFromField(selection)] = fieldResult,
|
||||
_a));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var fragment = void 0;
|
||||
if (apollo_utilities_1.isInlineFragment(selection)) {
|
||||
fragment = selection;
|
||||
}
|
||||
else {
|
||||
fragment = fragmentMap[selection.name.value];
|
||||
if (!fragment) {
|
||||
throw new ts_invariant_1.InvariantError("No fragment named " + selection.name.value);
|
||||
}
|
||||
}
|
||||
var typeCondition = fragment.typeCondition && fragment.typeCondition.name.value;
|
||||
var match = !typeCondition ||
|
||||
execContext.fragmentMatcher(rootValue, typeCondition, contextValue);
|
||||
if (match) {
|
||||
var fragmentExecResult = _this.executeSelectionSet({
|
||||
selectionSet: fragment.selectionSet,
|
||||
rootValue: rootValue,
|
||||
execContext: execContext,
|
||||
});
|
||||
if (match === 'heuristic' && fragmentExecResult.missing) {
|
||||
fragmentExecResult = tslib_1.__assign(tslib_1.__assign({}, fragmentExecResult), { missing: fragmentExecResult.missing.map(function (info) {
|
||||
return tslib_1.__assign(tslib_1.__assign({}, info), { tolerable: true });
|
||||
}) });
|
||||
}
|
||||
objectsToMerge.push(handleMissing(fragmentExecResult));
|
||||
}
|
||||
}
|
||||
});
|
||||
finalResult.result = apollo_utilities_1.mergeDeepArray(objectsToMerge);
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(finalResult.result);
|
||||
}
|
||||
return finalResult;
|
||||
};
|
||||
StoreReader.prototype.executeField = function (object, typename, field, execContext) {
|
||||
var variables = execContext.variableValues, contextValue = execContext.contextValue;
|
||||
var fieldName = field.name.value;
|
||||
var args = apollo_utilities_1.argumentsObjectFromField(field, variables);
|
||||
var info = {
|
||||
resultKey: apollo_utilities_1.resultKeyNameFromField(field),
|
||||
directives: apollo_utilities_1.getDirectiveInfoFromField(field, variables),
|
||||
};
|
||||
var readStoreResult = readStoreResolver(object, typename, fieldName, args, contextValue, info);
|
||||
if (Array.isArray(readStoreResult.result)) {
|
||||
return this.combineExecResults(readStoreResult, this.executeSubSelectedArray({
|
||||
field: field,
|
||||
array: readStoreResult.result,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
if (!field.selectionSet) {
|
||||
assertSelectionSetForIdValue(field, readStoreResult.result);
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
apollo_utilities_1.maybeDeepFreeze(readStoreResult);
|
||||
}
|
||||
return readStoreResult;
|
||||
}
|
||||
if (readStoreResult.result == null) {
|
||||
return readStoreResult;
|
||||
}
|
||||
return this.combineExecResults(readStoreResult, this.executeSelectionSet({
|
||||
selectionSet: field.selectionSet,
|
||||
rootValue: readStoreResult.result,
|
||||
execContext: execContext,
|
||||
}));
|
||||
};
|
||||
StoreReader.prototype.combineExecResults = function () {
|
||||
var execResults = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
execResults[_i] = arguments[_i];
|
||||
}
|
||||
var missing;
|
||||
execResults.forEach(function (execResult) {
|
||||
if (execResult.missing) {
|
||||
missing = missing || [];
|
||||
missing.push.apply(missing, execResult.missing);
|
||||
}
|
||||
});
|
||||
return {
|
||||
result: execResults.pop().result,
|
||||
missing: missing,
|
||||
};
|
||||
};
|
||||
StoreReader.prototype.executeSubSelectedArray = function (_a) {
|
||||
var _this = this;
|
||||
var field = _a.field, array = _a.array, execContext = _a.execContext;
|
||||
var missing;
|
||||
function handleMissing(childResult) {
|
||||
if (childResult.missing) {
|
||||
missing = missing || [];
|
||||
missing.push.apply(missing, childResult.missing);
|
||||
}
|
||||
return childResult.result;
|
||||
}
|
||||
array = array.map(function (item) {
|
||||
if (item === null) {
|
||||
return null;
|
||||
}
|
||||
if (Array.isArray(item)) {
|
||||
return handleMissing(_this.executeSubSelectedArray({
|
||||
field: field,
|
||||
array: item,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
if (field.selectionSet) {
|
||||
return handleMissing(_this.executeSelectionSet({
|
||||
selectionSet: field.selectionSet,
|
||||
rootValue: item,
|
||||
execContext: execContext,
|
||||
}));
|
||||
}
|
||||
assertSelectionSetForIdValue(field, item);
|
||||
return item;
|
||||
});
|
||||
if (this.freezeResults && process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(array);
|
||||
}
|
||||
return { result: array, missing: missing };
|
||||
};
|
||||
return StoreReader;
|
||||
}());
|
||||
exports.StoreReader = StoreReader;
|
||||
function assertSelectionSetForIdValue(field, value) {
|
||||
if (!field.selectionSet && apollo_utilities_1.isIdValue(value)) {
|
||||
throw new ts_invariant_1.InvariantError("Missing selection set for object of type " + value.typename + " returned for query field " + field.name.value);
|
||||
}
|
||||
}
|
||||
function defaultFragmentMatcher() {
|
||||
return true;
|
||||
}
|
||||
function assertIdValue(idValue) {
|
||||
ts_invariant_1.invariant(apollo_utilities_1.isIdValue(idValue), "Encountered a sub-selection on the query, but the store doesn't have an object reference. This should never happen during normal use unless you have custom code that is directly manipulating the store; please file an issue.");
|
||||
}
|
||||
exports.assertIdValue = assertIdValue;
|
||||
function readStoreResolver(object, typename, fieldName, args, context, _a) {
|
||||
var resultKey = _a.resultKey, directives = _a.directives;
|
||||
var storeKeyName = fieldName;
|
||||
if (args || directives) {
|
||||
storeKeyName = apollo_utilities_1.getStoreKeyName(storeKeyName, args, directives);
|
||||
}
|
||||
var fieldValue = void 0;
|
||||
if (object) {
|
||||
fieldValue = object[storeKeyName];
|
||||
if (typeof fieldValue === 'undefined' &&
|
||||
context.cacheRedirects &&
|
||||
typeof typename === 'string') {
|
||||
var type = context.cacheRedirects[typename];
|
||||
if (type) {
|
||||
var resolver = type[fieldName];
|
||||
if (resolver) {
|
||||
fieldValue = resolver(object, args, {
|
||||
getCacheKey: function (storeObj) {
|
||||
var id = context.dataIdFromObject(storeObj);
|
||||
return id && apollo_utilities_1.toIdValue({
|
||||
id: id,
|
||||
typename: storeObj.__typename,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof fieldValue === 'undefined') {
|
||||
return {
|
||||
result: fieldValue,
|
||||
missing: [{
|
||||
object: object,
|
||||
fieldName: storeKeyName,
|
||||
tolerable: false,
|
||||
}],
|
||||
};
|
||||
}
|
||||
if (apollo_utilities_1.isJsonValue(fieldValue)) {
|
||||
fieldValue = fieldValue.json;
|
||||
}
|
||||
return {
|
||||
result: fieldValue,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=readFromStore.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/readFromStore.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/readFromStore.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
80
node_modules/apollo-cache-inmemory/lib/types.d.ts
generated
vendored
Normal file
80
node_modules/apollo-cache-inmemory/lib/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import { DocumentNode } from 'graphql';
|
||||
import { FragmentMatcher } from './readFromStore';
|
||||
import { Transaction } from 'apollo-cache';
|
||||
import { IdValue, StoreValue } from 'apollo-utilities';
|
||||
export interface IdGetterObj extends Object {
|
||||
__typename?: string;
|
||||
id?: string;
|
||||
}
|
||||
export declare type IdGetter = (value: IdGetterObj) => string | null | undefined;
|
||||
export interface NormalizedCache {
|
||||
get(dataId: string): StoreObject;
|
||||
set(dataId: string, value: StoreObject): void;
|
||||
delete(dataId: string): void;
|
||||
clear(): void;
|
||||
toObject(): NormalizedCacheObject;
|
||||
replace(newData: NormalizedCacheObject): void;
|
||||
}
|
||||
export interface NormalizedCacheObject {
|
||||
[dataId: string]: StoreObject | undefined;
|
||||
}
|
||||
export interface StoreObject {
|
||||
__typename?: string;
|
||||
[storeFieldKey: string]: StoreValue;
|
||||
}
|
||||
export declare type OptimisticStoreItem = {
|
||||
id: string;
|
||||
data: NormalizedCacheObject;
|
||||
transaction: Transaction<NormalizedCacheObject>;
|
||||
};
|
||||
export declare type ReadQueryOptions = {
|
||||
store: NormalizedCache;
|
||||
query: DocumentNode;
|
||||
fragmentMatcherFunction?: FragmentMatcher;
|
||||
variables?: Object;
|
||||
previousResult?: any;
|
||||
rootId?: string;
|
||||
config?: ApolloReducerConfig;
|
||||
};
|
||||
export declare type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
|
||||
returnPartialData?: boolean;
|
||||
};
|
||||
export declare type ApolloReducerConfig = {
|
||||
dataIdFromObject?: IdGetter;
|
||||
fragmentMatcher?: FragmentMatcherInterface;
|
||||
addTypename?: boolean;
|
||||
cacheRedirects?: CacheResolverMap;
|
||||
};
|
||||
export declare type ReadStoreContext = {
|
||||
readonly store: NormalizedCache;
|
||||
readonly cacheRedirects: CacheResolverMap;
|
||||
readonly dataIdFromObject?: IdGetter;
|
||||
};
|
||||
export interface FragmentMatcherInterface {
|
||||
match(idValue: IdValue, typeCondition: string, context: ReadStoreContext): boolean | 'heuristic';
|
||||
}
|
||||
export declare type PossibleTypesMap = {
|
||||
[key: string]: string[];
|
||||
};
|
||||
export declare type IntrospectionResultData = {
|
||||
__schema: {
|
||||
types: {
|
||||
kind: string;
|
||||
name: string;
|
||||
possibleTypes: {
|
||||
name: string;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
export declare type CacheResolver = (rootValue: any, args: {
|
||||
[argName: string]: any;
|
||||
}, context: any) => any;
|
||||
export declare type CacheResolverMap = {
|
||||
[typeName: string]: {
|
||||
[fieldName: string]: CacheResolver;
|
||||
};
|
||||
};
|
||||
export declare type CustomResolver = CacheResolver;
|
||||
export declare type CustomResolverMap = CacheResolverMap;
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/types.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/types.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,WAAY,SAAQ,MAAM;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AACD,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,CAC7B,KAAK,EAAE,WAAW,KACf,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAM/B,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,IAAI,IAAI,CAAC;IAMd,QAAQ,IAAI,qBAAqB,CAAC;IAIlC,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC;CAC/C;AAMD,MAAM,WAAW,qBAAqB;IACpC,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;CAC3C;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAED,oBAAY,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,qBAAqB,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC;CACjD,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,EAAE,eAAe,CAAC;IACvB,KAAK,EAAE,YAAY,CAAC;IACpB,uBAAuB,CAAC,EAAE,eAAe,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF,oBAAY,4BAA4B,GAAG,gBAAgB,GAAG;IAC5D,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAC1C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC;CACtC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,KAAK,CACH,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,GAAG,WAAW,CAAC;CAC1B;AAED,oBAAY,gBAAgB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3D,oBAAY,uBAAuB,GAAG;IACpC,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;YACb,aAAa,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC;aACd,EAAE,CAAC;SACL,EAAE,CAAC;KACL,CAAC;CACH,CAAC;AAEF,oBAAY,aAAa,GAAG,CAC1B,SAAS,EAAE,GAAG,EACd,IAAI,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAChC,OAAO,EAAE,GAAG,KACT,GAAG,CAAC;AAET,oBAAY,gBAAgB,GAAG;IAC7B,CAAC,QAAQ,EAAE,MAAM,GAAG;QAClB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC;KACpC,CAAC;CACH,CAAC;AAGF,oBAAY,cAAc,GAAG,aAAa,CAAC;AAC3C,oBAAY,iBAAiB,GAAG,gBAAgB,CAAC"}
|
||||
3
node_modules/apollo-cache-inmemory/lib/types.js
generated
vendored
Normal file
3
node_modules/apollo-cache-inmemory/lib/types.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/types.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
||||
46
node_modules/apollo-cache-inmemory/lib/writeToStore.d.ts
generated
vendored
Normal file
46
node_modules/apollo-cache-inmemory/lib/writeToStore.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import { SelectionSetNode, FieldNode, DocumentNode } from 'graphql';
|
||||
import { FragmentMatcher } from './readFromStore';
|
||||
import { FragmentMap } from 'apollo-utilities';
|
||||
import { IdGetter, NormalizedCache } from './types';
|
||||
export declare class WriteError extends Error {
|
||||
type: string;
|
||||
}
|
||||
export declare function enhanceErrorWithDocument(error: Error, document: DocumentNode): WriteError;
|
||||
export declare type WriteContext = {
|
||||
readonly store: NormalizedCache;
|
||||
readonly processedData?: {
|
||||
[x: string]: FieldNode[];
|
||||
};
|
||||
readonly variables?: any;
|
||||
readonly dataIdFromObject?: IdGetter;
|
||||
readonly fragmentMap?: FragmentMap;
|
||||
readonly fragmentMatcherFunction?: FragmentMatcher;
|
||||
};
|
||||
export declare class StoreWriter {
|
||||
writeQueryToStore({ query, result, store, variables, dataIdFromObject, fragmentMatcherFunction, }: {
|
||||
query: DocumentNode;
|
||||
result: Object;
|
||||
store?: NormalizedCache;
|
||||
variables?: Object;
|
||||
dataIdFromObject?: IdGetter;
|
||||
fragmentMatcherFunction?: FragmentMatcher;
|
||||
}): NormalizedCache;
|
||||
writeResultToStore({ dataId, result, document, store, variables, dataIdFromObject, fragmentMatcherFunction, }: {
|
||||
dataId: string;
|
||||
result: any;
|
||||
document: DocumentNode;
|
||||
store?: NormalizedCache;
|
||||
variables?: Object;
|
||||
dataIdFromObject?: IdGetter;
|
||||
fragmentMatcherFunction?: FragmentMatcher;
|
||||
}): NormalizedCache;
|
||||
writeSelectionSetToStore({ result, dataId, selectionSet, context, }: {
|
||||
dataId: string;
|
||||
result: any;
|
||||
selectionSet: SelectionSetNode;
|
||||
context: WriteContext;
|
||||
}): NormalizedCache;
|
||||
private writeFieldToStore;
|
||||
private processArrayValue;
|
||||
}
|
||||
//# sourceMappingURL=writeToStore.d.ts.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/writeToStore.d.ts.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/writeToStore.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"writeToStore.d.ts","sourceRoot":"","sources":["src/writeToStore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,YAAY,EAGb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAGL,WAAW,EAeZ,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EACL,QAAQ,EACR,eAAe,EAGhB,MAAM,SAAS,CAAC;AAEjB,qBAAa,UAAW,SAAQ,KAAK;IAC5B,IAAI,SAAgB;CAC5B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,cAQ5E;AAED,oBAAY,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAAA;KAAE,CAAC;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC;IACzB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,eAAe,CAAC;CACpD,CAAC;AAEF,qBAAa,WAAW;IAkBf,iBAAiB,CAAC,EACvB,KAAK,EACL,MAAM,EACN,KAAuC,EACvC,SAAS,EACT,gBAAgB,EAChB,uBAAuB,GACxB,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,eAAe,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,QAAQ,CAAC;QAC5B,uBAAuB,CAAC,EAAE,eAAe,CAAC;KAC3C,GAAG,eAAe;IAYZ,kBAAkB,CAAC,EACxB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,KAAuC,EACvC,SAAS,EACT,gBAAgB,EAChB,uBAAuB,GACxB,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,GAAG,CAAC;QACZ,QAAQ,EAAE,YAAY,CAAC;QACvB,KAAK,CAAC,EAAE,eAAe,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,QAAQ,CAAC;QAC5B,uBAAuB,CAAC,EAAE,eAAe,CAAC;KAC3C,GAAG,eAAe;IA2BZ,wBAAwB,CAAC,EAC9B,MAAM,EACN,MAAM,EACN,YAAY,EACZ,OAAO,GACR,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,GAAG,CAAC;QACZ,YAAY,EAAE,gBAAgB,CAAC;QAC/B,OAAO,EAAE,YAAY,CAAC;KACvB,GAAG,eAAe;IAwGnB,OAAO,CAAC,iBAAiB;IAgJzB,OAAO,CAAC,iBAAiB;CA2C1B"}
|
||||
276
node_modules/apollo-cache-inmemory/lib/writeToStore.js
generated
vendored
Normal file
276
node_modules/apollo-cache-inmemory/lib/writeToStore.js
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var apollo_utilities_1 = require("apollo-utilities");
|
||||
var ts_invariant_1 = require("ts-invariant");
|
||||
var objectCache_1 = require("./objectCache");
|
||||
var depTrackingCache_1 = require("./depTrackingCache");
|
||||
var WriteError = (function (_super) {
|
||||
tslib_1.__extends(WriteError, _super);
|
||||
function WriteError() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.type = 'WriteError';
|
||||
return _this;
|
||||
}
|
||||
return WriteError;
|
||||
}(Error));
|
||||
exports.WriteError = WriteError;
|
||||
function enhanceErrorWithDocument(error, document) {
|
||||
var enhancedError = new WriteError("Error writing result to store for query:\n " + JSON.stringify(document));
|
||||
enhancedError.message += '\n' + error.message;
|
||||
enhancedError.stack = error.stack;
|
||||
return enhancedError;
|
||||
}
|
||||
exports.enhanceErrorWithDocument = enhanceErrorWithDocument;
|
||||
var StoreWriter = (function () {
|
||||
function StoreWriter() {
|
||||
}
|
||||
StoreWriter.prototype.writeQueryToStore = function (_a) {
|
||||
var query = _a.query, result = _a.result, _b = _a.store, store = _b === void 0 ? depTrackingCache_1.defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
||||
return this.writeResultToStore({
|
||||
dataId: 'ROOT_QUERY',
|
||||
result: result,
|
||||
document: query,
|
||||
store: store,
|
||||
variables: variables,
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
});
|
||||
};
|
||||
StoreWriter.prototype.writeResultToStore = function (_a) {
|
||||
var dataId = _a.dataId, result = _a.result, document = _a.document, _b = _a.store, store = _b === void 0 ? depTrackingCache_1.defaultNormalizedCacheFactory() : _b, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
|
||||
var operationDefinition = apollo_utilities_1.getOperationDefinition(document);
|
||||
try {
|
||||
return this.writeSelectionSetToStore({
|
||||
result: result,
|
||||
dataId: dataId,
|
||||
selectionSet: operationDefinition.selectionSet,
|
||||
context: {
|
||||
store: store,
|
||||
processedData: {},
|
||||
variables: apollo_utilities_1.assign({}, apollo_utilities_1.getDefaultValues(operationDefinition), variables),
|
||||
dataIdFromObject: dataIdFromObject,
|
||||
fragmentMap: apollo_utilities_1.createFragmentMap(apollo_utilities_1.getFragmentDefinitions(document)),
|
||||
fragmentMatcherFunction: fragmentMatcherFunction,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
throw enhanceErrorWithDocument(e, document);
|
||||
}
|
||||
};
|
||||
StoreWriter.prototype.writeSelectionSetToStore = function (_a) {
|
||||
var _this = this;
|
||||
var result = _a.result, dataId = _a.dataId, selectionSet = _a.selectionSet, context = _a.context;
|
||||
var variables = context.variables, store = context.store, fragmentMap = context.fragmentMap;
|
||||
selectionSet.selections.forEach(function (selection) {
|
||||
var _a;
|
||||
if (!apollo_utilities_1.shouldInclude(selection, variables)) {
|
||||
return;
|
||||
}
|
||||
if (apollo_utilities_1.isField(selection)) {
|
||||
var resultFieldKey = apollo_utilities_1.resultKeyNameFromField(selection);
|
||||
var value = result[resultFieldKey];
|
||||
if (typeof value !== 'undefined') {
|
||||
_this.writeFieldToStore({
|
||||
dataId: dataId,
|
||||
value: value,
|
||||
field: selection,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
else {
|
||||
var isDefered = false;
|
||||
var isClient = false;
|
||||
if (selection.directives && selection.directives.length) {
|
||||
isDefered = selection.directives.some(function (directive) { return directive.name && directive.name.value === 'defer'; });
|
||||
isClient = selection.directives.some(function (directive) { return directive.name && directive.name.value === 'client'; });
|
||||
}
|
||||
if (!isDefered && !isClient && context.fragmentMatcherFunction) {
|
||||
ts_invariant_1.invariant.warn("Missing field " + resultFieldKey + " in " + JSON.stringify(result, null, 2).substring(0, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var fragment = void 0;
|
||||
if (apollo_utilities_1.isInlineFragment(selection)) {
|
||||
fragment = selection;
|
||||
}
|
||||
else {
|
||||
fragment = (fragmentMap || {})[selection.name.value];
|
||||
ts_invariant_1.invariant(fragment, "No fragment named " + selection.name.value + ".");
|
||||
}
|
||||
var matches = true;
|
||||
if (context.fragmentMatcherFunction && fragment.typeCondition) {
|
||||
var id = dataId || 'self';
|
||||
var idValue = apollo_utilities_1.toIdValue({ id: id, typename: undefined });
|
||||
var fakeContext = {
|
||||
store: new objectCache_1.ObjectCache((_a = {}, _a[id] = result, _a)),
|
||||
cacheRedirects: {},
|
||||
};
|
||||
var match = context.fragmentMatcherFunction(idValue, fragment.typeCondition.name.value, fakeContext);
|
||||
if (!apollo_utilities_1.isProduction() && match === 'heuristic') {
|
||||
ts_invariant_1.invariant.error('WARNING: heuristic fragment matching going on!');
|
||||
}
|
||||
matches = !!match;
|
||||
}
|
||||
if (matches) {
|
||||
_this.writeSelectionSetToStore({
|
||||
result: result,
|
||||
selectionSet: fragment.selectionSet,
|
||||
dataId: dataId,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return store;
|
||||
};
|
||||
StoreWriter.prototype.writeFieldToStore = function (_a) {
|
||||
var _b;
|
||||
var field = _a.field, value = _a.value, dataId = _a.dataId, context = _a.context;
|
||||
var variables = context.variables, dataIdFromObject = context.dataIdFromObject, store = context.store;
|
||||
var storeValue;
|
||||
var storeObject;
|
||||
var storeFieldName = apollo_utilities_1.storeKeyNameFromField(field, variables);
|
||||
if (!field.selectionSet || value === null) {
|
||||
storeValue =
|
||||
value != null && typeof value === 'object'
|
||||
?
|
||||
{ type: 'json', json: value }
|
||||
:
|
||||
value;
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
var generatedId = dataId + "." + storeFieldName;
|
||||
storeValue = this.processArrayValue(value, generatedId, field.selectionSet, context);
|
||||
}
|
||||
else {
|
||||
var valueDataId = dataId + "." + storeFieldName;
|
||||
var generated = true;
|
||||
if (!isGeneratedId(valueDataId)) {
|
||||
valueDataId = '$' + valueDataId;
|
||||
}
|
||||
if (dataIdFromObject) {
|
||||
var semanticId = dataIdFromObject(value);
|
||||
ts_invariant_1.invariant(!semanticId || !isGeneratedId(semanticId), 'IDs returned by dataIdFromObject cannot begin with the "$" character.');
|
||||
if (semanticId ||
|
||||
(typeof semanticId === 'number' && semanticId === 0)) {
|
||||
valueDataId = semanticId;
|
||||
generated = false;
|
||||
}
|
||||
}
|
||||
if (!isDataProcessed(valueDataId, field, context.processedData)) {
|
||||
this.writeSelectionSetToStore({
|
||||
dataId: valueDataId,
|
||||
result: value,
|
||||
selectionSet: field.selectionSet,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
var typename = value.__typename;
|
||||
storeValue = apollo_utilities_1.toIdValue({ id: valueDataId, typename: typename }, generated);
|
||||
storeObject = store.get(dataId);
|
||||
var escapedId = storeObject && storeObject[storeFieldName];
|
||||
if (escapedId !== storeValue && apollo_utilities_1.isIdValue(escapedId)) {
|
||||
var hadTypename = escapedId.typename !== undefined;
|
||||
var hasTypename = typename !== undefined;
|
||||
var typenameChanged = hadTypename && hasTypename && escapedId.typename !== typename;
|
||||
ts_invariant_1.invariant(!generated || escapedId.generated || typenameChanged, "Store error: the application attempted to write an object with no provided id but the store already contains an id of " + escapedId.id + " for this object. The selectionSet that was trying to be written is:\n" + JSON.stringify(field));
|
||||
ts_invariant_1.invariant(!hadTypename || hasTypename, "Store error: the application attempted to write an object with no provided typename but the store already contains an object with typename of " + escapedId.typename + " for the object of id " + escapedId.id + ". The selectionSet that was trying to be written is:\n" + JSON.stringify(field));
|
||||
if (escapedId.generated) {
|
||||
if (typenameChanged) {
|
||||
if (!generated) {
|
||||
store.delete(escapedId.id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mergeWithGenerated(escapedId.id, storeValue.id, store);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
storeObject = store.get(dataId);
|
||||
if (!storeObject || !apollo_utilities_1.isEqual(storeValue, storeObject[storeFieldName])) {
|
||||
store.set(dataId, tslib_1.__assign(tslib_1.__assign({}, storeObject), (_b = {}, _b[storeFieldName] = storeValue, _b)));
|
||||
}
|
||||
};
|
||||
StoreWriter.prototype.processArrayValue = function (value, generatedId, selectionSet, context) {
|
||||
var _this = this;
|
||||
return value.map(function (item, index) {
|
||||
if (item === null) {
|
||||
return null;
|
||||
}
|
||||
var itemDataId = generatedId + "." + index;
|
||||
if (Array.isArray(item)) {
|
||||
return _this.processArrayValue(item, itemDataId, selectionSet, context);
|
||||
}
|
||||
var generated = true;
|
||||
if (context.dataIdFromObject) {
|
||||
var semanticId = context.dataIdFromObject(item);
|
||||
if (semanticId) {
|
||||
itemDataId = semanticId;
|
||||
generated = false;
|
||||
}
|
||||
}
|
||||
if (!isDataProcessed(itemDataId, selectionSet, context.processedData)) {
|
||||
_this.writeSelectionSetToStore({
|
||||
dataId: itemDataId,
|
||||
result: item,
|
||||
selectionSet: selectionSet,
|
||||
context: context,
|
||||
});
|
||||
}
|
||||
return apollo_utilities_1.toIdValue({ id: itemDataId, typename: item.__typename }, generated);
|
||||
});
|
||||
};
|
||||
return StoreWriter;
|
||||
}());
|
||||
exports.StoreWriter = StoreWriter;
|
||||
function isGeneratedId(id) {
|
||||
return id[0] === '$';
|
||||
}
|
||||
function mergeWithGenerated(generatedKey, realKey, cache) {
|
||||
if (generatedKey === realKey) {
|
||||
return false;
|
||||
}
|
||||
var generated = cache.get(generatedKey);
|
||||
var real = cache.get(realKey);
|
||||
var madeChanges = false;
|
||||
Object.keys(generated).forEach(function (key) {
|
||||
var value = generated[key];
|
||||
var realValue = real[key];
|
||||
if (apollo_utilities_1.isIdValue(value) &&
|
||||
isGeneratedId(value.id) &&
|
||||
apollo_utilities_1.isIdValue(realValue) &&
|
||||
!apollo_utilities_1.isEqual(value, realValue) &&
|
||||
mergeWithGenerated(value.id, realValue.id, cache)) {
|
||||
madeChanges = true;
|
||||
}
|
||||
});
|
||||
cache.delete(generatedKey);
|
||||
var newRealValue = tslib_1.__assign(tslib_1.__assign({}, generated), real);
|
||||
if (apollo_utilities_1.isEqual(newRealValue, real)) {
|
||||
return madeChanges;
|
||||
}
|
||||
cache.set(realKey, newRealValue);
|
||||
return true;
|
||||
}
|
||||
function isDataProcessed(dataId, field, processedData) {
|
||||
if (!processedData) {
|
||||
return false;
|
||||
}
|
||||
if (processedData[dataId]) {
|
||||
if (processedData[dataId].indexOf(field) >= 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
processedData[dataId].push(field);
|
||||
}
|
||||
}
|
||||
else {
|
||||
processedData[dataId] = [field];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=writeToStore.js.map
|
||||
1
node_modules/apollo-cache-inmemory/lib/writeToStore.js.map
generated
vendored
Normal file
1
node_modules/apollo-cache-inmemory/lib/writeToStore.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user