From 4f76c57dcc122c0e1c6230f0396fdac1149634be Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 20 Dec 2016 14:24:01 +0100 Subject: [PATCH 01/18] Use UMD bundle and ES6 modules --- .npmignore | 2 ++ package.json | 9 +++++++-- rollup.config.js | 9 +++++++++ src/ApolloClient.ts | 4 ++-- src/core/ObservableQuery.ts | 2 +- src/core/QueryManager.ts | 5 ++--- src/data/debug.ts | 4 +--- src/data/mutationResults.ts | 4 ++-- src/data/scopeQuery.ts | 2 +- src/data/storeUtils.ts | 2 +- src/data/writeToStore.ts | 6 +++--- src/optimistic-data/store.ts | 2 +- src/queries/getFromAST.ts | 6 +++--- src/queries/queryTransform.ts | 2 +- src/queries/store.ts | 2 +- src/store.ts | 2 +- src/transport/batchedNetworkInterface.ts | 3 +-- src/transport/networkInterface.ts | 4 +--- test/QueryManager.ts | 2 +- test/batchedNetworkInterface.ts | 2 +- test/client.ts | 4 +--- test/directives.ts | 2 +- test/fetchMore.ts | 11 +++++------ test/fixtures/redux-todomvc/reducers.ts | 2 +- test/graphqlSubscriptions.ts | 4 ++-- test/mockNetworkInterface.ts | 2 +- test/mutationResults.ts | 23 +++++++++++------------ test/networkInterface.ts | 7 +++---- test/optimistic.ts | 15 +++++++-------- test/readFromStore.ts | 3 +-- test/subscribeToMore.ts | 4 +--- test/writeToStore.ts | 4 +--- tsconfig.json | 5 ++--- tsconfig.test.json | 14 ++++++++++++++ 34 files changed, 93 insertions(+), 81 deletions(-) create mode 100644 rollup.config.js create mode 100644 tsconfig.test.json diff --git a/.npmignore b/.npmignore index aebe5ce87c2..d00b10f93a1 100644 --- a/.npmignore +++ b/.npmignore @@ -8,6 +8,8 @@ appveyor.yml CHANGELOG.md design.md Gruntfile.js +rollup.config.js tsconfig.json +tsconfig.test.json tslint.json typings.json diff --git a/package.json b/package.json index 94b19c48f97..6b32aedbec3 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,23 @@ "name": "apollo-client", "version": "0.5.26", "description": "A simple yet functional GraphQL client.", - "main": "./lib/src/index.js", + "main": "./lib/bundles/apollo.umd.js", + "module": "./lib/src/index.js", "typings": "./lib/src/index.d.ts", "scripts": { "dev": "./scripts/dev.sh", "deploy": "rm -rf ./lib && npm run compile && ./scripts/deploy.sh", - "pretest": "npm run compile", + "pretest": "npm run compile:test", "test": "npm run testonly --", "posttest": "npm run lint", "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=38", "compile": "tsc", + "compile:test": "tsc -p tsconfig.test.json", "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/src/index.js -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", + "bundle": "rollup -c", + "postcompile": "npm run bundle", "prepublish": "npm run compile", "lint": "grunt tslint", "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace lib/test/tests.js", @@ -66,6 +70,7 @@ "pretty-bytes": "^4.0.0", "remap-istanbul": "0.8.0", "request": "^2.75.0", + "rollup": "^0.37.0", "rxjs": "^5.0.0-beta.11", "sinon": "^1.17.4", "source-map-support": "^0.4.0", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000000..7ffdb60f839 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,9 @@ +export default { + entry: 'lib/src/index.js', + dest: 'lib/bundles/apollo.umd.js', + format: 'umd', + moduleName: 'apollo', + globals: { + 'lodash': '_' + } +}; diff --git a/src/ApolloClient.ts b/src/ApolloClient.ts index b43e8724685..65d2895d85e 100644 --- a/src/ApolloClient.ts +++ b/src/ApolloClient.ts @@ -13,8 +13,8 @@ import { } from 'graphql'; -import isUndefined = require('lodash/isUndefined'); -import isString = require('lodash/isString'); +import isUndefined from 'lodash/isUndefined'; +import isString from 'lodash/isString'; import { createApolloStore, diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index bd1e392f02f..2c7bac6008b 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -25,7 +25,7 @@ import { tryFunctionOrLogError } from '../util/errorHandling'; import { NetworkStatus } from '../queries/store'; -import isEqual = require('lodash/isEqual'); +import isEqual from 'lodash/isEqual'; export type ApolloCurrentResult = { data: any; diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 1b16f69d363..4433c0449e6 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -8,8 +8,8 @@ import { Deduplicator, } from '../transport/Deduplicator'; -import forOwn = require('lodash/forOwn'); -import isEqual = require('lodash/isEqual'); +import forOwn from 'lodash/forOwn'; +import isEqual from 'lodash/isEqual'; import { ApolloStore, @@ -598,7 +598,6 @@ export class QueryManager { this.fetchQueryPromises[requestId.toString()] = { promise, resolve, reject }; } - // Removes the promise in this.fetchQueryPromises for a particular request ID. public removeFetchQueryPromise(requestId: number) { delete this.fetchQueryPromises[requestId.toString()]; diff --git a/src/data/debug.ts b/src/data/debug.ts index f538677575b..b6c984ed297 100644 --- a/src/data/debug.ts +++ b/src/data/debug.ts @@ -1,7 +1,5 @@ // For development only! -import isObject = require('lodash/isObject'); -import omit = require('lodash/omit'); -import mapValues = require('lodash/mapValues'); +import { isObject, omit, mapValues } from 'lodash'; export function stripLoc(obj: Object) { if (Array.isArray(obj)) { diff --git a/src/data/mutationResults.ts b/src/data/mutationResults.ts index 726cf1a63f8..9b030bdc043 100644 --- a/src/data/mutationResults.ts +++ b/src/data/mutationResults.ts @@ -8,8 +8,8 @@ import { GraphQLResult, } from 'graphql'; -import mapValues = require('lodash/mapValues'); -import cloneDeep = require('lodash/cloneDeep'); +import mapValues from 'lodash/mapValues'; +import cloneDeep from 'lodash/cloneDeep'; import { replaceQueryResults } from './replaceQueryResults'; diff --git a/src/data/scopeQuery.ts b/src/data/scopeQuery.ts index 5827627dffa..32facdb30cb 100644 --- a/src/data/scopeQuery.ts +++ b/src/data/scopeQuery.ts @@ -13,7 +13,7 @@ import { resultKeyNameFromField, } from './storeUtils'; -import isNumber = require('lodash/isNumber'); +import { isNumber } from 'lodash'; // The type of a path export type StorePath = (string|number)[]; diff --git a/src/data/storeUtils.ts b/src/data/storeUtils.ts index a91a67017be..7b6092d0c2b 100644 --- a/src/data/storeUtils.ts +++ b/src/data/storeUtils.ts @@ -15,7 +15,7 @@ import { Name, } from 'graphql'; -import isObject = require('lodash/isObject'); +import { isObject } from 'lodash'; function isStringValue(value: Value): value is StringValue { return value.kind === 'StringValue'; diff --git a/src/data/writeToStore.ts b/src/data/writeToStore.ts index 91107561ad4..91bafb2541b 100644 --- a/src/data/writeToStore.ts +++ b/src/data/writeToStore.ts @@ -1,6 +1,6 @@ -import isNull = require('lodash/isNull'); -import isUndefined = require('lodash/isUndefined'); -import isObject = require('lodash/isObject'); +import isNull from 'lodash/isNull'; +import isUndefined from 'lodash/isUndefined'; +import isObject from 'lodash/isObject'; import { getOperationDefinition, diff --git a/src/optimistic-data/store.ts b/src/optimistic-data/store.ts index 0775a026e19..3f5b9df64bd 100644 --- a/src/optimistic-data/store.ts +++ b/src/optimistic-data/store.ts @@ -18,7 +18,7 @@ import { Store, } from '../store'; -import pick = require('lodash/pick'); +import pick from 'lodash/pick'; // a stack of patches of new or changed documents export type OptimisticStore = { diff --git a/src/queries/getFromAST.ts b/src/queries/getFromAST.ts index 532716e2bd8..ac13dc11d5b 100644 --- a/src/queries/getFromAST.ts +++ b/src/queries/getFromAST.ts @@ -4,9 +4,9 @@ import { FragmentDefinition, } from 'graphql'; -import countBy = require('lodash/countBy'); -import identity = require('lodash/identity'); -import uniq = require('lodash/uniq'); +import countBy from 'lodash/countBy'; +import identity from 'lodash/identity'; +import uniq from 'lodash/uniq'; export function getMutationDefinition(doc: Document): OperationDefinition { checkDocument(doc); diff --git a/src/queries/queryTransform.ts b/src/queries/queryTransform.ts index 7b3dcbecfb7..ca3d123e9b7 100644 --- a/src/queries/queryTransform.ts +++ b/src/queries/queryTransform.ts @@ -11,7 +11,7 @@ import { checkDocument, } from './getFromAST'; -import cloneDeep = require('lodash/cloneDeep'); +import { cloneDeep } from 'lodash'; const TYPENAME_FIELD: Field = { kind: 'Field', diff --git a/src/queries/store.ts b/src/queries/store.ts index 37229c78b70..c174a8e7a38 100644 --- a/src/queries/store.ts +++ b/src/queries/store.ts @@ -18,7 +18,7 @@ import { GraphQLError, } from 'graphql'; -import isEqual = require('lodash/isEqual'); +import isEqual from 'lodash/isEqual'; export interface QueryStore { [queryId: string]: QueryStoreValue; diff --git a/src/store.ts b/src/store.ts index 04d47709185..2edab02c01c 100644 --- a/src/store.ts +++ b/src/store.ts @@ -45,7 +45,7 @@ import { CustomResolverMap, } from './data/readFromStore'; -import assign = require('lodash/assign'); +import { assign } from 'lodash'; export interface Store { data: NormalizedCache; diff --git a/src/transport/batchedNetworkInterface.ts b/src/transport/batchedNetworkInterface.ts index ae1bbbb842f..c063372e1a3 100644 --- a/src/transport/batchedNetworkInterface.ts +++ b/src/transport/batchedNetworkInterface.ts @@ -4,8 +4,7 @@ import { import 'whatwg-fetch'; -import assign = require('lodash/assign'); -import isNumber = require('lodash/isNumber'); +import { assign, isNumber } from 'lodash'; import { HTTPFetchNetworkInterface, diff --git a/src/transport/networkInterface.ts b/src/transport/networkInterface.ts index 4e66d8dc73f..8c01b8159f9 100644 --- a/src/transport/networkInterface.ts +++ b/src/transport/networkInterface.ts @@ -1,6 +1,4 @@ -import isString = require('lodash/isString'); -import assign = require('lodash/assign'); -import mapValues = require('lodash/mapValues'); +import { isString, assign, mapValues } from 'lodash'; import 'whatwg-fetch'; import { diff --git a/test/QueryManager.ts b/test/QueryManager.ts index a41496c4091..a0a9fc2414b 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -42,7 +42,7 @@ import { createStore, combineReducers, applyMiddleware } from 'redux'; import * as Rx from 'rxjs'; -import assign = require('lodash/assign'); +import { assign } from 'lodash'; import mockNetworkInterface, { ParsedRequest, diff --git a/test/batchedNetworkInterface.ts b/test/batchedNetworkInterface.ts index d65b572f6dc..76bc5a8cee3 100644 --- a/test/batchedNetworkInterface.ts +++ b/test/batchedNetworkInterface.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import merge = require('lodash/merge'); +import { merge } from 'lodash'; import { HTTPBatchedNetworkInterface } from '../src/transport/batchedNetworkInterface'; diff --git a/test/client.ts b/test/client.ts index f0283533987..2b9ed25be50 100644 --- a/test/client.ts +++ b/test/client.ts @@ -74,9 +74,7 @@ import { withWarning } from './util/wrap'; import observableToPromise from './util/observableToPromise'; -import cloneDeep = require('lodash/cloneDeep'); - -import assign = require('lodash/assign'); +import { cloneDeep, assign } from 'lodash'; // make it easy to assert with promises chai.use(chaiAsPromised); diff --git a/test/directives.ts b/test/directives.ts index 5c2b98565de..245e8aed863 100644 --- a/test/directives.ts +++ b/test/directives.ts @@ -11,7 +11,7 @@ import { import gql from 'graphql-tag'; -import cloneDeep = require('lodash/cloneDeep'); +import { cloneDeep } from 'lodash'; describe('query directives', () => { it('should should not include a skipped field', () => { diff --git a/test/fetchMore.ts b/test/fetchMore.ts index 370f672b4a0..c7d66fef2cf 100644 --- a/test/fetchMore.ts +++ b/test/fetchMore.ts @@ -5,8 +5,7 @@ import mockNetworkInterface from './mocks/mockNetworkInterface'; import ApolloClient from '../src'; import { ObservableQuery } from '../src/core/ObservableQuery'; -import assign = require('lodash/assign'); -import clonedeep = require('lodash/cloneDeep'); +import { assign, cloneDeep } from 'lodash'; import gql from 'graphql-tag'; @@ -57,7 +56,7 @@ describe('updateQuery on a simple query', () => { .then((watchedQuery: ObservableQuery) => { assert.equal(latestResult.data.entry.value, 1); watchedQuery.updateQuery((prevResult: any) => { - const res = clonedeep(prevResult); + const res = cloneDeep(prevResult); res.entry.value = 2; return res; }); @@ -109,7 +108,7 @@ describe('fetchMore on an observable query', () => { }, }, }; - const resultMore = clonedeep(result); + const resultMore = cloneDeep(result); const result2: any = { data: { __typename: 'Query', @@ -175,7 +174,7 @@ describe('fetchMore on an observable query', () => { return watchedQuery.fetchMore({ variables: { start: 10 }, // rely on the fact that the original variables had limit: 10 updateQuery: (prev, options) => { - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.entry.comments = [...state.entry.comments, ...(options.fetchMoreResult as any).data.entry.comments]; return state; }, @@ -205,7 +204,7 @@ describe('fetchMore on an observable query', () => { query: query2, variables: variables2, updateQuery: (prev, options) => { - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.entry.comments = [...state.entry.comments, ...(options.fetchMoreResult as any).data.comments]; return state; }, diff --git a/test/fixtures/redux-todomvc/reducers.ts b/test/fixtures/redux-todomvc/reducers.ts index e3092adf3f5..7d56a6a0375 100644 --- a/test/fixtures/redux-todomvc/reducers.ts +++ b/test/fixtures/redux-todomvc/reducers.ts @@ -1,5 +1,5 @@ import { combineReducers } from 'redux'; -import assign = require('lodash/assign'); +import { assign } from 'lodash'; import { ADD_TODO, diff --git a/test/graphqlSubscriptions.ts b/test/graphqlSubscriptions.ts index add2390b7d6..763c9997ee8 100644 --- a/test/graphqlSubscriptions.ts +++ b/test/graphqlSubscriptions.ts @@ -6,7 +6,7 @@ import { assert, } from 'chai'; -import clonedeep = require('lodash/cloneDeep'); +import { cloneDeep } from 'lodash'; import { isSubscriptionResultAction } from '../src/actions'; @@ -282,7 +282,7 @@ describe('GraphQL Subscriptions', () => { reducer: (previousResult, action) => { counter++; if (isSubscriptionResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.number++; return newResult; } diff --git a/test/mockNetworkInterface.ts b/test/mockNetworkInterface.ts index 655fee38708..e3d3591b0b8 100644 --- a/test/mockNetworkInterface.ts +++ b/test/mockNetworkInterface.ts @@ -7,7 +7,7 @@ import { MockedSubscription, } from './mocks/mockNetworkInterface'; -import omit = require('lodash/omit'); +import { omit } from 'lodash'; import gql from 'graphql-tag'; diff --git a/test/mutationResults.ts b/test/mutationResults.ts index abaf81139e6..7c2cc7e0f91 100644 --- a/test/mutationResults.ts +++ b/test/mutationResults.ts @@ -7,8 +7,7 @@ import { isMutationResultAction, isQueryResultAction } from '../src/actions'; import { Subscription } from '../src/util/Observable'; -import assign = require('lodash/assign'); -import clonedeep = require('lodash/cloneDeep'); +import { assign, cloneDeep } from 'lodash'; import { ObservableQuery } from '../src/core/ObservableQuery'; @@ -743,7 +742,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { counter++; if (isMutationResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -854,7 +853,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { if (isMutationResultAction(action) && action.operationName === 'createTodo') { counter++; - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -871,7 +870,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { if (isMutationResultAction(action) && action.operationName === 'wrongName') { counter++; // shouldn't be called, so counter shouldn't increase. - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -919,7 +918,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { counter++; if (isQueryResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.newTodos[0]); return newResult; } @@ -1003,7 +1002,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { counter++; if (isMutationResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -1018,7 +1017,7 @@ describe('mutation results', () => { reducer: (previousResult, action) => { counter2++; if (isMutationResultAction(action) && action.result.data.createTodo.completed) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.filteredTodos.unshift(action.result.data.createTodo); return newResult; } @@ -1170,7 +1169,7 @@ describe('mutation results', () => { assert.equal(mResult.data.createTodo.id, '99'); assert.equal(mResult.data.createTodo.text, 'This one was created with a mutation.'); - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, @@ -1209,7 +1208,7 @@ describe('mutation results', () => { assert.equal(mResult.data.createTodo.id, '99'); assert.equal(mResult.data.createTodo.text, 'This one was created with a mutation.'); - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, @@ -1233,7 +1232,7 @@ describe('mutation results', () => { updateQueries: { todoList: (prev, options) => { const mResult = options.mutationResult as any; - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; // It's unfortunate that this function is called at all, but we are removing // the updateQueries API soon so it won't matter. state.todoList.todos.unshift(mResult.data && mResult.data.createTodo); @@ -1248,7 +1247,7 @@ describe('mutation results', () => { updateQueries: { todoList: (prev, options) => { const mResult = options.mutationResult as any; - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, diff --git a/test/networkInterface.ts b/test/networkInterface.ts index f171d213fe5..81da9d4cf26 100644 --- a/test/networkInterface.ts +++ b/test/networkInterface.ts @@ -1,8 +1,7 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import assign = require('lodash/assign'); -import isequal = require('lodash/isEqual'); +import { assign, isEqual } from 'lodash'; import * as fetchMock from 'fetch-mock'; // make it easy to assert with promises @@ -116,12 +115,12 @@ describe('network interface', () => { } if (query === print(simpleQueryWithVar) - && isequal(variables, { personNum: 1 })) { + && isEqual(variables, { personNum: 1 })) { return simpleResult; } if (query === print(complexQueryWithTwoVars) - && isequal(variables, { personNum: 1, filmNum: 1 })) { + && isEqual(variables, { personNum: 1, filmNum: 1 })) { return complexResult; } diff --git a/test/optimistic.ts b/test/optimistic.ts index a683bac726d..945c4191e86 100644 --- a/test/optimistic.ts +++ b/test/optimistic.ts @@ -6,8 +6,7 @@ import ApolloClient from '../src'; import { MutationBehaviorReducerArgs, MutationBehavior, MutationQueryReducersMap } from '../src/data/mutationResults'; import { NormalizedCache, StoreObject } from '../src/data/storeUtils'; -import assign = require('lodash/assign'); -import clonedeep = require('lodash/cloneDeep'); +import { assign, cloneDeep} from 'lodash'; import { Subscription } from '../src/util/Observable'; @@ -721,7 +720,7 @@ describe('optimistic mutation results', () => { const mResult = options.mutationResult as any; assert.equal(mResult.data.createTodo.id, '99'); - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, @@ -771,7 +770,7 @@ describe('optimistic mutation results', () => { todoList: (prev, options) => { const mResult = options.mutationResult as any; - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, @@ -845,7 +844,7 @@ describe('optimistic mutation results', () => { todoList: (prev, options) => { const mResult = options.mutationResult as any; - const state = clonedeep(prev) as any; + const state = cloneDeep(prev) as any; state.todoList.todos.unshift(mResult.data.createTodo); return state; }, @@ -950,7 +949,7 @@ describe('optimistic mutation results', () => { reducer: (previousResult, action) => { counter++; if (isMutationResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -978,7 +977,7 @@ describe('optimistic mutation results', () => { reducer: (previousResult, action) => { counter++; if (isMutationResultAction(action)) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } @@ -1134,7 +1133,7 @@ describe('optimistic mutation - githunt comments', () => { const updateQueries = { Comment: (prev, { mutationResult: mutationResultArg }) => { const newComment = (mutationResultArg as any).data.submitComment; - const state = clonedeep(prev); + const state = cloneDeep(prev); (state as any).entry.comments.unshift(newComment); return state; }, diff --git a/test/readFromStore.ts b/test/readFromStore.ts index 8901448208e..e6b4619564d 100644 --- a/test/readFromStore.ts +++ b/test/readFromStore.ts @@ -1,6 +1,5 @@ import { assert } from 'chai'; -import assign = require('lodash/assign'); -import omit = require('lodash/omit'); +import { assign, omit } from 'lodash'; import { readQueryFromStore, diff --git a/test/subscribeToMore.ts b/test/subscribeToMore.ts index fc1cda6c84e..78ea3058e2a 100644 --- a/test/subscribeToMore.ts +++ b/test/subscribeToMore.ts @@ -4,10 +4,8 @@ const { assert } = chai; import { mockSubscriptionNetworkInterface, } from './mocks/mockNetworkInterface'; -import ApolloClient from '../src'; -// import assign = require('lodash/assign'); -// import clonedeep = require('lodash/cloneDeep'); +import ApolloClient from '../src'; import gql from 'graphql-tag'; diff --git a/test/writeToStore.ts b/test/writeToStore.ts index 622da7dbc8a..c1021ff730c 100644 --- a/test/writeToStore.ts +++ b/test/writeToStore.ts @@ -1,7 +1,5 @@ import { assert } from 'chai'; -import cloneDeep = require('lodash/cloneDeep'); -import assign = require('lodash/assign'); -import omit = require('lodash/omit'); +import { cloneDeep, assign, omit } from 'lodash'; import { writeQueryToStore, diff --git a/tsconfig.json b/tsconfig.json index 20f0661b21a..36df1d7f256 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "module": "commonjs", + "module": "es2015", "moduleResolution": "node", "sourceMap": true, "declaration": true, @@ -19,7 +19,6 @@ "node_modules/typescript/lib/lib.dom.d.ts", "typings.d.ts", "fetch-mock.typings.d.ts", - "src/index.ts", - "test/tests.ts" + "src/index.ts" ] } diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 00000000000..d88aede9dec --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "commonjs" + }, + "files": [ + "node_modules/typescript/lib/lib.es2015.d.ts", + "node_modules/typescript/lib/lib.dom.d.ts", + "typings.d.ts", + "fetch-mock.typings.d.ts", + "src/index.ts", + "test/tests.ts" + ] +} From de2e7a2d281c4453b3a63355a753878e7f6cde0e Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 20 Dec 2016 15:34:21 +0100 Subject: [PATCH 02/18] Single imports --- src/data/debug.ts | 5 ++++- src/data/scopeQuery.ts | 2 +- src/data/storeUtils.ts | 2 +- src/queries/queryTransform.ts | 2 +- src/store.ts | 2 +- src/transport/batchedNetworkInterface.ts | 3 ++- src/transport/networkInterface.ts | 5 ++++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/data/debug.ts b/src/data/debug.ts index b6c984ed297..7a874984e2f 100644 --- a/src/data/debug.ts +++ b/src/data/debug.ts @@ -1,5 +1,8 @@ // For development only! -import { isObject, omit, mapValues } from 'lodash'; +// import { isObject, omit, mapValues } from 'lodash'; +import isObject from 'lodash/isObject'; +import omit from 'lodash/omit'; +import mapValues from 'lodash/mapValues'; export function stripLoc(obj: Object) { if (Array.isArray(obj)) { diff --git a/src/data/scopeQuery.ts b/src/data/scopeQuery.ts index 32facdb30cb..6a4705f8cfe 100644 --- a/src/data/scopeQuery.ts +++ b/src/data/scopeQuery.ts @@ -13,7 +13,7 @@ import { resultKeyNameFromField, } from './storeUtils'; -import { isNumber } from 'lodash'; +import isNumber from 'lodash/isNumber'; // The type of a path export type StorePath = (string|number)[]; diff --git a/src/data/storeUtils.ts b/src/data/storeUtils.ts index 7b6092d0c2b..5186fde2e09 100644 --- a/src/data/storeUtils.ts +++ b/src/data/storeUtils.ts @@ -15,7 +15,7 @@ import { Name, } from 'graphql'; -import { isObject } from 'lodash'; +import isObject from 'lodash/isObject'; function isStringValue(value: Value): value is StringValue { return value.kind === 'StringValue'; diff --git a/src/queries/queryTransform.ts b/src/queries/queryTransform.ts index ca3d123e9b7..7f5da94decd 100644 --- a/src/queries/queryTransform.ts +++ b/src/queries/queryTransform.ts @@ -11,7 +11,7 @@ import { checkDocument, } from './getFromAST'; -import { cloneDeep } from 'lodash'; +import cloneDeep from 'lodash/cloneDeep'; const TYPENAME_FIELD: Field = { kind: 'Field', diff --git a/src/store.ts b/src/store.ts index 2edab02c01c..f746f8731df 100644 --- a/src/store.ts +++ b/src/store.ts @@ -45,7 +45,7 @@ import { CustomResolverMap, } from './data/readFromStore'; -import { assign } from 'lodash'; +import assign from 'lodash/assign'; export interface Store { data: NormalizedCache; diff --git a/src/transport/batchedNetworkInterface.ts b/src/transport/batchedNetworkInterface.ts index c063372e1a3..86de70a136e 100644 --- a/src/transport/batchedNetworkInterface.ts +++ b/src/transport/batchedNetworkInterface.ts @@ -4,7 +4,8 @@ import { import 'whatwg-fetch'; -import { assign, isNumber } from 'lodash'; +import assign from 'lodash/assign'; +import isNumber from 'lodash/isNumber'; import { HTTPFetchNetworkInterface, diff --git a/src/transport/networkInterface.ts b/src/transport/networkInterface.ts index 8c01b8159f9..e594b1369d8 100644 --- a/src/transport/networkInterface.ts +++ b/src/transport/networkInterface.ts @@ -1,4 +1,7 @@ -import { isString, assign, mapValues } from 'lodash'; +import isString from 'lodash/isString'; +import assign from 'lodash/assign'; +import mapValues from 'lodash/mapValues'; + import 'whatwg-fetch'; import { From a781301c112cc2d6ccf31523ffcff191f05c7e9c Mon Sep 17 00:00:00 2001 From: urigo Date: Thu, 22 Dec 2016 14:30:41 +0200 Subject: [PATCH 03/18] Fix circular dependencies Note: Typescript files with only types, are used only in compilation phase and not going to be imported on compiled javascript. Closes #1074 --- src/ApolloClient.ts | 5 ++- src/core/ObservableQuery.ts | 5 ++- src/core/QueryManager.ts | 60 +++++++++--------------------------- src/core/types.ts | 43 ++++++++++++++++++++++++++ src/index.ts | 2 +- src/optimistic-data/store.ts | 12 ++++++-- src/scheduler/scheduler.ts | 7 +++-- src/store.ts | 11 ++----- 8 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 src/core/types.ts diff --git a/src/ApolloClient.ts b/src/ApolloClient.ts index 65d2895d85e..92d00f5388f 100644 --- a/src/ApolloClient.ts +++ b/src/ApolloClient.ts @@ -30,10 +30,13 @@ import { import { QueryManager, +} from './core/QueryManager'; + +import { ApolloQueryResult, ResultComparator, ResultTransformer, -} from './core/QueryManager'; +} from './core/types'; import { ObservableQuery, diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index 2c7bac6008b..c35d0373e42 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -17,9 +17,12 @@ import { import { QueryManager, +} from './QueryManager'; + +import { ApolloQueryResult, FetchType, -} from './QueryManager'; +} from './types'; import { tryFunctionOrLogError } from '../util/errorHandling'; diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 4433c0449e6..9848312d115 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -11,6 +11,20 @@ import { import forOwn from 'lodash/forOwn'; import isEqual from 'lodash/isEqual'; +import { + ResultTransformer, + ResultComparator, + QueryListener, + ApolloQueryResult, + FetchType, + SubscriptionOptions, +} from './types'; + +import { + QueryStoreValue, + NetworkStatus, +} from '../queries/store'; + import { ApolloStore, Store, @@ -18,10 +32,6 @@ import { ApolloReducerConfig, } from '../store'; -import { - QueryStoreValue, -} from '../queries/store'; - import { checkDocument, getQueryDefinition, @@ -82,10 +92,6 @@ import { Observable, } from '../util/Observable'; -import { - NetworkStatus, -} from '../queries/store'; - import { tryFunctionOrLogError } from '../util/errorHandling'; import { @@ -97,44 +103,6 @@ import { WatchQueryOptions } from './watchQueryOptions'; import { ObservableQuery } from './ObservableQuery'; -export type QueryListener = (queryStoreValue: QueryStoreValue) => void; - -export interface SubscriptionOptions { - document: Document; - variables?: { [key: string]: any }; -}; - -export type ApolloQueryResult = { - data: any; - loading: boolean; - networkStatus: NetworkStatus; - - // This type is different from the GraphQLResult type because it doesn't include errors. - // Those are thrown via the standard promise/observer catch mechanism. -}; - -// A result transformer is given the data that is to be returned from the store from a query or -// mutation, and can modify or observe it before the value is provided to your application. -// -// For watched queries, the transformer is only called when the data retrieved from the server is -// different from previous. -// -// If the transformer wants to mutate results (say, by setting the prototype of result data), it -// will likely need to be paired with a custom resultComparator. By default, Apollo performs a -// deep equality comparsion on results, and skips those that are considered equal - reducing -// re-renders. -export type ResultTransformer = (resultData: ApolloQueryResult) => ApolloQueryResult; - -// Controls how Apollo compares two query results and considers their equality. Two equal results -// will not trigger re-renders. -export type ResultComparator = (result1: ApolloQueryResult, result2: ApolloQueryResult) => boolean; - -export enum FetchType { - normal = 1, - refetch = 2, - poll = 3, -} - export class QueryManager { public pollingTimers: {[queryId: string]: NodeJS.Timer | any}; //oddity in Typescript public scheduler: QueryScheduler; diff --git a/src/core/types.ts b/src/core/types.ts new file mode 100644 index 00000000000..68736a36768 --- /dev/null +++ b/src/core/types.ts @@ -0,0 +1,43 @@ +import { Document } from 'graphql'; +import { + QueryStoreValue, + NetworkStatus, +} from '../queries/store'; + +export interface SubscriptionOptions { + document: Document; + variables?: { [key: string]: any }; +}; + +export type QueryListener = (queryStoreValue: QueryStoreValue) => void; + +export type ApolloQueryResult = { + data: any; + loading: boolean; + networkStatus: NetworkStatus; + + // This type is different from the GraphQLResult type because it doesn't include errors. + // Those are thrown via the standard promise/observer catch mechanism. +}; + +// A result transformer is given the data that is to be returned from the store from a query or +// mutation, and can modify or observe it before the value is provided to your application. +// +// For watched queries, the transformer is only called when the data retrieved from the server is +// different from previous. +// +// If the transformer wants to mutate results (say, by setting the prototype of result data), it +// will likely need to be paired with a custom resultComparator. By default, Apollo performs a +// deep equality comparsion on results, and skips those that are considered equal - reducing +// re-renders. +export type ResultTransformer = (resultData: ApolloQueryResult) => ApolloQueryResult; + +// Controls how Apollo compares two query results and considers their equality. Two equal results +// will not trigger re-renders. +export type ResultComparator = (result1: ApolloQueryResult, result2: ApolloQueryResult) => boolean; + +export enum FetchType { + normal = 1, + refetch = 2, + poll = 3, +} diff --git a/src/index.ts b/src/index.ts index 347cc4a9827..e434fbfd918 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,7 +65,7 @@ import ApolloClient from './ApolloClient'; import { ApolloQueryResult, -} from './core/QueryManager'; +} from './core/types'; import { toIdValue, diff --git a/src/optimistic-data/store.ts b/src/optimistic-data/store.ts index 3f5b9df64bd..8fb2d4119f8 100644 --- a/src/optimistic-data/store.ts +++ b/src/optimistic-data/store.ts @@ -14,10 +14,10 @@ import { } from '../data/storeUtils'; import { - getDataWithOptimisticResults, Store, } from '../store'; +import assign from 'lodash/assign'; import pick from 'lodash/pick'; // a stack of patches of new or changed documents @@ -28,6 +28,14 @@ export type OptimisticStore = { const optimisticDefaultState: any[] = []; +export function getDataWithOptimisticResults(store: Store): NormalizedCache { + if (store.optimistic.length === 0) { + return store.data; + } + const patches = store.optimistic.map(opt => opt.data); + return assign({}, store.data, ...patches) as NormalizedCache; +} + export function optimistic( previousState = optimisticDefaultState, action: any, @@ -49,7 +57,7 @@ export function optimistic( const fakeStore = { ...store, optimistic: previousState, - } as Store; + }; const optimisticData = getDataWithOptimisticResults(fakeStore); const fakeDataResultState = data( optimisticData, diff --git a/src/scheduler/scheduler.ts b/src/scheduler/scheduler.ts index c0928befe58..1a326970ba6 100644 --- a/src/scheduler/scheduler.ts +++ b/src/scheduler/scheduler.ts @@ -10,10 +10,13 @@ import { QueryManager, - QueryListener, - FetchType, } from '../core/QueryManager'; +import { + FetchType, + QueryListener, +} from '../core/types'; + import { ObservableQuery } from '../core/ObservableQuery'; import { WatchQueryOptions } from '../core/watchQueryOptions'; diff --git a/src/store.ts b/src/store.ts index f746f8731df..f68b9f8784e 100644 --- a/src/store.ts +++ b/src/store.ts @@ -27,7 +27,9 @@ import { import { optimistic, OptimisticStore, + getDataWithOptimisticResults, } from './optimistic-data/store'; +export { getDataWithOptimisticResults }; import { ApolloAction, @@ -184,17 +186,8 @@ export function createApolloStore({ ); } - export type ApolloReducerConfig = { dataIdFromObject?: IdGetter; mutationBehaviorReducers?: MutationBehaviorReducerMap; customResolvers?: CustomResolverMap; }; - -export function getDataWithOptimisticResults(store: Store): NormalizedCache { - if (store.optimistic.length === 0) { - return store.data; - } - const patches = store.optimistic.map(opt => opt.data); - return assign({}, store.data, ...patches) as NormalizedCache; -} From cc52b4684e896216752b77c41fbb6c5e38ef0f05 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:20:16 +0100 Subject: [PATCH 04/18] Compile to commonjs with babel This way we avoid an issue with require('lodash/someFunction').default() --- .babelrc | 8 ++++++++ package.json | 4 +++- tsconfig.test.json | 14 -------------- 3 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 .babelrc delete mode 100644 tsconfig.test.json diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000000..caa233040a6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,8 @@ +{ + "plugins": [ + "transform-es2015-modules-commonjs" + ], + "ignore": [ + "lib/**/*.d.ts" + ] +} diff --git a/package.json b/package.json index 6b32aedbec3..b1f64669098 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "posttest": "npm run lint", "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=38", "compile": "tsc", - "compile:test": "tsc -p tsconfig.test.json", + "compile:test": "npm run compile && babel lib --out-dir lib", "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/src/index.js -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", @@ -53,6 +53,8 @@ "devDependencies": { "@types/chai-as-promised": "0.0.28", "@types/mocha": "^2.2.31", + "babel-cli": "^6.18.0", + "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", "browserify": "^13.0.0", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index d88aede9dec..00000000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "commonjs" - }, - "files": [ - "node_modules/typescript/lib/lib.es2015.d.ts", - "node_modules/typescript/lib/lib.dom.d.ts", - "typings.d.ts", - "fetch-mock.typings.d.ts", - "src/index.ts", - "test/tests.ts" - ] -} From 0b2c92ca34d3ba364e38a37985746d3c14b90ab7 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:24:00 +0100 Subject: [PATCH 05/18] Inlude mising tests --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 36df1d7f256..29b8708907b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,6 +19,7 @@ "node_modules/typescript/lib/lib.dom.d.ts", "typings.d.ts", "fetch-mock.typings.d.ts", - "src/index.ts" + "src/index.ts", + "test/tests.ts" ] } From bc00bacfccb88ba806e65bc12ec89778a666c4c1 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:24:35 +0100 Subject: [PATCH 06/18] Exclude bundle from babel --- .babelrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index caa233040a6..1448a22462d 100644 --- a/.babelrc +++ b/.babelrc @@ -3,6 +3,7 @@ "transform-es2015-modules-commonjs" ], "ignore": [ - "lib/**/*.d.ts" + "lib/**/*.d.ts", + "lib/bundles/**" ] } From 87d2e830d791e88ef4f83052228b2228f447bbb9 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:33:35 +0100 Subject: [PATCH 07/18] Fix missing ApolloQueryResult in tests --- test/QueryManager.ts | 2 +- test/util/observableToPromise.ts | 2 +- test/util/subscribeAndCount.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/QueryManager.ts b/test/QueryManager.ts index a0a9fc2414b..987753368bf 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -36,7 +36,7 @@ import ApolloClient, { import { ApolloQueryResult, -} from '../src/core/QueryManager'; +} from '../src/core/types'; import { createStore, combineReducers, applyMiddleware } from 'redux'; diff --git a/test/util/observableToPromise.ts b/test/util/observableToPromise.ts index 8d719ed7396..d30715ed6a3 100644 --- a/test/util/observableToPromise.ts +++ b/test/util/observableToPromise.ts @@ -1,5 +1,5 @@ import { ObservableQuery } from '../../src/core/ObservableQuery'; -import { ApolloQueryResult } from '../../src/core/QueryManager'; +import { ApolloQueryResult } from '../../src/core/types'; import { Subscription } from '../../src/util/Observable'; /** diff --git a/test/util/subscribeAndCount.ts b/test/util/subscribeAndCount.ts index 7083d97c490..7e85602d3a1 100644 --- a/test/util/subscribeAndCount.ts +++ b/test/util/subscribeAndCount.ts @@ -1,5 +1,5 @@ import { ObservableQuery } from '../../src/core/ObservableQuery'; -import { ApolloQueryResult } from '../../src/core/QueryManager'; +import { ApolloQueryResult } from '../../src/core/types'; import { Subscription } from '../../src/util/Observable'; import wrap from './wrap'; From db0640290658064962231db2e62f816ca091f83b Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:52:46 +0100 Subject: [PATCH 08/18] Fix tests --- .babelrc | 3 ++- test/client.ts | 2 +- test/networkInterface.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.babelrc b/.babelrc index 1448a22462d..71c8a7f4b05 100644 --- a/.babelrc +++ b/.babelrc @@ -4,6 +4,7 @@ ], "ignore": [ "lib/**/*.d.ts", - "lib/bundles/**" + "lib/bundles/**", + "node_modules/**" ] } diff --git a/test/client.ts b/test/client.ts index 2b9ed25be50..92b9b54c092 100644 --- a/test/client.ts +++ b/test/client.ts @@ -66,7 +66,7 @@ import { createMockedIResponse, } from './mocks/mockFetch'; -import * as chaiAsPromised from 'chai-as-promised'; +import chaiAsPromised from 'chai-as-promised'; import { ApolloError } from '../src/errors/ApolloError'; diff --git a/test/networkInterface.ts b/test/networkInterface.ts index 81da9d4cf26..48244457b00 100644 --- a/test/networkInterface.ts +++ b/test/networkInterface.ts @@ -1,8 +1,8 @@ import * as chai from 'chai'; -import * as chaiAsPromised from 'chai-as-promised'; +import chaiAsPromised from 'chai-as-promised'; import { assign, isEqual } from 'lodash'; -import * as fetchMock from 'fetch-mock'; +import fetchMock from 'fetch-mock'; // make it easy to assert with promises chai.use(chaiAsPromised); From d960c6afe8dfb452931980c227a2fcf1661dc175 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 19:57:41 +0100 Subject: [PATCH 09/18] Compile with sourcemaps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1f64669098..17963c2fa56 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "posttest": "npm run lint", "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=38", "compile": "tsc", - "compile:test": "npm run compile && babel lib --out-dir lib", + "compile:test": "npm run compile && babel lib --out-dir lib --source-maps", "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/src/index.js -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", From f542f1495460badf2c544ed0aacc665a2a5d6cf5 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 21:44:11 +0100 Subject: [PATCH 10/18] Make everything ready to npm publish --- .npmignore | 1 - package.json | 4 ++-- rollup.config.js | 3 ++- scripts/deploy.sh | 7 +++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.npmignore b/.npmignore index d00b10f93a1..0c225678fa0 100644 --- a/.npmignore +++ b/.npmignore @@ -10,6 +10,5 @@ design.md Gruntfile.js rollup.config.js tsconfig.json -tsconfig.test.json tslint.json typings.json diff --git a/package.json b/package.json index 17963c2fa56..b9ba8245bf8 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "apollo-client", "version": "0.5.26", "description": "A simple yet functional GraphQL client.", - "main": "./lib/bundles/apollo.umd.js", + "main": "./lib/apollo.umd.js", "module": "./lib/src/index.js", "typings": "./lib/src/index.d.ts", "scripts": { "dev": "./scripts/dev.sh", - "deploy": "rm -rf ./lib && npm run compile && ./scripts/deploy.sh", + "deploy": "rm -rf ./lib && ./scripts/deploy.sh", "pretest": "npm run compile:test", "test": "npm run testonly --", "posttest": "npm run lint", diff --git a/rollup.config.js b/rollup.config.js index 7ffdb60f839..2617b65d9bc 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,8 @@ export default { entry: 'lib/src/index.js', - dest: 'lib/bundles/apollo.umd.js', + dest: 'lib/apollo.umd.js', format: 'umd', + sourceMap: true, moduleName: 'apollo', globals: { 'lodash': '_' diff --git a/scripts/deploy.sh b/scripts/deploy.sh index c77d9fddf15..c1362251c87 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,13 +11,16 @@ npm run compile rm -rf ./npm mkdir ./npm -cd ./lib/src && cp -r ./ ../../npm/ && cd ../../ +cd ./lib/src && cp -r ./ ../../npm/ && cd ../ +cp apollo.umd.js ../npm/ && cp apollo.umd.js.map ../npm/ && cd ../ # Ensure a vanilla package.json before deploying so other tools do not interpret # The built output as requiring any further transformation. node -e "var package = require('./package.json'); \ delete package.babel; delete package.scripts; delete package.options; \ - package.main = 'index.js'; \ + package.main = 'apollo.umd.js'; \ + package.module = 'index.js'; \ + package.typings = 'index.d.ts'; \ var fs = require('fs'); \ fs.writeFileSync('./npm/version.js', 'exports.version = \"' + package.version + '\"'); \ fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2));" From 696e2ed2b906da5141289ee6d865019636bf5df7 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 22 Dec 2016 21:57:35 +0100 Subject: [PATCH 11/18] Use UMD bundle to filesize check --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9ba8245bf8..7b76ef5f850 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=38", "compile": "tsc", "compile:test": "npm run compile && babel lib --out-dir lib --source-maps", - "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/src/index.js -o=./dist/index.js && npm run minify:browser", + "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/apollo.umd.js -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", "bundle": "rollup -c", From 5fe7970cf0f0d05426e15409082da392e066c43a Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 09:29:30 +0100 Subject: [PATCH 12/18] Fix wrong function usage in test --- test/mutationResults.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mutationResults.ts b/test/mutationResults.ts index 7c2cc7e0f91..678322721df 100644 --- a/test/mutationResults.ts +++ b/test/mutationResults.ts @@ -798,7 +798,7 @@ describe('mutation results', () => { reducer: (previousResult, action, variables: any) => { counter++; if (isMutationResultAction(action) && variables['id'] === 5) { - const newResult = clonedeep(previousResult) as any; + const newResult = cloneDeep(previousResult) as any; newResult.todoList.todos.unshift(action.result.data.createTodo); return newResult; } From 6ad6da8d782d5877932e0edde0531c4705454ab0 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 09:29:50 +0100 Subject: [PATCH 13/18] Add lodash to globals in rollup --- rollup.config.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 2617b65d9bc..8a1856fce72 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,12 @@ +function globals(mod) { + if (mod.indexOf('lodash/') === 0) return '_'; +} + export default { entry: 'lib/src/index.js', dest: 'lib/apollo.umd.js', format: 'umd', sourceMap: true, moduleName: 'apollo', - globals: { - 'lodash': '_' - } + globals }; From fa58b1f337203e162f439911ffa8b1d356c9bcdd Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 17:34:44 +0100 Subject: [PATCH 14/18] Make code coverage works --- package.json | 17 ++++++++--------- rollup.config.js | 8 +++----- src/data/debug.ts | 1 - 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 7b76ef5f850..068553eaba8 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,11 @@ "scripts": { "dev": "./scripts/dev.sh", "deploy": "rm -rf ./lib && ./scripts/deploy.sh", - "pretest": "npm run compile:test", + "pretest": "npm run compile", "test": "npm run testonly --", "posttest": "npm run lint", "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=38", "compile": "tsc", - "compile:test": "npm run compile && babel lib --out-dir lib --source-maps", "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/apollo.umd.js -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", @@ -21,9 +20,9 @@ "postcompile": "npm run bundle", "prepublish": "npm run compile", "lint": "grunt tslint", - "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace lib/test/tests.js", - "postcoverage": "remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info", - "testonly": "mocha --reporter spec --full-trace lib/test/tests.js", + "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --compilers js:babel-core/register --reporter dot --full-trace lib/test/tests.js", + "postcoverage": "remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info", + "testonly": "mocha --compilers js:babel-core/register --reporter spec --full-trace lib/test/tests.js", "preanalyze": "npm run compile", "analyze": "webpack -p --config analyze/webpack.config.js" }, @@ -53,7 +52,7 @@ "devDependencies": { "@types/chai-as-promised": "0.0.28", "@types/mocha": "^2.2.31", - "babel-cli": "^6.18.0", + "babel-core": "^6.21.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", "browserify": "^13.0.0", "chai": "^3.5.0", @@ -65,14 +64,14 @@ "grunt-tslint": "4.0.0", "gzip-size": "^3.0.0", "isomorphic-fetch": "^2.2.1", - "istanbul": "^0.4.5", + "istanbul": "^1.0.0-alpha", "lodash": "^4.17.1", "minimist": "^1.2.0", "mocha": "^3.0.0", "pretty-bytes": "^4.0.0", "remap-istanbul": "0.8.0", "request": "^2.75.0", - "rollup": "^0.37.0", + "rollup": "^0.40.0", "rxjs": "^5.0.0-beta.11", "sinon": "^1.17.4", "source-map-support": "^0.4.0", @@ -86,7 +85,7 @@ "@types/async": "^2.0.31", "@types/chai": "^3.4.32", "@types/isomorphic-fetch": "0.0.30", - "@types/lodash": "^4.14.34", + "@types/lodash": "4.14.42", "@types/node": "^6.0.38", "@types/promises-a-plus": "0.0.26", "@types/redux": "^3.5.29", diff --git a/rollup.config.js b/rollup.config.js index 8a1856fce72..d02362f1814 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,12 +1,10 @@ -function globals(mod) { - if (mod.indexOf('lodash/') === 0) return '_'; -} - export default { entry: 'lib/src/index.js', dest: 'lib/apollo.umd.js', format: 'umd', sourceMap: true, moduleName: 'apollo', - globals + external: [ + 'lodash' + ] }; diff --git a/src/data/debug.ts b/src/data/debug.ts index 7a874984e2f..fdc9e6b508a 100644 --- a/src/data/debug.ts +++ b/src/data/debug.ts @@ -1,5 +1,4 @@ // For development only! -// import { isObject, omit, mapValues } from 'lodash'; import isObject from 'lodash/isObject'; import omit from 'lodash/omit'; import mapValues from 'lodash/mapValues'; From 5ba7fe5000332103ece0dd570d6f692b193d9af5 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 17:41:43 +0100 Subject: [PATCH 15/18] Add jsnext:main --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 068553eaba8..abcea5deda3 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A simple yet functional GraphQL client.", "main": "./lib/apollo.umd.js", "module": "./lib/src/index.js", + "jsnext:main": "./lib/src/index.js", "typings": "./lib/src/index.d.ts", "scripts": { "dev": "./scripts/dev.sh", From ecef360fb7b12d36124bc2990e536f1567ef5c81 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 17:50:07 +0100 Subject: [PATCH 16/18] Define globals for lodash in rollup --- rollup.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index d02362f1814..1572acc2841 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,7 @@ +function globals(mod) { + if (mod.indexOf('lodash/') === 0) return '_'; +} + export default { entry: 'lib/src/index.js', dest: 'lib/apollo.umd.js', @@ -6,5 +10,6 @@ export default { moduleName: 'apollo', external: [ 'lodash' - ] + ], + globals }; From c90a749c08ff9300e173cebeff87aafac02890d3 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 18:01:19 +0100 Subject: [PATCH 17/18] Update to redux@3.4.0 This way we avoid using @types/redux and we use official typescript definition instead --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index abcea5deda3..ad9d15843b0 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "graphql-anywhere": "^1.0.0", "graphql-tag": "^1.1.1", "lodash": "^4.17.2", - "redux": "^3.3.1", + "redux": "^3.4.0", "symbol-observable": "^1.0.2", "whatwg-fetch": "^2.0.0" }, @@ -89,7 +89,6 @@ "@types/lodash": "4.14.42", "@types/node": "^6.0.38", "@types/promises-a-plus": "0.0.26", - "@types/redux": "^3.5.29", "@types/sinon": "^1.16.29", "typed-graphql": "1.0.2" } From c42b761b24efc691d5f3d7e3239fe4c4b7fdc353 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 4 Jan 2017 18:08:11 +0100 Subject: [PATCH 18/18] Add recent changes to the changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c6f5969ae..de0956f90e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Expect active development and potentially significant breaking changes in the `0 - ... +- Support AMD [PR #1069](https://github.com/apollostack/apollo-client/pull/1069) +- Support ES6 Modules and tree-shaking (`module`, `jsnext:main`) [PR #1069](https://github.com/apollostack/apollo-client/pull/1069) +- Replace `@types/redux` with official typescript definitions [PR #1069](https://github.com/apollostack/apollo-client/pull/1069) + - Remove fragment option from query, watchQuery etc. [PR #1096](https://github.com/apollostack/apollo-client/pull/1096) - Broadcast new store state only when Apollo state was affected by an action [PR #1118](https://github.com/apollostack/apollo-client/pull/1118)