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
Reference in New Issue
Block a user