···
import { write, writeOptimistic } from '../operations/write';
import * as InMemoryData from './data';
import { Store } from './store';
8
+
import { noop } from '../test-utils/utils';
query appointment($id: String) {
···
95
+
describe('Store with UpdatesConfig', () => {
96
+
it("sets the store's updates field to the given argument", () => {
97
+
const updatesOption = {
106
+
const store = new Store({
107
+
updates: updatesOption,
110
+
expect(store.updates.Mutation).toBe(updatesOption.Mutation);
111
+
expect(store.updates.Subscription).toBe(updatesOption.Subscription);
114
+
it("sets the store's updates field to an empty default if not provided", () => {
115
+
const store = new Store({});
117
+
expect(store.updates.Mutation).toEqual({});
118
+
expect(store.updates.Subscription).toEqual({});
121
+
it('should not warn if Mutation/Subscription operations do exist in the schema', function () {
123
+
schema: require('../test-utils/simple_schema.json'),
134
+
expect(console.warn).not.toBeCalled();
137
+
it("should warn if Mutation operations don't exist in the schema", function () {
139
+
schema: require('../test-utils/simple_schema.json'),
142
+
doTheChaChaSlide: noop,
147
+
expect(console.warn).toBeCalledTimes(1);
148
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
149
+
expect(warnMessage).toContain(
150
+
'Invalid mutation field: `doTheChaChaSlide` is not in the defined schema, but the `updates.Mutation` option is referencing it.'
152
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#21');
155
+
it("should warn if Subscription operations don't exist in the schema", function () {
157
+
schema: require('../test-utils/simple_schema.json'),
160
+
someoneDidTheChaChaSlide: noop,
165
+
expect(console.warn).toBeCalledTimes(1);
166
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
167
+
expect(warnMessage).toContain(
168
+
'Invalid subscription field: `someoneDidTheChaChaSlide` is not in the defined schema, but the `updates.Subscription` option is referencing it.'
170
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#22');
describe('Store with KeyingConfig', () => {
it('generates keys from custom keying function', () => {
const store = new Store({
···
221
+
describe('Store with ResolverConfig', () => {
222
+
it("sets the store's resolvers field to the given argument", () => {
223
+
const resolversOption = {
225
+
latestTodo: () => 'todo',
229
+
const store = new Store({
230
+
resolvers: resolversOption,
233
+
expect(store.resolvers).toBe(resolversOption);
236
+
it("sets the store's resolvers field to an empty default if not provided", () => {
237
+
const store = new Store({});
239
+
expect(store.resolvers).toEqual({});
242
+
it('should not warn if resolvers do exist in the schema', function () {
244
+
schema: require('../test-utils/simple_schema.json'),
247
+
latestTodo: () => 'todo',
248
+
todos: () => ['todo 1', 'todo 2'],
251
+
text: todo => (todo.text as string).toUpperCase(),
252
+
author: todo => (todo.author as string).toUpperCase(),
257
+
expect(console.warn).not.toBeCalled();
260
+
it("should warn if a Query doesn't exist in the schema", function () {
262
+
schema: require('../test-utils/simple_schema.json'),
265
+
todos: () => ['todo 1', 'todo 2'],
266
+
// This query should be warned about.
267
+
findDeletedTodos: () => ['todo 1', 'todo 2'],
272
+
expect(console.warn).toBeCalledTimes(1);
273
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
274
+
expect(warnMessage).toContain(
275
+
'Invalid resolver: `Query.findDeletedTodos` is not in the defined schema, but the `resolvers` option is referencing it'
277
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#23');
280
+
it("should warn if a type doesn't exist in the schema", function () {
282
+
schema: require('../test-utils/simple_schema.json'),
285
+
complete: () => true,
287
+
// This type should be warned about.
289
+
isExtinct: () => true,
294
+
expect(console.warn).toBeCalledTimes(1);
295
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
296
+
expect(warnMessage).toContain(
297
+
'Invalid resolver: `Dinosaur` is not in the defined schema, but the `resolvers` option is referencing it'
299
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#23');
302
+
it("should warn if a type's property doesn't exist in the schema", function () {
304
+
schema: require('../test-utils/simple_schema.json'),
307
+
complete: () => true,
308
+
// This property should be warned about.
309
+
isAboutDinosaurs: () => true,
314
+
expect(console.warn).toBeCalledTimes(1);
315
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
316
+
expect(warnMessage).toContain(
317
+
'Invalid resolver: `Todo.isAboutDinosaurs` is not in the defined schema, but the `resolvers` option is referencing it'
319
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#23');
describe('Store with OptimisticMutationConfig', () => {
···
InMemoryData.initDataState(store.data, null);
159
-
it('Should resolve a property', () => {
341
+
it('should resolve a property', () => {
const todoResult = store.resolve({ __typename: 'Todo', id: '0' }, 'text');
expect(todoResult).toEqual('Go to the shops');
const authorResult = store.resolve(
···
InMemoryData.clearDataState();
183
-
it('Should resolve a link property', () => {
365
+
it('should resolve a link property', () => {
···
InMemoryData.initDataState(store.data, null);
expect(InMemoryData.readRecord('Query', 'base')).toBe(true);
InMemoryData.clearDataState();
845
+
it("should warn if an optimistic field doesn't exist in the schema's mutations", function () {
847
+
schema: require('../test-utils/simple_schema.json'),
854
+
toggleTodo: () => null,
855
+
// This field should be warned about.
856
+
deleteTodo: () => null,
860
+
expect(console.warn).toBeCalledTimes(1);
861
+
const warnMessage = mocked(console.warn).mock.calls[0][0];
862
+
expect(warnMessage).toContain(
863
+
'Invalid optimistic mutation field: `deleteTodo` is not a mutation field in the defined schema, but the `optimistic` option is referencing it.'
865
+
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#24');