Skip to content

Commit

Permalink
Update optimism to use its new TypeScript declarations. (#4331)
Browse files Browse the repository at this point in the history
Since we've been struggling to declare correct types for the `optimism`
npm package (for example: #4158, #4327), I finally decided to move the
declarations into the `optimism` package itself: benjamn/optimism@03b3f88

Pretty easy! I wish I'd done this sooner.

Should fix #4327.
  • Loading branch information
benjamn committed Jan 18, 2019
1 parent 4a220cd commit 72c5587
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 37 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -17,6 +17,11 @@

### Apollo Cache In-Memory (vNext)

- The `optimism` npm package has been updated to a version (0.6.9) that
provides its own TypeScript declarations, which should fix problems like
[Issue #4327](https://github.com/apollographql/apollo-client/issues/4327). <br/>
[PR #4331](https://github.com/apollographql/apollo-client/pull/4331)

- Error messages involving GraphQL queries now print the queries using
`JSON.stringify` instead of the `print` function exported by the
`graphql` package, to avoid pulling unnecessary printing logic into your
Expand All @@ -27,7 +32,7 @@
results for non-identical queries (or sub-queries) with equivalent
structure will no longer be cached together. This feature was a nice
optimization in certain specific use cases, but it was not worth the
additional complexity or bundle size.
additional complexity or bundle size. <br/>
[PR #4245](https://github.com/apollographql/apollo-client/pull/4245)

- The `flattenSelections` helper function is no longer exported from
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-cache-inmemory/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-cache-inmemory/package.json
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"apollo-cache": "file:../apollo-cache",
"apollo-utilities": "file:../apollo-utilities",
"optimism": "^0.6.8"
"optimism": "^0.6.9"
},
"peerDependencies": {
"graphql": "0.11.7 || ^0.12.0 || ^0.13.0 || ^14.0.0"
Expand Down
@@ -1,19 +1,3 @@
export type OptimisticWrapperFunction<
T = (...args: any[]) => any
> = T & {
// The .dirty(...) method of an optimistic function takes exactly the same
// parameter types as the original function.
dirty: T;
};

export type OptimisticWrapOptions = {
max?: number;
disposable?: boolean;
makeCacheKey?(...args: any[]): any;
};

export { wrap } from 'optimism';

export class CacheKeyNode<KeyType = object> {
private children: Map<any, CacheKeyNode<KeyType>> | null = null;
private key: KeyType | null = null;
Expand All @@ -34,7 +18,7 @@ export class CacheKeyNode<KeyType = object> {
const map = this.children || (this.children = new Map());
let node = map.get(value);
if (!node) {
map.set(value, node = new CacheKeyNode<KeyType>());
map.set(value, (node = new CacheKeyNode<KeyType>()));
}
return node;
}
Expand Down
6 changes: 0 additions & 6 deletions packages/apollo-cache-inmemory/src/declarations.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/apollo-cache-inmemory/src/depTrackingCache.ts
@@ -1,5 +1,5 @@
import { NormalizedCache, NormalizedCacheObject, StoreObject } from './types';
import { wrap, OptimisticWrapperFunction } from './optimism';
import { wrap, OptimisticWrapperFunction } from 'optimism';

const hasOwn = Object.prototype.hasOwnProperty;

Expand Down
9 changes: 4 additions & 5 deletions packages/apollo-cache-inmemory/src/inMemoryCache.ts
Expand Up @@ -5,9 +5,9 @@ import { DocumentNode } from 'graphql';

import { Cache, ApolloCache, Transaction } from 'apollo-cache';

import {
addTypenameToDocument,
} from 'apollo-utilities';
import { addTypenameToDocument } from 'apollo-utilities';

import { wrap } from 'optimism';

import { HeuristicFragmentMatcher } from './fragmentMatcher';
import {
Expand All @@ -18,9 +18,8 @@ import {

import { StoreReader } from './readFromStore';
import { StoreWriter } from './writeToStore';

import { DepTrackingCache } from './depTrackingCache';
import { wrap, CacheKeyNode } from './optimism';
import { CacheKeyNode } from './cacheKeys';
import { ObjectCache } from './objectCache';

export interface InMemoryCacheConfig extends ApolloReducerConfig {
Expand Down
5 changes: 2 additions & 3 deletions packages/apollo-cache-inmemory/src/readFromStore.ts
Expand Up @@ -39,9 +39,8 @@ import {
SelectionSetNode,
} from 'graphql';

import { wrap, CacheKeyNode } from './optimism';
export { OptimisticWrapperFunction } from './optimism';

import { wrap } from 'optimism';
import { CacheKeyNode } from './cacheKeys';
import { DepTrackingCache } from './depTrackingCache';

export type VariableMap = { [name: string]: any };
Expand Down

0 comments on commit 72c5587

Please sign in to comment.