From 634e9bb2d739c8d1fde8a9aeb85ba383a502c86a Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 12 Aug 2017 12:39:18 +0200 Subject: [PATCH 1/4] Release v0.6.0-rc.1 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0532b2b..1338968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change log -### vNEXT +### v0.6.0-rc.1 ### v0.5.2 diff --git a/package.json b/package.json index 5cf71d2..40adf0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-client-rxjs", - "version": "0.5.2", + "version": "0.6.0-rc.1", "description": "Adds RxJS to ApolloClient", "author": "Kamil Kisiela ", "license": "MIT", From 0f29b09e68ae33d879014277e9d4e147e56d4ba8 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 12 Aug 2017 13:02:33 +0200 Subject: [PATCH 2/4] Fix an issue with lift method in TypeScript 2.4 (#47) * Fix an issue with lift method in TypeScript 2.4 * Add it to changelog --- .gitignore | 2 ++ .vscode/settings.json | 2 +- CHANGELOG.md | 3 ++ package.json | 40 ++++++++++----------- rollup.config.js | 44 +++++++++++++++-------- src/RxObservableQuery.ts | 6 ++-- src/utils/variables.ts | 2 +- tests/RxApolloClient/watchQuery.ts | 8 ++--- tests/RxObservableQuery.ts | 39 +++++++++++++++----- tests/rxify.ts | 11 ++++-- tests/utils/variables/observeVariables.ts | 20 +++++------ tsconfig.json | 2 +- tslint.json | 2 +- 13 files changed, 115 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 8f09ef4..df77f70 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ build/ coverage/ node_modules/ npm-debug.log +package-lock.json +yarn.lock diff --git a/.vscode/settings.json b/.vscode/settings.json index e676897..9e5f4b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "files.exclude": { "**/.git": true, "**/.DS_Store": true, - "node_modules/**": true, + "node_modules": true, "build": true, "coverage": true }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 1338968..7fffdad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### v0.6.0-rc.1 +- Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) + ### v0.5.2 - Support `v1.0.0-rc.2` of `apollo-client` [PR #39](https://github.com/kamilkisiela/apollo-client-rxjs/pull/39) diff --git a/package.json b/package.json index 40adf0f..fc818e1 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "test-watch": "mocha --reporter spec --full-trace build/tests/index.js --watch", "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace build/tests/index.js", "postcoverage": "remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info", - "lint": "tslint src/**/*.ts && tslint tests/*.ts", + "lint": "tslint src/**/*.ts && tslint tests/**/*.ts", "prebuild": "npm run clean:build", "build": "tsc", "build-test": "tsc -p tsconfig.test.json", @@ -42,29 +42,29 @@ "prepublish": "npm run clean && npm run build" }, "peerDependencies": { - "apollo-client": ">=0.7.2 <=0.10.1 || >=1.0.0-beta <2.0.0", - "rxjs": "^5.0.0-beta.12 || ^5.0.0-rc.1 || ^5.0.0" + "apollo-client": ">=1.0.0-beta <2.0.0", + "rxjs": "^5.0.0-beta.12 || >=5.0.0-rc.1 <6.0.0" }, "devDependencies": { - "@types/chai": "^3.4.35", - "@types/mocha": "^2.2.40", - "@types/node": "^6.0.38", - "@types/sinon": "^1.16.35", - "apollo-client": "^1.0.0-rc.2", - "apollo-test-utils": "^0.2.0", - "chai": "^3.5.0", - "graphql": "^0.9.1", - "graphql-tag": "^1.3.1", + "@types/chai": "^4.0.2", + "@types/mocha": "^2.2.41", + "@types/node": "^8.0.20", + "@types/sinon": "^2.3.3", + "apollo-client": "^1.9.1", + "apollo-test-utils": "^0.3.2", + "chai": "^4.1.1", + "graphql": "^0.10.5", + "graphql-tag": "^2.4.2", "isomorphic-fetch": "^2.2.1", "istanbul": "^0.4.5", - "mocha": "^3.2.0", - "remap-istanbul": "^0.9.1", + "mocha": "^3.5.0", + "remap-istanbul": "^0.9.5", "rimraf": "^2.6.1", - "rollup": "^0.41.5", - "rxjs": "^5.2.0", - "sinon": "^2.0.0", - "source-map-support": "^0.4.12", - "tslint": "^4.5.1", - "typescript": "^2.2.1" + "rollup": "^0.45.2", + "rxjs": "^5.4.2", + "sinon": "^3.2.0", + "source-map-support": "^0.4.15", + "tslint": "^5.6.0", + "typescript": "^2.4.2" } } diff --git a/rollup.config.js b/rollup.config.js index 080f2fa..3e91a5f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,23 +1,39 @@ +const globals = { + 'apollo-client': 'apollo', + 'rxjs/Observable': 'Rx', + 'rxjs/Observer': 'Rx', + 'rxjs/Subscription': 'Rx', + 'rxjs/Subscriber': 'Rx', + 'rxjs/Operator': 'Rx', + + 'rxjs/symbol/observable': 'Rx.Symbol', + + 'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async', + + 'rxjs/observable/combineLatest': 'Rx.Observable', + + 'rxjs/operator/observeOn': 'Rx.Observable.prototype', + 'rxjs/operator/switchMap': 'Rx.Observable.prototype' +} + export default { entry: 'build/src/index.js', dest: 'build/bundles/apollo-rxjs.umd.js', format: 'umd', + sourceMap: true, + exports: 'named', moduleName: 'apollo.rxjs', - globals: { - 'apollo-client': 'apollo', - 'rxjs/Observable': 'Rx', - 'rxjs/Observer': 'Rx', - 'rxjs/Subscription': 'Rx', - 'rxjs/Subscriber': 'Rx', - 'rxjs/Operator': 'Rx', - - 'rxjs/symbol/observable': 'Rx.Symbol', - - 'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async', + globals, + onwarn +} - 'rxjs/observable/combineLatest': 'Rx.Observable', +function onwarn(message) { + const suppressed = [ + 'UNRESOLVED_IMPORT', + 'THIS_IS_UNDEFINED' + ]; - 'rxjs/operator/observeOn': 'Rx.Observable.prototype', - 'rxjs/operator/switchMap': 'Rx.Observable.prototype' + if (!suppressed.find(code => message.code === code)) { + return console.warn(message.message); } } diff --git a/src/RxObservableQuery.ts b/src/RxObservableQuery.ts index 0e93b16..ebbfeb6 100644 --- a/src/RxObservableQuery.ts +++ b/src/RxObservableQuery.ts @@ -19,13 +19,13 @@ export class RxObservableQuery extends Observable> { } } - public lift(operator: Operator, ApolloQueryResult>): Observable> { + public lift(operator: Operator, R>): Observable { const observable = new RxObservableQuery(this.apollo); observable.source = this; - observable.operator = operator; + observable.operator = operator as any; - return observable; + return observable as any; } // apollo-specific methods diff --git a/src/utils/variables.ts b/src/utils/variables.ts index fc440b0..d9ee209 100644 --- a/src/utils/variables.ts +++ b/src/utils/variables.ts @@ -46,7 +46,7 @@ export function observeVariables(variables?: Object): Observable { observer.next(resultVariables); }); }); -}; +} function mapVariablesToObservables(variables?: Object): Observable[] { return Object.keys(variables) diff --git a/tests/RxApolloClient/watchQuery.ts b/tests/RxApolloClient/watchQuery.ts index 27ecf15..bc2b0be 100644 --- a/tests/RxApolloClient/watchQuery.ts +++ b/tests/RxApolloClient/watchQuery.ts @@ -12,7 +12,7 @@ describe('RxApolloClient.watchQuery', () => { it('should get the result', (done) => { const obs = client.watchQuery({ - query: heroes.query + query: heroes.query, }); obs.subscribe({ @@ -22,13 +22,13 @@ describe('RxApolloClient.watchQuery', () => { }, error() { done(new Error('should not be called')); - } + }, }); }); it('should be able to refetch', (done) => { const obs = client.watchQuery({ - query: heroes.query + query: heroes.query, }); obs.subscribe({ @@ -37,7 +37,7 @@ describe('RxApolloClient.watchQuery', () => { }, error() { done(new Error('should not be called')); - } + }, }); obs.refetch(heroes.variables).then(({data}) => { diff --git a/tests/RxObservableQuery.ts b/tests/RxObservableQuery.ts index 5639fe3..82f27f2 100644 --- a/tests/RxObservableQuery.ts +++ b/tests/RxObservableQuery.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; import { spy, stub } from 'sinon'; -import { ApolloClient, ObservableQuery } from 'apollo-client'; +import { ApolloClient, ObservableQuery, ApolloQueryResult } from 'apollo-client'; import * as heroes from './fixtures/heroes'; import { RxObservableQuery } from '../src/RxObservableQuery'; @@ -8,6 +8,7 @@ import { ObservableQueryRef } from '../src/utils/ObservableQueryRef'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/filter'; describe('RxObservableQuery', () => { let obsQuery: ObservableQuery; @@ -56,7 +57,9 @@ describe('RxObservableQuery', () => { }); it('should be able to use a operator', (done: MochaDone) => { - rxObsQuery.map(result => result.data).subscribe({ + rxObsQuery + .map(result => result.data) + .subscribe({ next(result) { assert.deepEqual(result, heroes.data); done(); @@ -67,6 +70,26 @@ describe('RxObservableQuery', () => { }); }); + it('should be able to use multiple operators', (done: MochaDone) => { + function onlyFoo(hero: heroes.Hero): boolean { + return !!hero.name.match(/foo/i); + } + + rxObsQuery + .map, heroes.Hero[]> + (result => result.data.allHeroes.heroes) + .map(heroes => heroes.filter(onlyFoo)) + .subscribe({ + next(result) { + assert.deepEqual(result, heroes.data.allHeroes.heroes.filter(onlyFoo)); + done(); + }, + error() { + done(new Error('should not be called')); + }, + }); + }); + it('should be chainable', (done: MochaDone) => { const counter = { calls: 0 }; @@ -97,7 +120,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.refetch(heroes.variables); assert.deepEqual(stubbed.args[0], [heroes.variables]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to startPolling', () => { @@ -121,7 +144,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.fetchMore(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to subscribeToMore', () => { @@ -130,7 +153,7 @@ describe('RxObservableQuery', () => { const fn = rxObsQuery.subscribeToMore(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(fn, 'fn'); + assert.equal(fn, 'fn' as any); }); it('should be able to updateQuery', () => { @@ -148,7 +171,7 @@ describe('RxObservableQuery', () => { stub(obsQuery, 'result').returns('promise'); const promise = rxObsQuery.result(); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to use currentResult', () => { @@ -168,7 +191,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.setOptions(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to setVariables', () => { @@ -177,7 +200,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.setVariables(variables); assert.deepEqual(stubbed.args[0], [variables, false]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); }); }); diff --git a/tests/rxify.ts b/tests/rxify.ts index 787ba33..2b098e6 100644 --- a/tests/rxify.ts +++ b/tests/rxify.ts @@ -3,6 +3,7 @@ import { Subject } from 'rxjs/Subject'; import { ApolloClient } from 'apollo-client'; import { rxify } from '../src/rxify'; +import { RxObservableQuery } from '../src/RxObservableQuery'; import * as heroes from './fixtures/heroes'; @@ -37,8 +38,12 @@ describe('rxify', () => { }); describe('watchQuery', () => { + const watchQuery = (options: Object): RxObservableQuery => { + return new RxObservableQuery(rxify(client.watchQuery)(options)); + }; + it('should be able to subscribe', (done) => { - rxify(client.watchQuery)({ query: heroes.query }) + watchQuery({ query: heroes.query }) .map(result => result.data) .subscribe({ next(data) { @@ -54,7 +59,7 @@ describe('rxify', () => { it('should be able to use observable variables', (done) => { const hero = new Subject(); - const obs = rxify(client.watchQuery)({ + const obs = watchQuery({ query: heroes.queryWithVariables, variables: { hero }, }); @@ -75,7 +80,7 @@ describe('rxify', () => { it('should be able to use operator and observable variables', (done) => { const hero = new Subject(); - const obs = rxify(client.watchQuery)({ + const obs = watchQuery({ query: heroes.queryWithVariables, variables: { hero }, }).map(result => result.data); diff --git a/tests/utils/variables/observeVariables.ts b/tests/utils/variables/observeVariables.ts index 446f09c..8bd32a9 100644 --- a/tests/utils/variables/observeVariables.ts +++ b/tests/utils/variables/observeVariables.ts @@ -6,10 +6,10 @@ import { observeVariables } from '../../../src/utils/variables'; describe('observeVariables', () => { it('should handle primitive values', (done) => { const variables = { - foo: 'first' + foo: 'first', }; const result = { - foo: 'first' + foo: 'first', }; observeVariables(variables).subscribe((newVariables: any) => { @@ -25,9 +25,9 @@ describe('observeVariables', () => { }; const results = [{ - foo: 'first' + foo: 'first', }, { - foo: 'second' + foo: 'second', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -46,15 +46,15 @@ describe('observeVariables', () => { const counter = { calls: 0 }; const variables = { foo: new Subject(), - bar: new Subject() + bar: new Subject(), }; const results = [{ foo: 'foo 1', - bar: 'bar 1' + bar: 'bar 1', }, { foo: 'foo 1', - bar: 'bar 2' + bar: 'bar 2', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -86,7 +86,7 @@ describe('observeVariables', () => { }, { foo: 'foo 1', bar: 'bar 2', - baz: 'baz 1' + baz: 'baz 1', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -105,10 +105,10 @@ describe('observeVariables', () => { it('should transform undefined variables to be null', (done) => { const variables = { - foo: undefined + foo: undefined, }; const result = { - foo: null + foo: null, }; observeVariables(variables).subscribe((newVariables: any) => { diff --git a/tsconfig.json b/tsconfig.json index 9946f80..1120d27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": ["es6", "dom"], + "lib": ["es2015", "dom", "esnext.asynciterable"], "module": "es2015", "moduleResolution": "node", "removeComments": true, diff --git a/tslint.json b/tslint.json index 530e38d..a0eda3e 100644 --- a/tslint.json +++ b/tslint.json @@ -57,7 +57,7 @@ "no-switch-case-fall-through": true, "no-trailing-whitespace": true, "no-unused-expression": true, - "no-use-before-declare": true, + "no-use-before-declare": false, "no-var-keyword": true, "no-var-requires": true, "object-literal-sort-keys": false, From bd9edddfda1238f98224a187f0dcfe8153df6d8f Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 12 Aug 2017 13:09:30 +0200 Subject: [PATCH 3/4] Deploy script (#48) * Add it to changelog * Deploy script --- .gitignore | 1 + .npmignore | 2 ++ .vscode/settings.json | 3 ++- CHANGELOG.md | 4 ++++ package.json | 3 ++- scripts/deploy.sh | 46 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 scripts/deploy.sh diff --git a/.gitignore b/.gitignore index df77f70..989eef4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build/ coverage/ node_modules/ +npm/ npm-debug.log package-lock.json yarn.lock diff --git a/.npmignore b/.npmignore index c3429c9..c4bd052 100644 --- a/.npmignore +++ b/.npmignore @@ -2,8 +2,10 @@ build/tests/ src/ tests/ docs/ +scripts/ .travis.yml CHANGELOG.md +rollup.config.js tsconfig.json tsconfig.test.json tslint.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e5f4b3..9c7b24f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,8 @@ "**/.DS_Store": true, "node_modules": true, "build": true, - "coverage": true + "coverage": true, + "npm": true }, "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fffdad..b8747eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) - Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Add a deploy script to keep compiled filed in the root directory [PR #48](https://github.com/kamilkisiela/apollo-client-rxjs/pull/48) + ### v0.5.2 - Support `v1.0.0-rc.2` of `apollo-client` [PR #39](https://github.com/kamilkisiela/apollo-client-rxjs/pull/39) diff --git a/package.json b/package.json index fc818e1..b47f530 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "clean": "npm run clean:build && npm run clean:coverage", "clean:build": "rimraf build/*", "clean:coverage": "rimraf coverage/*", - "prepublish": "npm run clean && npm run build" + "prepare": "npm run clean && npm run build", + "deploy": "./scripts/deploy.sh" }, "peerDependencies": { "apollo-client": ">=1.0.0-beta <2.0.0", diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..795931e --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e + + +# When we publish to npm, the published files are available in the root +# directory, which allows for a clean include or require of sub-modules. +# +# var language = require('apollo-client-rxjs/rxify'); +# + +# Clear the built output +rm -rf ./build + +# Compile new files +npm run build + +# Make sure the ./npm directory is empty +rm -rf ./npm +mkdir ./npm + +# Copy all files from ./lib/src to /npm +cd ./build/src && cp -r ./ ../../npm/ +# Copy also the umd bundle with the source map file +cd ../bundles +cp apollo-rxjs.umd.js ../../npm/ && cp apollo-rxjs.umd.js.map ../../npm/ + +# Back to the root directory +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.scripts; \ + delete package.devDependencies; \ + package.main = 'apollo-rxjs.umd.js'; \ + package.module = 'index.js'; \ + package.typings = 'index.d.ts'; \ + var fs = require('fs'); \ + fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2)); \ + " + + +# Copy few more files to ./npm +cp README.md npm/ + +echo 'deploying to npm...' +cd npm && npm publish && git push --tags From afc9531519707c029ab9f69b44c61c1928c7eba4 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 12 Aug 2017 13:14:34 +0200 Subject: [PATCH 4/4] Fix changelog --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8747eb..daaeaf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,6 @@ ### v0.6.0-rc.1 -- Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) -- Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) - - Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) - Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) - Add a deploy script to keep compiled filed in the root directory [PR #48](https://github.com/kamilkisiela/apollo-client-rxjs/pull/48)